Fix make debug check
[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 # Find all *.log entries to test
12 TESTLOADS := $(shell ls -1 *.log | sed '/.log/s///' | sort)
13
14 .PHONY: check coverage clean testlist listcheck savegames buildregress
15 .PHONY: savecheck regress
16
17 check: savecheck regress
18         @echo "=== No diff output is good news."
19         @-advent -x 2>/dev/null # Get usage message into coverage tests
20         @-advent -l /dev/null <pitfall.log >/dev/null
21
22 coverage: check
23         lcov -t "advent" -o ../advent.info -c -d ..
24         genhtml -o ../coverage/ ../advent.info
25
26 .SUFFIXES: .chk
27
28 clean:
29         rm -fr *~ adventure.text *.adv scratch.tmp
30
31 # Show summary lines for all tests.
32 testlist:
33         @grep '^##' *.log
34 listcheck:
35         @for f in *.log; do \
36             if ( head -3 $$f | grep -q '^ *##' ); then :; else echo "$$f needs a description"; fi; \
37         done
38
39 # Generate bogus savegames.
40 savegames:
41         $(ECHO) "cheat: Generate save file with -1000 deaths"
42         ../cheat -d -1000 -o cheat_numdie.adv > /tmp/cheat_numdie
43         $(ECHO) "cheat: Generate save file with version -1337"
44         ../cheat -v -1337 -o resume_badversion.adv > /tmp/cheat_badversion
45         $(ECHO) "cheat: Generate save file 1000 saves"
46         ../cheat -s -1000 -o thousand_saves.adv > /tmp/cheat_1000saves
47         rm -f /tmp/cheat*
48
49
50 # Rebuild characterizing tests
51 buildregress: savegames
52         ../cheat -s -1000 -o thousand_saves.adv > /tmp/regress1000saves
53         @for file in $(TESTLOADS); do \
54             echo "Remaking $${file}.chk"; \
55             OPTS=`sed -n /#options:/s///p <$${file}.log`; \
56             advent $$OPTS <$${file}.log >$${file}.chk 2>&1 || exit 1; \
57         done; \
58         rm -f scratch.tmp
59
60 savecheck: savegames
61         $(ECHO) "TEST cheat: Bogus option for save file generation"
62         ../cheat -QqQ 2> /tmp/coverage_cheat_batopt | true
63         $(ECHO) "TEST cheat: Fail to save because we omit -o"
64         ../cheat -d 1 2> /tmp/coverage_cheat_nooutput | true
65         $(ECHO) "TEST cheat: Fail to save to invalid path"
66         ../cheat -o / 2> /tmp/coverage_cheat_badoutput | true
67         $(ECHO) "TEST advent: Start with invalid file with -r"
68         advent -r /badfilename < pitfall.log > /tmp/coverage_advent_readfail 2>&1 || exit 1
69         $(ECHO) "TEST advent: Start with invalid file with -r"
70         advent -l / < pitfall.log > /tmp/coverage_advent_logfail 2>&1 || exit 1
71         $(ECHO) "TEST advent: Test -r with valid input"
72         advent -r thousand_saves.adv < pitfall.log > /tmp/coverage_advent_readfail 2>&1 || exit 1
73         rm -f scratch.tmp /tmp/regress$$$$ /tmp/coverage*
74
75 # General regression testing of commands and output; look at the *.log and
76 # corresponding *.chk files to see which tests this runs.
77 regress:
78         @for file in $(TESTLOADS); do \
79             $(ECHO) -n "  $${file} "; grep '##' $${file}.log  || echo ' ## (no description)'; \
80             OPTS=`sed -n /#options:/s///p <$${file}.log`; \
81             if advent $$OPTS < $${file}.log >/tmp/regress$$$$ 2>&1; \
82             then diff --text -u $${file}.chk /tmp/regress$$$$ || exit 1; \
83             else echo "*** Nonzero return status on $${file}!"; exit 1; fi \
84         done;
85
86 # end