Cleaned up tests/Makefile - added save generation to its own target
[open-adventure.git] / tests / Makefile
1 # Test-suite makefile for reposurgeon
2
3 # Use absolute path so tests that change working directory still use 
4 # scripts from parent directory.  Note that using $PWD seems to fail
5 # here under Gitlab's CI environment.
6 PATH := $(realpath ..):$(realpath .):${PATH}
7
8 # Defeat annoying behavior under Mac OS X - builtin echo doesn't do -n
9 ECHO := /bin/echo
10
11 check: regress
12         @echo "=== No diff output is good news."
13         @-advent -x 2>/dev/null # Get usage message into coverage tests
14         @-advent -l /dev/null <quit.log >/dev/null
15
16 .SUFFIXES: .chk
17
18 clean:
19         rm -fr *~ adventure.text *.adv scratch.tmp
20
21 # Show summary lines for all tests.
22 testlist:
23         @grep '^##' *.log
24 listcheck:
25         @for f in *.log; do \
26             if ( head -3 $$f | grep -q '^ *##' ); then :; else echo "$$f needs a description"; fi; \
27         done
28
29 savegames:
30         $(ECHO) "cheat: Generate save file with -1000 deaths"
31         ../cheat -d -1000 -o cheat_numdie.adv > /tmp/cheat_numdie
32         $(ECHO) "cheat: Generate save file with version -1337"
33         ../cheat -v -1337 -o resume_badversion.adv > /tmp/cheat_badversion
34         $(ECHO) "cheat: Generate save file 1000 saves"
35         ../cheat -s -1000 -o thousand_saves.adv > /tmp/cheat_1000saves
36         rm -f /tmp/cheat*
37
38 # General regression testing of commands and output; look at the *.log and
39 # corresponding *.chk files to see which tests this runs.
40 TESTLOADS := $(shell ls -1 *.log | sed '/.log/s///' | sort)
41 buildregress: savegames
42         ../cheat -s -1000 -o thousand_saves.adv > /tmp/regress1000saves
43         @for file in $(TESTLOADS); do \
44             echo "Remaking $${file}.chk"; \
45             OPTS=`sed -n /#options:/s///p <$${file}.log`; \
46             advent $$OPTS <$${file}.log >$${file}.chk 2>&1 || exit 1; \
47         done; \
48         rm -f scratch.tmp
49 regress: savegames
50         $(ECHO) "TEST cheat: Bogus option for save file generation"
51         ../cheat -QqQ 2> /tmp/coverage_cheat_batopt | true
52         $(ECHO) "TEST cheat: Fail to save because we omit -o"
53         ../cheat -d 1 2> /tmp/coverage_cheat_nooutput | true
54         $(ECHO) "TEST cheat: Fail to save to invalid path"
55         ../cheat -o / 2> /tmp/coverage_cheat_badoutput | true
56         $(ECHO) "TEST advent: Start with invalid file with -r"
57         advent -r /badfilename < quit.log > /tmp/coverage_advent_readfail 2>&1 || exit 1
58         $(ECHO) "TEST advent: Start with invalid file with -r"
59         advent -l / < quit.log > /tmp/coverage_advent_logfail 2>&1 || exit 1
60         $(ECHO) "TEST advent: Test -r with valid input"
61         advent -r thousand_saves.adv < quit.log > /tmp/coverage_advent_readfail 2>&1 || exit 1
62         @for file in $(TESTLOADS); do \
63             $(ECHO) -n "  $${file} "; grep '##' $${file}.log  || echo ' ## (no description)'; \
64             OPTS=`sed -n /#options:/s///p <$${file}.log`; \
65             if advent $$OPTS < $${file}.log >/tmp/regress$$$$ 2>&1; \
66             then diff --text -u $${file}.chk /tmp/regress$$$$ || exit 1; \
67             else echo "*** Nonzero return status on $${file}!"; exit 1; fi \
68         done; \
69         rm -f scratch.tmp /tmp/regress$$$$ /tmp/coverage*
70
71 # end