Makefile revision 1.76 1 # $NetBSD: Makefile,v 1.76 2020/07/29 19:48:33 rillig Exp $
2 #
3 # Unit tests for make(1)
4 #
5 # The main targets are:
6 #
7 # all:
8 # run all the tests
9 # test:
10 # run 'all', and compare to expected results
11 # accept:
12 # move generated output to expected results
13 #
14 # Settable variables
15 #
16 # TEST_MAKE
17 # The make program to be tested.
18 #
19 #
20 # Adding a test case
21 #
22 # Each feature should get its own set of tests in its own suitably
23 # named makefile (*.mk), with its own set of expected results (*.exp),
24 # and it should be added to the TESTS list.
25 #
26 # Any added files must also be added to src/distrib/sets/lists/tests/mi.
27 # Makefiles that are not added to TESTS must be ignored in
28 # src/tests/usr.bin/make/t_make.sh (example: include-sub).
29 #
30
31 # Each test is in a sub-makefile.
32 # Keep the list sorted.
33 TESTS+= # archive # broken on FreeBSD
34 TESTS+= cmdline
35 TESTS+= comment
36 TESTS+= cond-late
37 TESTS+= cond-short
38 TESTS+= cond1
39 TESTS+= cond2
40 TESTS+= directives
41 TESTS+= dollar
42 TESTS+= doterror
43 TESTS+= dotwait
44 TESTS+= envfirst
45 TESTS+= error
46 TESTS+= # escape # broken by reverting POSIX changes
47 TESTS+= export
48 TESTS+= export-all
49 TESTS+= export-env
50 TESTS+= forloop
51 TESTS+= forsubst
52 TESTS+= hash
53 TESTS+= # impsrc # broken by reverting POSIX changes
54 TESTS+= include-main
55 TESTS+= misc
56 TESTS+= moderrs
57 TESTS+= modmatch
58 TESTS+= modmisc
59 TESTS+= modorder
60 TESTS+= modts
61 TESTS+= modword
62 TESTS+= order
63 TESTS+= # phony-end # broken by reverting POSIX changes
64 TESTS+= posix
65 TESTS+= # posix1 # broken by reverting POSIX changes
66 TESTS+= qequals
67 TESTS+= # suffixes # broken by reverting POSIX changes
68 TESTS+= sunshcmd
69 TESTS+= sysv
70 TESTS+= ternary
71 TESTS+= unexport
72 TESTS+= unexport-env
73 TESTS+= varcmd
74 TESTS+= vardebug
75 TESTS+= varfind
76 TESTS+= varmisc
77 TESTS+= varmod-edge
78 TESTS+= varparse-dynamic
79 TESTS+= varquote
80 TESTS+= varshell
81
82 # Override environment variables for some of the tests.
83 ENV.envfirst= FROM_ENV=value-from-env
84 ENV.export= -i PATH=${PATH:Q}
85 ENV.varmisc= FROM_ENV=env
86 ENV.varmisc+= FROM_ENV_BEFORE=env
87 ENV.varmisc+= FROM_ENV_AFTER=env
88
89 # Override make flags for some of the tests; default is -k.
90 FLAGS.doterror= # none
91 FLAGS.envfirst= -e
92 FLAGS.export= -r
93 FLAGS.order= -j1
94 FLAGS.vardebug= -k -dv FROM_CMDLINE=
95
96 # Some tests need extra post-processing.
97 SED_CMDS.moderrs+= -e 's,\(substitution error:\).*,\1 (details omitted),'
98 SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),'
99 SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
100 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
101
102 # Some tests need an additional round of postprocessing.
103 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
104
105 # End of the configuration section.
106
107 .MAIN: all
108
109 UNIT_TESTS:= ${.PARSEDIR}
110 .PATH: ${UNIT_TESTS}
111
112 OUTFILES= ${TESTS:=.out}
113
114 all: ${OUTFILES}
115
116 CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp
117 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
118 CLEANFILES+= issue* .[ab]* # suffixes.mk
119 CLEANRECURSIVE+= dir dummy # posix1.mk
120
121 clean:
122 rm -f ${CLEANFILES}
123 .if !empty(CLEANRECURSIVE)
124 rm -rf ${CLEANRECURSIVE}
125 .endif
126
127 TEST_MAKE?= ${.MAKE}
128 TOOL_SED?= sed
129
130 # ensure consistent results from sort(1)
131 LC_ALL= C
132 LANG= C
133 .export LANG LC_ALL
134
135 # the tests are actually done with sub-makes.
136 .SUFFIXES: .mk .rawout .out
137 .mk.rawout:
138 @echo testing ${.IMPSRC}
139 @set -eu; \
140 cd ${.OBJDIR}; \
141 env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \
142 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
143 > ${.TARGET}.tmp 2>&1 \
144 && status=$$? || status=$$?; \
145 echo $$status > ${.TARGET:R}.status
146 @mv ${.TARGET}.tmp ${.TARGET}
147
148 # Post-process the test output so that the results can be compared.
149 #
150 # always pretend .MAKE was called 'make'
151 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
152 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
153 # replace anything after 'stopped in' with unit-tests
154 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
155 # strip ${.CURDIR}/ from the output
156 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
157 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
158
159 .rawout.out:
160 @echo postprocess ${.TARGET}
161 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
162 < ${.IMPSRC} > ${.TARGET}.tmp1
163 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
164 @rm ${.TARGET}.tmp1
165 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
166 @mv ${.TARGET}.tmp2 ${.TARGET}
167
168 # Compare all output files
169 test: ${OUTFILES} .PHONY
170 @failed= ; \
171 for test in ${TESTS}; do \
172 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
173 || failed="$${failed}$${failed:+ }$${test}" ; \
174 done ; \
175 if [ -n "$${failed}" ]; then \
176 echo "Failed tests: $${failed}" ; false ; \
177 else \
178 echo "All tests passed" ; \
179 fi
180
181 accept:
182 @for test in ${TESTS}; do \
183 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
184 || { echo "Replacing $${test}.exp" ; \
185 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
186 done
187
188 .if exists(${TEST_MAKE})
189 ${TESTS:=.rawout}: ${TEST_MAKE}
190 .endif
191
192 .-include <bsd.obj.mk>
193