[pypy-commit] lang-scheme default: Improve Scheme-level testing:

boemmels noreply at buildbot.pypy.org
Sat Dec 3 18:22:01 CET 2011


Author: Juergen Boemmels <boemmels at web.de>
Branch: 
Changeset: r26:55878863ff6b
Date: 2011-12-03 02:25 +0100
http://bitbucket.org/pypy/lang-scheme/changeset/55878863ff6b/

Log:	Improve Scheme-level testing:

	In case of differences show the calculated values

diff --git a/scheme/test/test_object.py b/scheme/test/test_object.py
--- a/scheme/test/test_object.py
+++ b/scheme/test/test_object.py
@@ -87,6 +87,7 @@
 def test_symbol():
     w_sym = W_Symbol("symb")
     assert w_sym.to_string() == "symb"
+    assert w_sym.to_repr() == "symb"
     assert w_sym.to_boolean() is True
 
 def test_vector():
diff --git a/scheme/test/test_scheme_level.py b/scheme/test/test_scheme_level.py
--- a/scheme/test/test_scheme_level.py
+++ b/scheme/test/test_scheme_level.py
@@ -2,6 +2,7 @@
 from scheme.ssparser import parse
 from scheme.execution import ExecutionContext
 from scheme.object import *
+import re
 
 # A scheme level macro, which raises an AssertionError at python
 # level. This python level Errors are then reported by pytest.py
@@ -19,7 +20,38 @@
                 raise WrongArgsNumber
             comment = w_rest.car.to_string()
 
-        w_test_result = w_test.eval(ctx)
+        if isinstance(w_test, W_Pair) and isinstance(w_test.car, W_Symbol):
+            w_test_oper = w_test.car
+            test_name = w_test_oper.name
+            if test_name in ['eq?', 'eqv?', 'equal?']:
+                w_iter = w_test.cdr
+                if not isinstance(w_iter, W_Pair):
+                    raise SchemeSyntaxError
+                w_first = w_iter.car
+                w_iter = w_iter.cdr
+                if not isinstance(w_iter, W_Pair):
+                    raise SchemeSyntaxError
+                w_second = w_iter.car
+                w_iter = w_iter.cdr
+                if not w_iter is w_nil:
+                    raise WrongArgsNumber
+
+                w_got = w_first.eval(ctx)
+                w_expected= w_second.eval(ctx)
+
+                comment += "\n + got: " + w_got.to_repr()
+                comment += "\n + expected: " + w_expected.to_repr()
+
+                w_compare = ctx.get(test_name)
+                if not isinstance(w_compare, W_Procedure):
+                    raise SchemeSyntaxError
+                w_test_result = w_compare.procedure(ctx,
+                    [w_got, w_expected])
+            else:
+                w_test_result = w_test.eval(ctx)
+        else:
+            w_test_result = w_test.eval(ctx)
+
         assert w_test_result.to_boolean(), comment
 
         return w_undefined
@@ -42,6 +74,21 @@
         r'(assert #f "Failed assert raises")')
     py.test.raises(AssertionError, run_with_assert,
         r'(define foo #f) (+ 1 1) (assert foo "more complex test")')
+    e = py.test.raises(AssertionError, run_with_assert,
+        r'(assert (eqv? (+ 9 7) 10))')
+    assert re.search('got: \d+', str(e.value))
+    assert re.search('expected: 10', str(e.value))
+
+def test_simple():
+    run_with_assert(r"""
+(assert (equal? (list 1 2 3) '(1 2 3)))
+(assert (equal? (cons 'a 'b) '(a . b)))
+(assert (eq? (car (cons 'a 'b)) 'a))
+(assert (eq? (cdr (cons 'a 'b)) 'b))
+(assert (eqv? (+ 1 2) 3))
+(assert (eqv? (* (+ 1 2) 3) 9))
+(assert (eqv? (- (* 2 3) (/ 6 2)) 3))
+""")
 
 def test_fac():
     run_with_assert(r"""


More information about the pypy-commit mailing list