[pypy-svn] r27230 - in pypy/dist/pypy/translator/stackless: . test

mwh at codespeak.net mwh at codespeak.net
Mon May 15 13:27:54 CEST 2006


Author: mwh
Date: Mon May 15 13:27:53 2006
New Revision: 27230

Modified:
   pypy/dist/pypy/translator/stackless/test/test_transform.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
give the stackless transformer a mode that allows the tests to assert that a
test actually tests something.  make test_constant_on_link actually test
something.


Modified: pypy/dist/pypy/translator/stackless/test/test_transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/test/test_transform.py	Mon May 15 13:27:53 2006
@@ -47,8 +47,12 @@
 def test_nothing():
     def fn():
         return 21
-    res = llinterp_stackless_function(fn)
+    res = llinterp_stackless_function(fn, assert_unwind=False)
     assert res == 21
+    info = py.test.raises(
+        llinterp.LLException,
+        "llinterp_stackless_function(fn, assert_unwind=True)")
+    assert ''.join(info.value.args[0].name).strip('\x00') == "AssertionError"        
 
 def test_simple_transform_llinterp():
     def check(x):
@@ -185,6 +189,7 @@
         if m > 100:
             raise KeyError
         a = A()
+        rstack.stack_unwind()
         a.m = m + 5
         return a
     def g(n, m):
@@ -255,11 +260,12 @@
     res = cbuilder.cmdexec('')
     return int(res.strip())
 
-def llinterp_stackless_function(fn, returntranslator=False):
+def llinterp_stackless_function(fn, returntranslator=False,
+                                assert_unwind=True):
     def wrapper(argv):
         return fn()
     t = rtype_stackless_function(wrapper)
-    st = StacklessTransformer(t, wrapper)
+    st = StacklessTransformer(t, wrapper, assert_unwind=assert_unwind)
     st.transform_all()
     if conftest.option.view:
         t.view()

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Mon May 15 13:27:53 2006
@@ -111,7 +111,8 @@
 
 class StacklessTransformer(object):
 
-    def __init__(self, translator, entrypoint, stackless_gc=False):
+    def __init__(self, translator, entrypoint,
+                 stackless_gc=False, assert_unwind=False):
         self.translator = translator
         self.stackless_gc = stackless_gc
 
@@ -138,14 +139,26 @@
         mixlevelannotator = MixLevelHelperAnnotator(translator.rtyper)
         l2a = annmodel.lltype_to_annotation
 
-        def slp_entry_point(argv):
-            try:
-                r = entrypoint(argv)
-            except code.UnwindException, u:
-                code.slp_main_loop()
-                return code.global_state.retval_long
-            return r
-        slp_entry_point.stackless_explicit = True
+        if assert_unwind:
+            def slp_entry_point(argv):
+                try:
+                    r = entrypoint(argv)
+                except code.UnwindException, u:
+                    code.slp_main_loop()
+                    return code.global_state.retval_long
+                else:
+                    assert False, "entrypoint never unwound the stack"
+                return r
+            slp_entry_point.stackless_explicit = True
+        else:
+            def slp_entry_point(argv):
+                try:
+                    r = entrypoint(argv)
+                except code.UnwindException, u:
+                    code.slp_main_loop()
+                    return code.global_state.retval_long
+                return r
+            slp_entry_point.stackless_explicit = True
 
         self.slp_entry_point = slp_entry_point
         oldgraph = bk.getdesc(entrypoint).getuniquegraph()



More information about the Pypy-commit mailing list