[pypy-svn] r70472 - in pypy/branch/c-traceback/pypy/translator/c: . test

arigo at codespeak.net arigo at codespeak.net
Sat Jan 9 21:50:08 CET 2010


Author: arigo
Date: Sat Jan  9 21:50:06 2010
New Revision: 70472

Modified:
   pypy/branch/c-traceback/pypy/translator/c/genc.py
   pypy/branch/c-traceback/pypy/translator/c/test/test_standalone.py
Log:
Add a test, not passing so far.


Modified: pypy/branch/c-traceback/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/c-traceback/pypy/translator/c/genc.py	(original)
+++ pypy/branch/c-traceback/pypy/translator/c/genc.py	Sat Jan  9 21:50:06 2010
@@ -430,12 +430,16 @@
         bk = self.translator.annotator.bookkeeper
         return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
 
-    def cmdexec(self, args='', env=None, err=False):
+    def cmdexec(self, args='', env=None, err=False, expect_crash=False):
         assert self._compiled
         res = self.translator.platform.execute(self.executable_name, args,
                                                env=env)
         if res.returncode != 0:
+            if expect_crash:
+                return res.out, res.err
             raise Exception("Returned %d" % (res.returncode,))
+        if expect_crash:
+            raise Exception("Program did not crash!")
         if err:
             return res.out, res.err
         return res.out

Modified: pypy/branch/c-traceback/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/c-traceback/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/branch/c-traceback/pypy/translator/c/test/test_standalone.py	Sat Jan  9 21:50:06 2010
@@ -377,6 +377,39 @@
         assert not err
         assert path.check(file=0)
 
+    def test_fatal_error(self):
+        def g(x):
+            if x == 1:
+                raise ValueError
+            else:
+                raise KeyError
+        def entry_point(argv):
+            if len(argv) < 3:
+                g(len(argv))
+            return 0
+        t, cbuilder = self.compile(entry_point)
+        #
+        out, err = cbuilder.cmdexec("", expect_crash=True)
+        assert out.strip() == ''
+        lines = err.strip().splitlines()
+        assert lines[-1] == 'Fatal RPython error: ValueError'
+        assert len(lines) >= 4
+        l0, l1, l2 = lines[-4:-1]
+        assert l0 == 'RPython traceback:'
+        assert re.match(r'  File "\w+.c", line \d+, in g', l1)
+        assert re.match(r'  File "\w+.c", line \d+, in entry_point', l2)
+        #
+        out2, err2 = cbuilder.cmdexec("x", expect_crash=True)
+        assert out2.strip() == ''
+        lines2 = err2.strip().splitlines()
+        assert lines2[-1] == 'Fatal RPython error: KeyError'
+        l0, l1, l2 = lines2[-4:-1]
+        assert l0 == 'RPython traceback:'
+        assert re.match(r'  File "\w+.c", line \d+, in g', l1)
+        assert re.match(r'  File "\w+.c", line \d+, in entry_point', l2)
+        assert lines2[-3] != lines[-3]
+        assert lines2[-2] == lines[-2]
+
 
 class TestMaemo(TestStandalone):
     def setup_class(cls):



More information about the Pypy-commit mailing list