Makefile revision 1.91 1 # $NetBSD: Makefile,v 1.91 2020/08/09 16:32:28 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 # To do that, just run "make sync-mi" in this directory.
28 #
29 # A few *.mk files are helper files for other tests (such as include-sub.mk)
30 # and are thus not added to TESTS. Such files must be ignored in
31 # src/tests/usr.bin/make/t_make.sh.
32 #
33
34 # Each test is in a sub-makefile.
35 # Keep the list sorted.
36 TESTS+= # archive # broken on FreeBSD
37 TESTS+= cmdline
38 TESTS+= comment
39 TESTS+= cond-late
40 TESTS+= cond-short
41 TESTS+= cond1
42 TESTS+= cond2
43 TESTS+= counter
44 TESTS+= dir
45 TESTS+= directives
46 TESTS+= dollar
47 TESTS+= doterror
48 TESTS+= dotwait
49 TESTS+= envfirst
50 TESTS+= error
51 TESTS+= # escape # broken by reverting POSIX changes
52 TESTS+= export
53 TESTS+= export-all
54 TESTS+= export-env
55 TESTS+= export-variants
56 TESTS+= forloop
57 TESTS+= forsubst
58 TESTS+= hash
59 TESTS+= impsrc
60 TESTS+= include-main
61 TESTS+= lint
62 TESTS+= make-exported
63 TESTS+= misc
64 TESTS+= moderrs
65 TESTS+= modmatch
66 TESTS+= modmisc
67 TESTS+= modorder
68 TESTS+= modts
69 TESTS+= modword
70 TESTS+= order
71 TESTS+= phony-end
72 TESTS+= posix
73 TESTS+= # posix1 # broken by reverting POSIX changes
74 TESTS+= qequals
75 TESTS+= recursive
76 TESTS+= # suffixes # runs into an endless loop (try -dA)
77 TESTS+= sunshcmd
78 TESTS+= sysv
79 TESTS+= ternary
80 TESTS+= unexport
81 TESTS+= unexport-env
82 TESTS+= use-inference
83 TESTS+= varcmd
84 TESTS+= vardebug
85 TESTS+= varfind
86 TESTS+= varmisc
87 TESTS+= varmod-edge
88 TESTS+= varparse-dynamic
89 TESTS+= varquote
90 TESTS+= varshell
91
92 # Override environment variables for some of the tests.
93 ENV.counter= -i
94 ENV.envfirst= FROM_ENV=value-from-env
95 ENV.export= -i PATH=${PATH:Q}
96 ENV.export-variants= -i PATH=${PATH:Q}
97 ENV.lint= -i
98 ENV.make-exported= -i PATH=${PATH:Q}
99 ENV.recursive= -i
100 ENV.varmisc= FROM_ENV=env
101 ENV.varmisc+= FROM_ENV_BEFORE=env
102 ENV.varmisc+= FROM_ENV_AFTER=env
103
104 # Override make flags for some of the tests; default is -k.
105 FLAGS.counter= -r -dv
106 FLAGS.doterror= # none
107 FLAGS.envfirst= -e
108 FLAGS.export= -r
109 FLAGS.lint= -dL -k
110 FLAGS.order= -j1
111 FLAGS.recursive= -dL -r
112 FLAGS.vardebug= -k -dv FROM_CMDLINE=
113
114 # Some tests need extra post-processing.
115 SED_CMDS.moderrs+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
116 SED_CMDS.modmisc+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
117 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
118 SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
119 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
120
121 # Some tests need an additional round of postprocessing.
122 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
123 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
124
125 export-all.rawout: export.mk
126 unexport.rawout: export.mk
127 unexport-env.rawout: export.mk
128
129 # End of the configuration section.
130
131 .MAIN: all
132
133 UNIT_TESTS:= ${.PARSEDIR}
134 .PATH: ${UNIT_TESTS}
135
136 OUTFILES= ${TESTS:=.out}
137
138 all: ${OUTFILES}
139
140 CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp
141 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
142 CLEANFILES+= issue* .[ab]* # suffixes.mk
143 CLEANRECURSIVE+= dir dummy # posix1.mk
144
145 clean:
146 rm -f ${CLEANFILES}
147 .if !empty(CLEANRECURSIVE)
148 rm -rf ${CLEANRECURSIVE}
149 .endif
150
151 TEST_MAKE?= ${.MAKE}
152 TOOL_SED?= sed
153
154 # ensure consistent results from sort(1)
155 LC_ALL= C
156 LANG= C
157 .export LANG LC_ALL
158
159 # the tests are actually done with sub-makes.
160 .SUFFIXES: .mk .rawout .out
161 .mk.rawout:
162 @echo testing ${.IMPSRC}
163 @set -eu; \
164 cd ${.OBJDIR}; \
165 env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \
166 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
167 > ${.TARGET}.tmp 2>&1 \
168 && status=$$? || status=$$?; \
169 echo $$status > ${.TARGET:R}.status
170 @mv ${.TARGET}.tmp ${.TARGET}
171
172 # Post-process the test output so that the results can be compared.
173 #
174 # always pretend .MAKE was called 'make'
175 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
176 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
177 # replace anything after 'stopped in' with unit-tests
178 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
179 # strip ${.CURDIR}/ from the output
180 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
181 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
182
183 .rawout.out:
184 @echo postprocess ${.TARGET}
185 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
186 < ${.IMPSRC} > ${.TARGET}.tmp1
187 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
188 @rm ${.TARGET}.tmp1
189 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
190 @mv ${.TARGET}.tmp2 ${.TARGET}
191
192 # Compare all output files
193 test: ${OUTFILES} .PHONY
194 @failed= ; \
195 for test in ${TESTS}; do \
196 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
197 || failed="$${failed}$${failed:+ }$${test}" ; \
198 done ; \
199 if [ -n "$${failed}" ]; then \
200 echo "Failed tests: $${failed}" ; false ; \
201 else \
202 echo "All tests passed" ; \
203 fi
204
205 accept:
206 @for test in ${TESTS}; do \
207 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
208 || { echo "Replacing $${test}.exp" ; \
209 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
210 done
211
212 SYNC_MI_AWK= \
213 BEGIN { \
214 testsdir = "usr.bin/make/unit-tests"; \
215 linestart = "./usr/tests/" testsdir; \
216 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
217 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
218 } \
219 function startswith(s, prefix) { \
220 return substr(s, 1, length(prefix)) == prefix; \
221 } \
222 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
223 { print $$0 } \
224 $$1 == linestart "/Makefile" { system(cmd) }
225
226 sync-mi:
227 @set -eu; \
228 cd "${MAKEFILE:tA:H}/../../.."; \
229 mi="distrib/sets/lists/tests/mi"; \
230 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
231 mv -f "$$mi.$@" "$$mi"; \
232 cvs diff "$$mi" || true
233
234 .if exists(${TEST_MAKE})
235 ${TESTS:=.rawout}: ${TEST_MAKE}
236 .endif
237
238 .-include <bsd.obj.mk>
239