[pypy-svn] r27735 - in pypy/dist/pypy/translator/cli: src test
antocuni at codespeak.net
antocuni at codespeak.net
Fri May 26 19:13:18 CEST 2006
Author: antocuni
Date: Fri May 26 19:13:07 2006
New Revision: 27735
Modified:
pypy/dist/pypy/translator/cli/src/pypylib.cs
pypy/dist/pypy/translator/cli/test/runtest.py
pypy/dist/pypy/translator/cli/test/test_runtest.py
Log:
Added support for CliTest.interpret_raises.
Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/pypylib.cs (original)
+++ pypy/dist/pypy/translator/cli/src/pypylib.cs Fri May 26 19:13:07 2006
@@ -14,6 +14,11 @@
{
return string.Format("InstanceWrapper('{0}')", obj.GetType().FullName);
}
+
+ public static string FormatException(object obj)
+ {
+ return string.Format("ExceptionWrapper('{0}')", obj.GetType().FullName);
+ }
}
}
Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py (original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py Fri May 26 19:13:07 2006
@@ -68,12 +68,24 @@
ilasm.call('%s class [mscorlib]System.Convert::%s(string)' %
(arg_type, self.__convert_method(arg_type)))
+ # call the function and convert the result to a string containing a valid python expression
+ ilasm.begin_try()
ilasm.call(cts.graph_to_signature(self.graph))
-
- # convert result to a string containing a valid python expression
TYPE = self.graph.getreturnvar().concretetype
format_object(TYPE, ilasm)
ilasm.call('void class [mscorlib]System.Console::WriteLine(string)')
+ ilasm.leave('return')
+ ilasm.end_try()
+
+ for exc in ('[mscorlib]System.Exception', 'exceptions.Exception'):
+ ilasm.begin_catch(exc)
+ ilasm.call('string class [pypylib]pypy.test.Result::FormatException(object)')
+ ilasm.call('void class [mscorlib]System.Console::WriteLine(string)')
+ ilasm.leave('return')
+ ilasm.end_catch()
+
+ # write the result to stdout
+ ilasm.label('return')
ilasm.opcode('ret')
ilasm.end_function()
self.db.pending_function(self.graph)
@@ -157,6 +169,7 @@
retval = mono.wait()
assert retval == 0, stderr
+ print stdout
res = eval(stdout)
if isinstance(res, tuple):
res = StructTuple(res) # so tests can access tuple elements with .item0, .item1, etc.
@@ -183,14 +196,22 @@
def __init__(self, class_name):
self.class_name = class_name
+class ExceptionWrapper:
+ def __init__(self, class_name):
+ self.class_name = class_name
+
+
class CliTest(BaseRtypingTest, OORtypeMixin):
def interpret(self, fn, args):
ann = [lltype_to_annotation(typeOf(x)) for x in args]
f = compile_function(fn, ann)
return f(*args)
- def interpret_raises(self, exc, func, args):
- py.test.skip("CLI tests don't support interpret_raises")
+ def interpret_raises(self, exception, fn, args):
+ import exceptions # needed by eval
+ res = self.interpret(fn, args)
+ assert isinstance(res, ExceptionWrapper)
+ assert eval(res.class_name) is exception
def ll_to_string(self, s):
py.test.skip('ll_to_string not supported, yet')
Modified: pypy/dist/pypy/translator/cli/test/test_runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_runtest.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_runtest.py Fri May 26 19:13:07 2006
@@ -30,3 +30,8 @@
def fn():
return 1, 2
assert self.interpret(fn, []) == (1, 2)
+
+ def test_exception(self):
+ def fn():
+ raise ValueError
+ self.interpret_raises(ValueError, fn, [])
More information about the Pypy-commit
mailing list