commit d88863db699e76c741d23345e1e86b759c163436
parent 7b8fc6e712c67be4391639a71c4c3f568fb1dec1
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Tue, 21 Apr 2026 07:41:58 -0700
lisp test harness
Diffstat:
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -70,7 +70,7 @@ PODMAN := podman run --rm --platform $(PLATFORM) \
# --- Targets ---------------------------------------------------------------
-.PHONY: all toolchain run run-all clean
+.PHONY: all toolchain run run-all test-lisp test-lisp-all clean
all: $(OUT_DIR)/$(PROG)
@@ -122,6 +122,41 @@ run-all:
-$(MAKE) --no-print-directory PROG=$(PROG) ARCH=amd64 run
-$(MAKE) --no-print-directory PROG=$(PROG) ARCH=riscv64 run
+# Test harness (LISP.md step 9). Each fixtures pair in tests/lisp/ is a
+# <name>.scm program plus a <name>.expected file holding its exact
+# stdout. test-lisp runs every fixture on $(ARCH); test-lisp-all runs
+# the suite on all three arches — cross-arch consistency falls out by
+# transitivity, since every arch must match the shared expectation.
+#
+# Non-zero exits from the interpreter are fine (it exits with the
+# final fixnum payload), so we ignore exit codes and only diff stdout.
+LISP_TESTS := $(sort $(wildcard tests/lisp/*.scm))
+
+test-lisp:
+ @$(MAKE) --no-print-directory PROG=lisp ARCH=$(ARCH) build/$(ARCH)/lisp
+ @pass=0; fail=0; \
+ for scm in $(LISP_TESTS); do \
+ expected="$${scm%.scm}.expected"; \
+ actual=$$($(PODMAN) ./build/$(ARCH)/lisp "$$scm" 2>/dev/null || true); \
+ want=$$(cat "$$expected" 2>/dev/null || printf ''); \
+ if [ "$$actual" = "$$want" ]; then \
+ echo " PASS [$(ARCH)] $$scm"; \
+ pass=$$((pass+1)); \
+ else \
+ echo " FAIL [$(ARCH)] $$scm"; \
+ echo " expected: $$want"; \
+ echo " actual: $$actual"; \
+ fail=$$((fail+1)); \
+ fi; \
+ done; \
+ echo "[$(ARCH)] $$pass passed, $$fail failed"; \
+ [ $$fail -eq 0 ]
+
+test-lisp-all:
+ $(MAKE) --no-print-directory ARCH=aarch64 test-lisp
+ $(MAKE) --no-print-directory ARCH=amd64 test-lisp
+ $(MAKE) --no-print-directory ARCH=riscv64 test-lisp
+
clean:
rm -rf build/ p1_aarch64.M1 p1_amd64.M1 p1_riscv64.M1
diff --git a/tests/lisp/00-identity.expected b/tests/lisp/00-identity.expected
@@ -0,0 +1 @@
+42
diff --git a/tests/lisp/00-identity.scm b/tests/lisp/00-identity.scm
@@ -0,0 +1,2 @@
+(define id (lambda (x) x))
+(id 42)