From 91b1662302c14cf84ca8b90c1f3ec20a585f67a5 Mon Sep 17 00:00:00 2001 From: dozens Date: Fri, 7 Jun 2024 17:27:11 -0600 Subject: add ui tests --- .gitignore | 1 + justfile | 4 ++++ main.fnl | 2 -- test/README | 18 ++++++++++++++++++ test/moving-capture.dat | 22 ++++++++++++++++++++++ test/placing-capture.dat | 5 +++++ test/test.awk | 12 ++++++++++++ 7 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 test/README create mode 100644 test/moving-capture.dat create mode 100644 test/placing-capture.dat create mode 100644 test/test.awk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae062d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test/*.expect diff --git a/justfile b/justfile index 6fbee75..e5fa402 100644 --- a/justfile +++ b/justfile @@ -5,3 +5,7 @@ default: # run tests test: for f in lib/*.test.fnl; do fennel $f | faucet; done + +# build expect scripts +expects: + for f in test/*.dat; do awk -f test/test.awk $f > ${f/dat/expect}; done diff --git a/main.fnl b/main.fnl index af23d90..bf6933e 100644 --- a/main.fnl +++ b/main.fnl @@ -72,8 +72,6 @@ 2 ;; moving (let [from (index-of-move (string.sub move 1 2)) to (index-of-move (string.sub move -2 -1))] - (print "From" from) - (print "To" to) (tset self.moves from 0) (tset self.moves to self.player) (if (mill-at? self.moves to) diff --git a/test/README b/test/README new file mode 100644 index 0000000..11b09a4 --- /dev/null +++ b/test/README @@ -0,0 +1,18 @@ +== ABOUT == + +these files are to help me test the ui + +moves are recorded in `.dat`. +then you can `awk -f test.awk file.dat > file.expect`. +(or `just expects` to build them all.) +then you can `expect file.expect` +to have expect play the game for you up to a certain point. + +== REQUIREMENTS == + +- awk +- expect + +== FUTURE PLANS == + +have actual integration tests? diff --git a/test/moving-capture.dat b/test/moving-capture.dat new file mode 100644 index 0000000..d19ede6 --- /dev/null +++ b/test/moving-capture.dat @@ -0,0 +1,22 @@ +A1 +A4 +A7 +b2 +b4 +b6 +c3 +c4 +c5 +d1 +d2 +d3 +d5 +d6 +d7 +e3 +e4 +e5 +e4f4 +e3e4 +f4g4 +d3e3 diff --git a/test/placing-capture.dat b/test/placing-capture.dat new file mode 100644 index 0000000..67aebec --- /dev/null +++ b/test/placing-capture.dat @@ -0,0 +1,5 @@ +a1 +b4 +a4 +b2 +a7 diff --git a/test/test.awk b/test/test.awk new file mode 100644 index 0000000..ef6df20 --- /dev/null +++ b/test/test.awk @@ -0,0 +1,12 @@ +BEGIN { + print "#!/usr/bin/expect -f" + print "spawn fennel main.fnl" +} + +{ print "expect -re \"Player .'s turn:\"" + print "send -- \"" $0 "\\r\"" +} + +END { + print "interact" +} -- cgit 1.4.1-2-gfad0