Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This Makefile made available to his students by
# Prof. Ronald Moore
# https://fbi.h-da.de/personen/ronald-moore/
# mailto:ronald.moore@h-da.de
# with no warranties whatsoever
## More preliminaries
# See https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
# In this makefile, we want to keep going even if we find errors
.IGNORE :
.NOTPARALLEL :
## Define test collections - each line should contain one or more filenames
GOOD-INPUTS := goodTest.input
BAD-INPUTS := badTest.input
# the sum of all tests
INPUTS := $(GOOD-INPUTS) $(BAD-INPUTS)
# reference files ("correct" output)
REFERENCES := $(INPUTS:.input=.reference)
# output files
OUTPUTS := $(INPUTS:.input=.output)
# Program we'll be testing
PROGRAM := ../halfbaker
# Tell make that the following "targets" are "phony"
# Cf. https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets
.PHONY : all clean tests goodtests badtests
## Now, the targets -- the things that will get made!
all: tests
# For convenience, "make check" == "make test"
check: tests
# TESTING
# Calling "make test" should
# (1) make the programs (if necessary)
# (2) erase all the test outputs
# (3) create them again (see rules, below).
# (4) run the special case "bigtest" (see below)
tests: $(PROGRAM)
cd .. && $(MAKE)
$(MAKE) clean
$(MAKE) updatetests
updatetests: $(OUTPUTS)
$(PROGRAM) :
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# "make clean" or equivalently "make testclean" deletes all files created by testing
clean: testclean
testclean:
$(RM) -fv *.output *~
# By the way, for more information about calling make from make, see
# https://www.gnu.org/software/make/manual/html_node/Recursion.html#Recursion
# User-defined function (Cf. http://oreilly.com/catalog/make3/book/ch04.pdf)
# Takes two arguments - an output file and a reference output file
# (the two files should be the same). Function prints "success" or "failure",
# depending on whether the two files are equal.
#define testReferenceOutput
# @cmp -s $1 $2 \
# && /bin/echo -e "Test against $2 successful" \
# || /bin/echo -e "\n\tTest against $2 FAILED!!!\n"
#endef
#### If your terminal supports colors, comment out the version above,
# and use this version instead - good tests have a green background,
# failed tests have a red background. See
# <http://misc.flogisoft.com/bash/tip_colors_and_formatting>
# for information about output formatting (colors, bold, etc.)).
define testReferenceOutput
# @cmp -s $1 $2
@diff -qs $1 $2 \
&& /bin/echo -e "\e[1;42mTest against $2 successful.\e[0m" \
|| /bin/echo -e "\e[1;41mTest against $2 FAILED!!! \e[0m"
endef
# Reminder...
# $@ = The filename representing the target.
# $< = The filename of the first prerequisite.
# $* = The stem of the target (i.e. without .o, .cpp...)
# $(*F) = The stem of the target (i.e. without .o, .cpp... AND without directory)
# $^ = The names of all the prerequisites, with spaces between them.
################ Assembler Tests ###################
# For some files x.job, we have stored the "correct" (expected) output in x.ref
# (where "ref" is short for "reference").
$(OUTPUTS): %.output: %.input %.reference
$(PROGRAM) $< >$@ 2>&1
$(call testReferenceOutput,$@, $*.reference)
# Finished!