Integrate multifile test into TAP sequence.
[open-adventure.git] / tests / Makefile
1 # Test-suite makefile for opeb-adventure
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 PARDIR=$(realpath ..)
7 PATH := $(PARDIR):$(realpath .):${PATH}
8 GCOV?=gcov
9
10 # Make this overrideable so it's easier to test old versions
11 advent?=advent
12
13 # Defeat annoying behavior under Mac OS X - builtin echo doesn't do -n
14 ECHO := /bin/echo
15
16 # Find all *.log entries to test
17 TESTLOADS := $(shell ls -1 *.log | sed '/.log/s///' | sort)
18
19 .PHONY: check coverage clean testlist listcheck savegames buildregress
20 .PHONY: savecheck regress
21
22 check: savecheck regress
23         @echo "=== No diff output is good news."
24         @-advent -x 2>/dev/null # Get usage message into coverage tests
25         @-advent -l /dev/null <pitfall.log >/dev/null
26
27 coverage: check
28         lcov -t "advent" -o $(PARDIR)/advent.info -c -d $(PARDIR) --gcov-tool=$(GCOV)
29         genhtml -o $(PARDIR)/coverage/ $(PARDIR)/advent.info
30         ./coverage_dungeon.py
31
32 .SUFFIXES: .chk
33
34 clean:
35         rm -fr *~ adventure.text *.adv scratch.tmp
36
37 # Show summary lines for all tests.
38 testlist:
39         @grep '^##' *.log
40 listcheck:
41         @for f in *.log; do \
42             if ( head -3 $$f | grep -q '^ *##' ); then :; else echo "$$f needs a description"; fi; \
43         done
44
45 # Generate bogus savegames.
46 savegames:
47         @$(ECHO) "cheat: Generate save file with -900 deaths"
48         @$(PARDIR)/cheat -d -900 -o cheat_numdie.adv > /tmp/cheat_numdie
49         @$(ECHO) "cheat: Generate save file with -1000 deaths"
50         @$(PARDIR)/cheat -d -1000 -o cheat_numdie1000.adv > /tmp/cheat_numdie1000
51         @$(ECHO) "cheat: Generate save file with version -1337"
52         @$(PARDIR)/cheat -v -1337 -o resume_badversion.adv > /tmp/cheat_badversion
53         @$(ECHO) "cheat: Generate save file 1000 saves"
54         @$(PARDIR)/cheat -s -1000 -o thousand_saves.adv > /tmp/cheat_1000saves
55         @$(ECHO) "cheat: Generate save file 1000 turns"
56         @$(PARDIR)/cheat -t -1000 -o thousand_saves.adv > /tmp/cheat_1000turns
57         @$(ECHO) "cheat: Generate save file 1000 turns"
58         @$(PARDIR)/cheat -l -1000 -o thousand_lamp.adv > /tmp/cheat_1000lamp
59         @rm -f /tmp/cheat*
60
61
62 # Rebuild characterizing tests
63 buildregress: savegames
64         $(PARDIR)/cheat -s -1000 -o thousand_saves.adv > /tmp/regress1000saves
65         @for file in $(TESTLOADS); do \
66             echo "Remaking $${file}.chk"; \
67             OPTS=`sed -n /#options:/s///p <$${file}.log`; \
68             advent $$OPTS <$${file}.log >$${file}.chk 2>&1 || exit 1; \
69         done; \
70         echo "inven" | advent isofoo.log /dev/stdin >multifile.chk
71         rm -f scratch.tmp
72
73 savecheck: savegames
74         @$(ECHO) "TEST cheat: Bogus option for save file generation"
75         @$(PARDIR)/cheat -QqQ 2> /tmp/coverage_cheat_batopt | true
76         @$(ECHO) "TEST cheat: No save file specified"
77         @$(PARDIR)/cheat 2>/dev/null | true
78         @$(ECHO) "TEST cheat: Fail to save because we omit -o"
79         @$(PARDIR)/cheat -d 1 2> /tmp/coverage_cheat_nooutput | true
80         @$(ECHO) "TEST cheat: Fail to save to invalid path"
81         @$(PARDIR)/cheat -o / 2> /tmp/coverage_cheat_badoutput | true
82         @$(ECHO) "TEST advent: Start with invalid file with -r"
83         @advent -r /badfilename < pitfall.log > /tmp/coverage_advent_readfail 2>&1 || exit 1
84         @$(ECHO) "TEST advent: Start with invalid file with -l"
85         @advent -l / < pitfall.log > /tmp/coverage_advent_logfail 2>&1 || exit 1
86         @$(ECHO) "TEST advent: Test -r with valid input"
87         @advent -r thousand_saves.adv < pitfall.log > /tmp/coverage_advent_readfail 2>&1 || exit 1
88         @rm -f /tmp/coverage*
89
90 # General regression testing of commands and output; look at the *.log and
91 # corresponding *.chk files to see which tests this runs.
92 regress:
93         @for file in $(TESTLOADS); do \
94             $(ECHO) -n "  $${file} "; grep '##' $${file}.log  || echo ' ## (no description)'; \
95             OPTS=`sed -n /#options:/s///p <$${file}.log`; \
96             if $(advent) $$OPTS < $${file}.log >/tmp/regress$$$$ 2>&1; \
97             then diff --text -u $${file}.chk /tmp/regress$$$$ || exit 1; \
98             else echo "*** Nonzero return status on $${file}!"; exit 1; fi \
99         done; \
100         $(ECHO) "  multifile ## Test multiple file arguments"
101         @(echo "inven" | advent isofoo.log /dev/stdin | diff --text -u multifile.chk -) || exit 1
102         rm -f scratch.tmp /tmp/regress$$$$
103
104 # Steps towards TAP. savecheck is not yet integrated.
105
106 # The TAP filter. Only affects presentation of the test suite messages
107 TAPCONSUMER=tapview
108
109 # Fall back to safety if our declared TAP consumer does not exist.
110 # This is helpful in the CI environment, where it would be better for
111 # the logfiles to carry the raw TAP messages. 
112 TAPFILTER=$(shell command -v $(TAPCONSUMER) || echo cat)
113
114 FAILLOG=/tmp/advent-test.log
115
116 RUN_TARGETS=$(TESTLOADS:%=run-regress-%)
117 $(RUN_TARGETS): run-regress-%: %.log
118         @(test=$(<:.log=); legend=$$(sed -n '/^## /s///p' <"$<" 2>/dev/null || echo "(no description)"); \
119         OPTS=`sed -n /#options:/s///p $<`; \
120         $(advent) $$OPTS <$< | tapdiffer "$<: $${legend}" "$${test}.chk") >>$(FAILLOG)
121
122 multifile-regress:
123         @(echo "inven" | advent isofoo.log /dev/stdin) | tapdiffer "multifile: multiple-file test" multifile.chk >>$(FAILLOG)
124
125 TEST_TARGETS = $(RUN_TARGETS) multifile-regress
126
127 tap: count $(TEST_TARGETS)
128 count:
129         @echo 1..$(words $(TEST_TARGETS)) >$(FAILLOG)
130
131 tapcheck:
132         @make --no-print-directory tap; tapview <$(FAILLOG)
133
134 # end