Makefile revision 1.103 1 # $NetBSD: Makefile,v 1.103 2020/08/20 17:45:47 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 # Any test that is commented out must be ignored in
37 # src/tests/usr.bin/make/t_make.sh as well.
38 TESTS+= # archive # broken on FreeBSD, enabled in t_make.sh
39 TESTS+= cmdline
40 TESTS+= comment
41 TESTS+= cond-cmp-numeric
42 TESTS+= cond-cmp-string
43 TESTS+= cond-func
44 TESTS+= cond-func-commands
45 TESTS+= cond-func-defined
46 TESTS+= cond-func-empty
47 TESTS+= cond-func-exists
48 TESTS+= cond-func-make
49 TESTS+= cond-func-target
50 TESTS+= cond-late
51 TESTS+= cond-op
52 TESTS+= cond-op-and
53 TESTS+= cond-op-not
54 TESTS+= cond-op-or
55 TESTS+= cond-op-parentheses
56 TESTS+= cond-short
57 TESTS+= cond-token-number
58 TESTS+= cond-token-plain
59 TESTS+= cond-token-string
60 TESTS+= cond-token-var
61 TESTS+= cond1
62 TESTS+= cond2
63 TESTS+= counter
64 TESTS+= dep
65 TESTS+= dep-colon
66 TESTS+= dep-double-colon
67 TESTS+= dep-exclam
68 TESTS+= dep-wildcards
69 TESTS+= depsrc
70 TESTS+= depsrc-exec
71 TESTS+= depsrc-ignore
72 TESTS+= depsrc-made
73 TESTS+= depsrc-make
74 TESTS+= depsrc-meta
75 TESTS+= depsrc-nometa
76 TESTS+= depsrc-nometa_cmp
77 TESTS+= depsrc-nopath
78 TESTS+= depsrc-notmain
79 TESTS+= depsrc-optional
80 TESTS+= depsrc-phony
81 TESTS+= depsrc-precious
82 TESTS+= depsrc-recursive
83 TESTS+= depsrc-silent
84 TESTS+= depsrc-use
85 TESTS+= depsrc-usebefore
86 TESTS+= depsrc-wait
87 TESTS+= deptgt
88 TESTS+= deptgt-begin
89 TESTS+= deptgt-default
90 TESTS+= deptgt-delete_on_error
91 TESTS+= deptgt-end
92 TESTS+= deptgt-error
93 TESTS+= deptgt-ignore
94 TESTS+= deptgt-interrupt
95 TESTS+= deptgt-main
96 TESTS+= deptgt-makeflags
97 TESTS+= deptgt-no_parallel
98 TESTS+= deptgt-nopath
99 TESTS+= deptgt-notparallel
100 TESTS+= deptgt-objdir
101 TESTS+= deptgt-order
102 TESTS+= deptgt-path
103 TESTS+= deptgt-path-suffix
104 TESTS+= deptgt-phony
105 TESTS+= deptgt-precious
106 TESTS+= deptgt-shell
107 TESTS+= deptgt-silent
108 TESTS+= deptgt-stale
109 TESTS+= deptgt-suffixes
110 TESTS+= dir
111 TESTS+= directive
112 TESTS+= directive-elif
113 TESTS+= directive-elifdef
114 TESTS+= directive-elifmake
115 TESTS+= directive-elifndef
116 TESTS+= directive-elifnmake
117 TESTS+= directive-else
118 TESTS+= directive-endif
119 TESTS+= directive-error
120 TESTS+= directive-export
121 TESTS+= directive-export-env
122 TESTS+= directive-export-literal
123 TESTS+= directive-if
124 TESTS+= directive-ifdef
125 TESTS+= directive-ifmake
126 TESTS+= directive-ifndef
127 TESTS+= directive-ifnmake
128 TESTS+= directive-info
129 TESTS+= directive-undef
130 TESTS+= directive-unexport
131 TESTS+= directive-unexport-env
132 TESTS+= directive-warning
133 TESTS+= directives
134 TESTS+= dollar
135 TESTS+= doterror
136 TESTS+= dotwait
137 TESTS+= envfirst
138 TESTS+= error
139 TESTS+= # escape # broken by reverting POSIX changes
140 TESTS+= export
141 TESTS+= export-all
142 TESTS+= export-env
143 TESTS+= export-variants
144 TESTS+= forloop
145 TESTS+= forsubst
146 TESTS+= hash
147 TESTS+= impsrc
148 TESTS+= include-main
149 TESTS+= lint
150 TESTS+= make-exported
151 TESTS+= misc
152 TESTS+= moderrs
153 TESTS+= modmatch
154 TESTS+= modmisc
155 TESTS+= modts
156 TESTS+= modword
157 TESTS+= opt
158 TESTS+= opt-backwards
159 TESTS+= opt-chdir
160 TESTS+= opt-debug
161 TESTS+= opt-define
162 TESTS+= opt-env
163 TESTS+= opt-file
164 TESTS+= opt-ignore
165 TESTS+= opt-include-dir
166 TESTS+= opt-jobs
167 TESTS+= opt-jobs-internal
168 TESTS+= opt-keep-going
169 TESTS+= opt-m-include-dir
170 TESTS+= opt-no-action
171 TESTS+= opt-no-action-at-all
172 TESTS+= opt-query
173 TESTS+= opt-raw
174 TESTS+= opt-silent
175 TESTS+= opt-touch
176 TESTS+= opt-tracefile
177 TESTS+= opt-var-expanded
178 TESTS+= opt-var-literal
179 TESTS+= opt-warnings-as-errors
180 TESTS+= opt-where-am-i
181 TESTS+= opt-x-reduce-exported
182 TESTS+= order
183 TESTS+= phony-end
184 TESTS+= posix
185 TESTS+= # posix1 # broken by reverting POSIX changes
186 TESTS+= qequals
187 TESTS+= recursive
188 TESTS+= sh
189 TESTS+= sh-jobs
190 TESTS+= sh-jobs-error
191 TESTS+= sh-leading-at
192 TESTS+= sh-leading-hyphen
193 TESTS+= sh-leading-plus
194 TESTS+= sh-meta-chars
195 TESTS+= sh-multi-line
196 TESTS+= sh-single-line
197 TESTS+= # suffixes # runs into an endless loop (try -dA)
198 TESTS+= sunshcmd
199 TESTS+= sysv
200 TESTS+= ternary
201 TESTS+= unexport
202 TESTS+= unexport-env
203 TESTS+= use-inference
204 TESTS+= var-class
205 TESTS+= var-class-cmdline
206 TESTS+= var-class-env
207 TESTS+= var-class-global
208 TESTS+= var-class-local
209 TESTS+= var-class-local-legacy
210 TESTS+= var-op
211 TESTS+= var-op-append
212 TESTS+= var-op-assign
213 TESTS+= var-op-default
214 TESTS+= var-op-expand
215 TESTS+= var-op-shell
216 TESTS+= varcmd
217 TESTS+= vardebug
218 TESTS+= varfind
219 TESTS+= varmisc
220 TESTS+= varmod
221 TESTS+= varmod-assign
222 TESTS+= varmod-defined
223 TESTS+= varmod-edge
224 TESTS+= varmod-exclam-shell
225 TESTS+= varmod-extension
226 TESTS+= varmod-gmtime
227 TESTS+= varmod-hash
228 TESTS+= varmod-head
229 TESTS+= varmod-ifelse
230 TESTS+= varmod-l-name-to-value
231 TESTS+= varmod-localtime
232 TESTS+= varmod-loop
233 TESTS+= varmod-match
234 TESTS+= varmod-match-escape
235 TESTS+= varmod-no-match
236 TESTS+= varmod-order
237 TESTS+= varmod-order-reverse
238 TESTS+= varmod-order-shuffle
239 TESTS+= varmod-path
240 TESTS+= varmod-quote
241 TESTS+= varmod-quote-dollar
242 TESTS+= varmod-range
243 TESTS+= varmod-remember
244 TESTS+= varmod-root
245 TESTS+= varmod-select-words
246 TESTS+= varmod-shell
247 TESTS+= varmod-subst
248 TESTS+= varmod-subst-regex
249 TESTS+= varmod-sysv
250 TESTS+= varmod-tail
251 TESTS+= varmod-to-abs
252 TESTS+= varmod-to-lower
253 TESTS+= varmod-to-many-words
254 TESTS+= varmod-to-one-word
255 TESTS+= varmod-to-separator
256 TESTS+= varmod-to-upper
257 TESTS+= varmod-undefined
258 TESTS+= varmod-unique
259 TESTS+= varname
260 TESTS+= varname-dollar
261 TESTS+= varname-dot-alltargets
262 TESTS+= varname-dot-curdir
263 TESTS+= varname-dot-includedfromdir
264 TESTS+= varname-dot-includedfromfile
265 TESTS+= varname-dot-make-dependfile
266 TESTS+= varname-dot-make-expand_variables
267 TESTS+= varname-dot-make-exported
268 TESTS+= varname-dot-make-jobs
269 TESTS+= varname-dot-make-jobs-prefix
270 TESTS+= varname-dot-make-level
271 TESTS+= varname-dot-make-makefile_preference
272 TESTS+= varname-dot-make-makefiles
273 TESTS+= varname-dot-make-meta-bailiwick
274 TESTS+= varname-dot-make-meta-created
275 TESTS+= varname-dot-make-meta-files
276 TESTS+= varname-dot-make-meta-ignore_filter
277 TESTS+= varname-dot-make-meta-ignore_paths
278 TESTS+= varname-dot-make-meta-ignore_patterns
279 TESTS+= varname-dot-make-meta-prefix
280 TESTS+= varname-dot-make-mode
281 TESTS+= varname-dot-make-path_filemon
282 TESTS+= varname-dot-make-pid
283 TESTS+= varname-dot-make-ppid
284 TESTS+= varname-dot-make-save_dollars
285 TESTS+= varname-dot-makeoverrides
286 TESTS+= varname-dot-newline
287 TESTS+= varname-dot-objdir
288 TESTS+= varname-dot-parsedir
289 TESTS+= varname-dot-parsefile
290 TESTS+= varname-dot-path
291 TESTS+= varname-dot-targets
292 TESTS+= varname-make
293 TESTS+= varname-make_print_var_on_error
294 TESTS+= varname-makeflags
295 TESTS+= varname-pwd
296 TESTS+= varname-vpath
297 TESTS+= varparse-dynamic
298 TESTS+= varquote
299 TESTS+= varshell
300
301 # Additional environment variables for some of the tests.
302 # The base environment is -i PATH="$PATH".
303 ENV.envfirst= FROM_ENV=value-from-env
304 ENV.varmisc= FROM_ENV=env
305 ENV.varmisc+= FROM_ENV_BEFORE=env
306 ENV.varmisc+= FROM_ENV_AFTER=env
307
308 # Override make flags for some of the tests; default is -k.
309 FLAGS.counter= -dv
310 FLAGS.doterror= # none
311 FLAGS.envfirst= -e
312 FLAGS.export= # none
313 FLAGS.lint= -dL -k
314 FLAGS.opt-no-action= -n
315 FLAGS.opt-query= -q
316 FLAGS.order= -j1
317 FLAGS.recursive= -dL
318 FLAGS.vardebug= -k -dv FROM_CMDLINE=
319 FLAGS.varmod-match-escape= -dv
320
321 # Some tests need extra post-processing.
322 SED_CMDS.varmod-subst-regex+= \
323 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
324 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
325 SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
326 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
327
328 # Some tests need an additional round of postprocessing.
329 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
330 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
331 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
332
333 # Some tests reuse other tests, which makes them unnecessarily fragile.
334 export-all.rawout: export.mk
335 unexport.rawout: export.mk
336 unexport-env.rawout: export.mk
337
338 # End of the configuration section.
339
340 .MAIN: all
341
342 UNIT_TESTS:= ${.PARSEDIR}
343 .PATH: ${UNIT_TESTS}
344
345 OUTFILES= ${TESTS:=.out}
346
347 all: ${OUTFILES}
348
349 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
350 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
351 CLEANFILES+= issue* .[ab]* # suffixes.mk
352 CLEANDIRS= dir dummy # posix1.mk
353
354 clean:
355 rm -f ${CLEANFILES}
356 rm -rf ${CLEANDIRS}
357
358 TEST_MAKE?= ${.MAKE}
359 TOOL_SED?= sed
360
361 # ensure consistent results from sort(1)
362 LC_ALL= C
363 LANG= C
364 .export LANG LC_ALL
365
366 # the tests are actually done with sub-makes.
367 .SUFFIXES: .mk .rawout .out
368 .mk.rawout:
369 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
370 @set -eu; \
371 cd ${.OBJDIR}; \
372 env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \
373 ${TEST_MAKE} \
374 -r -C ${.CURDIR} -f ${.IMPSRC} \
375 ${FLAGS.${.TARGET:R}:U-k} \
376 > ${.TARGET}.tmp 2>&1 \
377 && status=$$? || status=$$?; \
378 echo $$status > ${.TARGET:R}.status
379 @mv ${.TARGET}.tmp ${.TARGET}
380
381 # Post-process the test output so that the results can be compared.
382 #
383 # always pretend .MAKE was called 'make'
384 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
385 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
386 # replace anything after 'stopped in' with unit-tests
387 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
388 # strip ${.CURDIR}/ from the output
389 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
390 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
391
392 .rawout.out:
393 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
394 < ${.IMPSRC} > ${.TARGET}.tmp1
395 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
396 @rm ${.TARGET}.tmp1
397 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
398 @mv ${.TARGET}.tmp2 ${.TARGET}
399
400 # Compare all output files
401 test: ${OUTFILES} .PHONY
402 @failed= ; \
403 for test in ${TESTS}; do \
404 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
405 || failed="$${failed}$${failed:+ }$${test}" ; \
406 done ; \
407 if [ -n "$${failed}" ]; then \
408 echo "Failed tests: $${failed}" ; false ; \
409 else \
410 echo "All tests passed" ; \
411 fi
412
413 accept:
414 @for test in ${TESTS}; do \
415 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
416 || { echo "Replacing $${test}.exp" ; \
417 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
418 done
419
420 SYNC_MI_AWK= \
421 BEGIN { \
422 testsdir = "usr.bin/make/unit-tests"; \
423 linestart = "./usr/tests/" testsdir; \
424 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
425 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
426 } \
427 function startswith(s, prefix) { \
428 return substr(s, 1, length(prefix)) == prefix; \
429 } \
430 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
431 { print $$0 } \
432 $$1 == linestart "/Makefile" { system(cmd) }
433
434 sync-mi:
435 @set -eu; \
436 cd "${MAKEFILE:tA:H}/../../.."; \
437 mi="distrib/sets/lists/tests/mi"; \
438 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
439 mv -f "$$mi.$@" "$$mi"; \
440 cvs diff "$$mi" || true
441
442 .if exists(${TEST_MAKE})
443 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
444 .endif
445
446 .-include <bsd.obj.mk>
447