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