diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-06-19 06:17:00 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-06-19 06:17:00 -0700 |
commit | 5d4159ba88001b52b814f13210421b8efd5cf9f2 (patch) | |
tree | 0a48222e64bcc336b969189d1b51f863971325c1 | |
parent | 1081759195124f46fba0028c3583aa878fa72869 (diff) | |
download | txr-5d4159ba88001b52b814f13210421b8efd5cf9f2.tar.gz txr-5d4159ba88001b52b814f13210421b8efd5cf9f2.tar.bz2 txr-5d4159ba88001b52b814f13210421b8efd5cf9f2.zip |
Test ifa macro.
* Makefile (TEST_OUT): Include .tl files.
(tst/%.out): New rule variant, from .tl prerequisite.
* tests/012/ifa.expected: New file.
* tests/012/ifa.tl: New file.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | tests/012/ifa.expected | 0 | ||||
-rw-r--r-- | tests/012/ifa.tl | 47 |
4 files changed, 68 insertions, 2 deletions
@@ -1,5 +1,16 @@ 2015-06-19 Kaz Kylheku <kaz@kylheku.com> + Test ifa macro. + + * Makefile (TEST_OUT): Include .tl files. + (tst/%.out): New rule variant, from .tl prerequisite. + + * tests/012/ifa.expected: New file. + + * tests/012/ifa.tl: New file. + +2015-06-19 Kaz Kylheku <kaz@kylheku.com> + * parser.c (parser_mark): Do not mark p->syntax_tree if its value is nao. Introduced on 2015-06-10, "Error handling improvement in read". @@ -256,8 +256,10 @@ endif TESTS_TMP := txr.test.out TESTS_OUT := $(addprefix tst/,\ - $(patsubst %.txr,%.out,\ - $(shell find -H tests -name '*.txr' | sort))) + $(patsubst %.tl,%.out,\ + $(patsubst %.txr,%.out,\ + $(shell find -H tests \ + \( -name '*.txr' -o -name '*.tl' \) | sort)))) TESTS_OK := $(TESTS_OUT:.out=.ok) .PHONY: tests @@ -299,6 +301,12 @@ tst/%.out: %.txr $(TXR) $(TXR_DBG_OPTS) $(TXR_OPTS) $< $(TXR_ARGS) > $(TESTS_TMP)) $(V)mv $(TESTS_TMP) $@ +tst/%.out: %.tl + $(call ABBREV,TXR) + $(V)mkdir -p $(dir $@) + $(V)$(TXR) $(TXR_DBG_OPTS) $(TXR_OPTS) $< $(TXR_ARGS) > $(TESTS_TMP) + $(V)mv $(TESTS_TMP) $@ + %.ok: %.out $(V)diff -u $(patsubst tst/%.out,%.expected,$<) $< $(V)touch $@ diff --git a/tests/012/ifa.expected b/tests/012/ifa.expected new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/012/ifa.expected diff --git a/tests/012/ifa.tl b/tests/012/ifa.tl new file mode 100644 index 00000000..d659399e --- /dev/null +++ b/tests/012/ifa.tl @@ -0,0 +1,47 @@ +(defmacro error-to-sym (expr) + ^(catch ,expr + (error (cond) :error))) + +;; test framework for ifa uses ifa! +(defmacro test (:env env expr expected) + (catch + (let ((expr-expn (macroexpand expr env))) + ^(ifa (not (equal (error-to-sym ,expr-expn) ',expected)) + (error "test case ~s failed: produced ~s; expected ~s" + ',expr it ',expected))) + (error (exc) + (unless (eq expected :error) + (error "test case ~s failed to expand: expected is ~s" expr expected))))) + +;; "it" is (+ 2 2) +(ifa (> (+ 2 2) 0) (* it 2)) + +(test (ifa (> (+ 2 2) 0) (* it 2)) + 8) + +;; "it" is (* x x) +(test (let ((x 7)) + (ifa (>= (* x x) 49) + (isqrt it))) + 7) + +;; ambiguous: is "it" x or is "it" y? +(test (ifa (> x y) (print it)) :error) + +;; "it" is (+ 3 (* 2 x)) +(test (let ((x 5)) + (ifa (< 0 (+ 3 (* 2 x)) 20) (* 100 it))) + 1300) + +;; "it" is (length '(a b c d)) +;; Intuition: it" could also be '(a b c d) +;; TODO: deal specially with chains of unary functions. +;; How about it = (length ...), itt = '(a b c d) +(test (ifa (not (oddp (length '(a b c d)))) it) + 4) + +;; "it" is y because %x% is constantp +(test (symacrolet ((%x% 42)) + (let ((y 41)) + (ifa (> %x% y) it))) + 42) |