From 64a1ee9810c06606e293b45811af2262e5549700 Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Thu, 22 Oct 2020 21:03:27 -0500 Subject: [PATCH] add a simple unit-test framework --- .gitignore | 1 + Makefile | 27 ++++++++++++++++++++++++++- test/compares.4th | 21 +++++++++++++++++++++ test/compares.exp | 13 +++++++++++++ test/double-compares.4th | 21 +++++++++++++++++++++ test/double-compares.exp | 13 +++++++++++++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/compares.4th create mode 100644 test/compares.exp create mode 100644 test/double-compares.4th create mode 100644 test/double-compares.exp diff --git a/.gitignore b/.gitignore index 36e2836..fc391fb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ jumpforth .*.swp .*.swo *~ +test/*.act diff --git a/Makefile b/Makefile index a3a3b64..92899c8 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,27 @@ -jumpforth: jumpforth.S startup.4th +SHELL = /bin/bash +TARGET = jumpforth +SOURCES = $(TARGET).S + +all: $(TARGET) + +$(TARGET): $(SOURCES) startup.4th gcc -m32 -nostdlib -static -o $@ $< + +clean: test-clean + $(RM) $(TARGET) + +TEST_RESULTS := $(patsubst %.4th,%.act,$(wildcard test/*.4th)) + +.PHONY: test $(TEST_RESULTS) +test: $(TEST_RESULTS) + +test-clean: + $(RM) $(TEST_RESULTS) + +.PHONY: $(TEST_RESULTS) +$(TEST_RESULTS): %.act: %.4th $(TARGET) + @printf '%s … ' $(notdir $<) && \ + { ./$(TARGET) < $< >& $@; echo exit-code: $$? >> $@; } && \ + if [[ ! -e $(@:%.act=%.exp) ]]; then echo '(new)'; cp $@ $(@:%.act=%.exp); \ + elif diff -q $(@:%.act=%.exp) $@ >/dev/null; then echo '✓'; \ + else echo '✗'; diff -u $(@:%.act=%.exp) $@; :; fi diff --git a/test/compares.4th b/test/compares.4th new file mode 100644 index 0000000..078bcf0 --- /dev/null +++ b/test/compares.4th @@ -0,0 +1,21 @@ +: X DUP >R >NAME TUCK TYPE 6 SWAP - SPACES + -1 R@ EXECUTE NEGATE . SPACE + 0 R@ EXECUTE NEGATE . SPACE + 1 R> EXECUTE NEGATE . EOL ; + +: Y DUP >R >NAME TUCK TYPE 6 SWAP - SPACES + -3 -2 R@ EXECUTE NEGATE . SPACE + -3 -3 R@ EXECUTE NEGATE . SPACE + -3 -4 R> EXECUTE NEGATE . EOL ; + +0 ARRAY UNARY-OPS ] 0< 0<= 0= 0<> 0>= 0> [ +HERE 0 UNARY-OPS - CELL / CONSTANT N-UNARY-OPS + +0 ARRAY BINARY-OPS ] < <= = <> >= > [ +HERE 0 BINARY-OPS - CELL / CONSTANT N-BINARY-OPS + +: TEST + N-UNARY-OPS 0 DO I UNARY-OPS @ X LOOP + N-BINARY-OPS 0 DO I BINARY-OPS @ Y LOOP ; + +TEST diff --git a/test/compares.exp b/test/compares.exp new file mode 100644 index 0000000..460693f --- /dev/null +++ b/test/compares.exp @@ -0,0 +1,13 @@ +0< 1 0 0 +0<= 1 1 0 +0= 0 1 0 +0<> 1 0 1 +0>= 0 1 1 +0> 0 0 1 +< 1 0 0 +<= 1 1 0 += 0 1 0 +<> 1 0 1 +>= 0 1 1 +> 0 0 1 +exit-code: 0 diff --git a/test/double-compares.4th b/test/double-compares.4th new file mode 100644 index 0000000..b0ce21b --- /dev/null +++ b/test/double-compares.4th @@ -0,0 +1,21 @@ +: X DUP >R >NAME TUCK TYPE 6 SWAP - SPACES + -1 S>D R@ EXECUTE NEGATE . SPACE + 0 S>D R@ EXECUTE NEGATE . SPACE + 1 S>D R> EXECUTE NEGATE . EOL ; + +: Y DUP >R >NAME TUCK TYPE 6 SWAP - SPACES + -3 S>D -2 S>D R@ EXECUTE NEGATE . SPACE + -3 S>D -3 S>D R@ EXECUTE NEGATE . SPACE + -3 S>D -4 S>D R> EXECUTE NEGATE . EOL ; + +0 ARRAY UNARY-OPS ] D0< D0<= D0= D0<> D0>= D0> [ +HERE 0 UNARY-OPS - CELL / CONSTANT N-UNARY-OPS + +0 ARRAY BINARY-OPS ] D< D<= D= D<> D>= D> [ +HERE 0 BINARY-OPS - CELL / CONSTANT N-BINARY-OPS + +: TEST + N-UNARY-OPS 0 DO I UNARY-OPS @ X LOOP + N-BINARY-OPS 0 DO I BINARY-OPS @ Y LOOP ; + +TEST diff --git a/test/double-compares.exp b/test/double-compares.exp new file mode 100644 index 0000000..4789aca --- /dev/null +++ b/test/double-compares.exp @@ -0,0 +1,13 @@ +D0< 1 0 0 +D0<= 1 1 0 +D0= 0 1 0 +D0<> 1 0 1 +D0>= 0 1 1 +D0> 0 0 1 +D< 1 0 0 +D<= 1 1 0 +D= 0 1 0 +D<> 1 0 1 +D>= 0 1 1 +D> 0 0 1 +exit-code: 0