Commits

Jürgen Bömmels  committed 5587886

Improve Scheme-level testing:

In case of differences show the calculated values

  • Participants
  • Parent commits 9ff8fb6

Comments (0)

Files changed (2)

File scheme/test/test_object.py

 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():

File scheme/test/test_scheme_level.py

 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
                 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
         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"""