From a5af22120f97651c4c40fad448ae7f017aed28dc Mon Sep 17 00:00:00 2001 From: Tijn Kersjes Date: Fri, 26 Jul 2019 07:40:30 +0200 Subject: [PATCH] WIP test suite --- Makefile | 2 + examples/ans-test-suite/ans-test-suite.fs | 94 +++++++++++++++++++++++ test/gbtest.js | 2 +- test/test-examples.js | 18 +++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 examples/ans-test-suite/ans-test-suite.fs diff --git a/Makefile b/Makefile index 11683b12..fc9fa294 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ all: examples examples: \ examples/hello-world-asm/hello.gb \ examples/hello-world/hello.gb \ + examples/ans-test-suite/ans-test-suite.gb \ examples/happy-birthday/happy-birthday.gb \ examples/sokoban/sokoban.gb \ examples/synth/synth.gb @@ -44,6 +45,7 @@ tests: $(TEST_OBJS) clean: -rm -f examples/hello-world-asm/hello.gb -rm -f examples/hello-world/hello.gb + -rm -f examples/ans-test-suite/ans-test-suite.gb -rm -f examples/happy-birthday/happy-birthday.gb -rm -f examples/sokoban/sokoban.gb -rm -f examples/synth/synth.gb diff --git a/examples/ans-test-suite/ans-test-suite.fs b/examples/ans-test-suite/ans-test-suite.fs new file mode 100644 index 00000000..d0ceacef --- /dev/null +++ b/examples/ans-test-suite/ans-test-suite.fs @@ -0,0 +1,94 @@ +title: ANSTESTSUITE +gamecode: ANSF + +require ibm-font.fs +require logger.fs +require tester.fs + +variable #total +: }T 1 #total +! }T ; + +: .progress + scroll-to-bottom + #total ? ." completed..." cr ; + + +0 CONSTANT 0S +0 INVERT CONSTANT 1S + +: GI1 IF 123 THEN ; +: GI2 IF 123 ELSE 234 THEN ; + +: GI3 BEGIN DUP 5 < WHILE DUP 1+ REPEAT ; + +: GI4 BEGIN DUP 1+ DUP 5 > UNTIL ; + +: GI5 BEGIN DUP 2 > + WHILE DUP 5 < WHILE DUP 1+ REPEAT 123 ELSE 345 THEN ; + +: run-tests + log" BOOLEANS: INVERT AND OR XOR" + + T{ 0 0 AND -> 0 }T + T{ 0 1 AND -> 0 }T + T{ 1 0 AND -> 0 }T + T{ 1 1 AND -> 1 }T .progress + + T{ 0 INVERT 1 AND -> 1 }T + T{ 1 INVERT 1 AND -> 0 }T + + T{ 0S INVERT -> 1S }T + T{ 1S INVERT -> 0S }T + + T{ 0S 0S AND -> 0S }T + T{ 0S 1S AND -> 0S }T + T{ 1S 0S AND -> 0S }T + T{ 1S 1S AND -> 1S }T .progress + + T{ 0S 0S OR -> 0S }T + T{ 0S 1S OR -> 1S }T + T{ 1S 0S OR -> 1S }T + T{ 1S 1S OR -> 1S }T + + T{ 0S 0S XOR -> 0S }T + T{ 0S 1S XOR -> 1S }T + T{ 1S 0S XOR -> 1S }T + T{ 1S 1S XOR -> 0S }T .progress + + log" IF ELSE THEN BEGIN WHILE REPEAT UNTIL" + + T{ 0 GI1 -> }T + T{ 1 GI1 -> 123 }T + T{ -1 GI1 -> 123 }T + T{ 0 GI2 -> 234 }T + T{ 1 GI2 -> 123 }T + T{ -1 GI1 -> 123 }T .progress + + T{ 0 GI3 -> 0 1 2 3 4 5 }T + T{ 4 GI3 -> 4 5 }T + T{ 5 GI3 -> 5 }T + T{ 6 GI3 -> 6 }T + + T{ 3 GI4 -> 3 4 5 6 }T .progress + T{ 5 GI4 -> 5 6 }T + T{ 6 GI4 -> 6 7 }T + + T{ 1 GI5 -> 1 345 }T + T{ 2 GI5 -> 2 345 }T + T{ 3 GI5 -> 3 4 5 123 }T + T{ 4 GI5 -> 4 5 123 }T + T{ 5 GI5 -> 5 123 }T .progress +; + +: main + install-font + init-term + init-tester + 0 #total ! + page + run-tests + log" --------------------" + log" Test suite completed" cr + #total @ 4 .r space ." total" cr + #errors @ 4 .r space ." failures" + cr scroll-to-bottom ; diff --git a/test/gbtest.js b/test/gbtest.js index 6220fcd3..6f8c2e35 100644 --- a/test/gbtest.js +++ b/test/gbtest.js @@ -61,7 +61,7 @@ module.exports = filename => { }, get frameSha() { - return getSha(frame); + return frame && getSha(frame); }, get depth() { diff --git a/test/test-examples.js b/test/test-examples.js index 6afeb720..087bcf16 100644 --- a/test/test-examples.js +++ b/test/test-examples.js @@ -47,3 +47,21 @@ describe("hello-world-asm", () => { ); }); }); + +describe("ans-test-suite", () => { + const gb = require("./gbtest")( + path.resolve(__dirname, "../examples/ans-test-suite/ans-test-suite.gb") + ); + + test("all tests pass", () => { + gb.steps(10); + gb.run(); + gb.steps(100); + gb.saveFrame( + path.resolve(__dirname, "../examples/ans-test-suite/ans-test-suite.png") + ); + expect(gb.frameSha).toBe( + "1dded7c5cbaaa4b94377fc76574deffb0869ee65e9b72dfafae0604304fbe365" + ); + }); +});