From 460b8ad3357e5bb91e32035b3ac1ceec8f10faf1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 23 Apr 2020 02:20:59 -0700 Subject: ifa: fix broken/invalid test case. * tests/012/ifa.tl: The "ambiguous" test case is not ambiguous at all. The reason it was yielding :error previously was not due to the ifa macro identifying an ambiguity but due to the funcion < not accepting nil arguments. Since < now does accept nil arguments, this test broke. Fixing this test, and adding one that tests for the ambiguous case: multiple it-candidates being rejected by ifa at expansion time. * tests/common.tl (vtest): This macro requires maintenance. To test for expansion-time failure, we must use expand, not just macroexpand. In this case, the (ifa ...) macro call is wrapped in a (let ...) so macroexpand won't do it. Secondly, the expected value is an quote expression that must be evaluated if we need its value in vtest itself. Otherwise it won't compare equal to :error, since it is actually (quote :error). --- tests/012/ifa.tl | 7 +++++-- tests/common.tl | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/012/ifa.tl b/tests/012/ifa.tl index d669244d..45a2939b 100644 --- a/tests/012/ifa.tl +++ b/tests/012/ifa.tl @@ -10,8 +10,11 @@ (isqrt it))) 7) -;; ambiguous: is "it" x or is "it" y? -(test (let (x y) (ifa (> x y) (print it))) :error) +;; no it-candidates: "it" is leftmost arg x. +(test (let ((x 1) (y 0)) (ifa (> x y) it)) 1) + +;; multiple it-candidates: error +(test (let (x y) (ifa (> (* x x) (* y y)) it)) :error) ;; "it" is (+ 3 (* 2 x)) (test (let ((x 5)) diff --git a/tests/common.tl b/tests/common.tl index 3cd5df63..3eef8d31 100644 --- a/tests/common.tl +++ b/tests/common.tl @@ -4,14 +4,14 @@ (defmacro vtest (:env env expr expected) (catch - (let ((expr-expn (macroexpand expr env)) + (let ((expr-expn (expand expr env)) (expval (gensym))) ^(let ((,expval ,expected)) (ifa (not (equal (error-to-sym ,expr-expn) ,expval)) (error "test case ~s failed: produced ~s; expected ~s" ',expr it ,expval)))) (error (exc) - (unless (eq expected :error) + (unless (eq (eval expected) :error) (error "test case ~s failed to expand: expected is ~s" expr expected))))) (defmacro test (expr expected) -- cgit v1.2.3