Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r67204:ae1fe34facf8
Date: 2013-10-08 15:23 +0200
http://bitbucket.org/pypy/pypy/changeset/ae1fe34facf8/

Log:    Test and fix for the error message

diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -187,13 +187,15 @@
         if hop.nb_args > 2:
             v_start = hop.inputarg(Signed, arg=2)
             if not hop.args_s[2].nonneg:
-                raise TyperError("str.find() start must be proven 
non-negative")
+                raise TyperError("str.%s() start must be proven non-negative"
+                                 % (reverse and 'rfind' or 'find',))
         else:
             v_start = hop.inputconst(Signed, 0)
         if hop.nb_args > 3:
             v_end = hop.inputarg(Signed, arg=3)
             if not hop.args_s[3].nonneg:
-                raise TyperError("str.find() end must be proven non-negative")
+                raise TyperError("str.%s() end must be proven non-negative"
+                                 % (reverse and 'rfind' or 'find',))
         else:
             v_end = hop.gendirectcall(self.ll.ll_strlen, v_str)
         hop.exception_cannot_occur()
diff --git a/rpython/rtyper/test/test_rstr.py b/rpython/rtyper/test/test_rstr.py
--- a/rpython/rtyper/test/test_rstr.py
+++ b/rpython/rtyper/test/test_rstr.py
@@ -416,6 +416,14 @@
             res = self.interpret(f, [i])
             assert res == expected
 
+    def test_rfind_error_message(self):
+        const = self.const
+        def f(i):
+            return const("abc").rfind(const(''), i)
+        e = py.test.raises(TyperError, self.interpret, f, [-5])
+        assert str(e.value).startswith(
+            'str.rfind() start must be proven non-negative')
+
     def test_find_char(self):
         const = self.const
         def fn(ch):
@@ -1134,4 +1142,4 @@
         array = lltype.malloc(TP, 12, flavor='raw')
         self.interpret(f, [array, 4])
         assert list(array) == list('abc'*4)
-        lltype.free(array, flavor='raw')
\ No newline at end of file
+        lltype.free(array, flavor='raw')
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to