Makefile revision 1.58 1 # $NetBSD: Makefile,v 1.58 2020/05/17 12:36:26 rillig Exp $
2 #
3 # Unit tests for make(1)
4 # The main targets are:
5 #
6 # all: run all the tests
7 # test: run 'all', and compare to expected results
8 # accept: move generated output to expected results
9 #
10 # Adding a test case.
11 # Each feature should get its own set of tests in its own suitably
12 # named makefile (*.mk), with its own set of expected results (*.exp),
13 # and it should be added to the TESTNAMES list.
14 #
15
16 .MAIN: all
17
18 UNIT_TESTS:= ${.PARSEDIR}
19 .PATH: ${UNIT_TESTS}
20
21 # Each test is in a sub-makefile.
22 # Keep the list sorted.
23 TESTNAMES= \
24 comment \
25 cond-late \
26 cond1 \
27 cond2 \
28 dollar \
29 doterror \
30 dotwait \
31 error \
32 export \
33 export-all \
34 export-env \
35 forloop \
36 forsubst \
37 hash \
38 include-main \
39 misc \
40 moderrs \
41 modmatch \
42 modmisc \
43 modorder \
44 modts \
45 modword \
46 order \
47 posix \
48 qequals \
49 sunshcmd \
50 sysv \
51 ternary \
52 unexport \
53 unexport-env \
54 varcmd \
55 varmisc \
56 varmod-edge \
57 varquote \
58 varshell
59
60 # these tests were broken by referting POSIX chanegs
61 STRICT_POSIX_TESTS = \
62 escape \
63 impsrc \
64 phony-end \
65 posix1 \
66 suffixes
67
68 # Override make flags for certain tests
69 flags.doterror=
70 flags.order=-j1
71
72 OUTFILES= ${TESTNAMES:S/$/.out/}
73
74 all: ${OUTFILES}
75
76 CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
77 CLEANFILES += obj*.[och] lib*.a # posix1.mk
78 CLEANFILES += issue* .[ab]* # suffixes.mk
79 CLEANRECURSIVE += dir dummy # posix1.mk
80
81 clean:
82 rm -f ${CLEANFILES}
83 .if !empty(CLEANRECURSIVE)
84 rm -rf ${CLEANRECURSIVE}
85 .endif
86
87 TEST_MAKE?= ${.MAKE}
88 TOOL_SED?= sed
89
90 # ensure consistent results from sort(1)
91 LC_ALL= C
92 LANG= C
93 .export LANG LC_ALL
94
95 # the tests are actually done with sub-makes.
96 .SUFFIXES: .mk .rawout .out
97 .mk.rawout:
98 @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
99 -@cd ${.OBJDIR} && \
100 { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
101 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
102 @mv ${.TARGET}.tmp ${.TARGET}
103
104 # We always pretend .MAKE was called 'make'
105 # and strip ${.CURDIR}/ from the output
106 # and replace anything after 'stopped in' with unit-tests
107 # so the results can be compared.
108 .rawout.out:
109 @echo postprocess ${.TARGET}
110 @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
111 -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
112 -e '/stopped/s, /.*, unit-tests,' \
113 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
114 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
115 < ${.IMPSRC} > ${.TARGET}.tmp
116 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
117 @mv ${.TARGET}.tmp ${.TARGET}
118
119 # Compare all output files
120 test: ${OUTFILES} .PHONY
121 @failed= ; \
122 for test in ${TESTNAMES}; do \
123 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
124 || failed="$${failed}$${failed:+ }$${test}" ; \
125 done ; \
126 if [ -n "$${failed}" ]; then \
127 echo "Failed tests: $${failed}" ; false ; \
128 else \
129 echo "All tests passed" ; \
130 fi
131
132 accept:
133 @for test in ${TESTNAMES}; do \
134 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
135 || { echo "Replacing $${test}.exp" ; \
136 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
137 done
138
139 .if exists(${TEST_MAKE})
140 ${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
141 .endif
142
143 .-include <bsd.obj.mk>
144