Makefile revision 1.155 1 # $NetBSD: Makefile,v 1.155 2020/09/29 18:16:24 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
39 TESTS+= archive-suffix
40 TESTS+= cmd-interrupt
41 TESTS+= cmdline
42 TESTS+= comment
43 TESTS+= cond-cmp-numeric
44 TESTS+= cond-cmp-numeric-eq
45 TESTS+= cond-cmp-numeric-ge
46 TESTS+= cond-cmp-numeric-gt
47 TESTS+= cond-cmp-numeric-le
48 TESTS+= cond-cmp-numeric-lt
49 TESTS+= cond-cmp-numeric-ne
50 TESTS+= cond-cmp-string
51 TESTS+= cond-cmp-unary
52 TESTS+= cond-func
53 TESTS+= cond-func-commands
54 TESTS+= cond-func-defined
55 TESTS+= cond-func-empty
56 TESTS+= cond-func-exists
57 TESTS+= cond-func-make
58 TESTS+= cond-func-target
59 TESTS+= cond-late
60 TESTS+= cond-op
61 TESTS+= cond-op-and
62 TESTS+= cond-op-not
63 TESTS+= cond-op-or
64 TESTS+= cond-op-parentheses
65 TESTS+= cond-short
66 TESTS+= cond-token-number
67 TESTS+= cond-token-plain
68 TESTS+= cond-token-string
69 TESTS+= cond-token-var
70 TESTS+= cond-undef-lint
71 TESTS+= cond1
72 TESTS+= cond2
73 TESTS+= counter
74 TESTS+= counter-append
75 TESTS+= dep
76 TESTS+= dep-colon
77 TESTS+= dep-colon-bug-cross-file
78 TESTS+= dep-double-colon
79 TESTS+= dep-exclam
80 TESTS+= dep-none
81 TESTS+= dep-var
82 TESTS+= dep-wildcards
83 TESTS+= depsrc
84 TESTS+= depsrc-exec
85 TESTS+= depsrc-ignore
86 TESTS+= depsrc-made
87 TESTS+= depsrc-make
88 TESTS+= depsrc-meta
89 TESTS+= depsrc-nometa
90 TESTS+= depsrc-nometa_cmp
91 TESTS+= depsrc-nopath
92 TESTS+= depsrc-notmain
93 TESTS+= depsrc-optional
94 TESTS+= depsrc-phony
95 TESTS+= depsrc-precious
96 TESTS+= depsrc-recursive
97 TESTS+= depsrc-silent
98 TESTS+= depsrc-use
99 TESTS+= depsrc-usebefore
100 TESTS+= depsrc-usebefore-double-colon
101 TESTS+= depsrc-wait
102 TESTS+= deptgt
103 TESTS+= deptgt-begin
104 TESTS+= deptgt-default
105 TESTS+= deptgt-delete_on_error
106 TESTS+= deptgt-end
107 TESTS+= deptgt-end-jobs
108 TESTS+= deptgt-error
109 TESTS+= deptgt-ignore
110 TESTS+= deptgt-interrupt
111 TESTS+= deptgt-main
112 TESTS+= deptgt-makeflags
113 TESTS+= deptgt-no_parallel
114 TESTS+= deptgt-nopath
115 TESTS+= deptgt-notparallel
116 TESTS+= deptgt-objdir
117 TESTS+= deptgt-order
118 TESTS+= deptgt-path
119 TESTS+= deptgt-path-suffix
120 TESTS+= deptgt-phony
121 TESTS+= deptgt-precious
122 TESTS+= deptgt-shell
123 TESTS+= deptgt-silent
124 TESTS+= deptgt-stale
125 TESTS+= deptgt-suffixes
126 TESTS+= dir
127 TESTS+= dir-expand-path
128 TESTS+= directive
129 TESTS+= directive-dinclude
130 TESTS+= directive-elif
131 TESTS+= directive-elifdef
132 TESTS+= directive-elifmake
133 TESTS+= directive-elifndef
134 TESTS+= directive-elifnmake
135 TESTS+= directive-else
136 TESTS+= directive-endif
137 TESTS+= directive-error
138 TESTS+= directive-export
139 TESTS+= directive-export-env
140 TESTS+= directive-export-literal
141 TESTS+= directive-for
142 TESTS+= directive-for-generating-endif
143 TESTS+= directive-hyphen-include
144 TESTS+= directive-if
145 TESTS+= directive-ifdef
146 TESTS+= directive-ifmake
147 TESTS+= directive-ifndef
148 TESTS+= directive-ifnmake
149 TESTS+= directive-include
150 TESTS+= directive-include-fatal
151 TESTS+= directive-info
152 TESTS+= directive-sinclude
153 TESTS+= directive-undef
154 TESTS+= directive-unexport
155 TESTS+= directive-unexport-env
156 TESTS+= directive-warning
157 TESTS+= directives
158 TESTS+= dollar
159 TESTS+= doterror
160 TESTS+= dotwait
161 TESTS+= envfirst
162 TESTS+= error
163 TESTS+= # escape # broken by reverting POSIX changes
164 TESTS+= export
165 TESTS+= export-all
166 TESTS+= export-env
167 TESTS+= export-variants
168 TESTS+= forloop
169 TESTS+= forsubst
170 TESTS+= impsrc
171 TESTS+= include-main
172 TESTS+= job-output-long-lines
173 TESTS+= lint
174 TESTS+= make-exported
175 TESTS+= misc
176 TESTS+= moderrs
177 TESTS+= modmatch
178 TESTS+= modmisc
179 TESTS+= modts
180 TESTS+= modword
181 TESTS+= opt
182 TESTS+= opt-backwards
183 TESTS+= opt-chdir
184 TESTS+= opt-debug
185 TESTS+= opt-debug-all
186 TESTS+= opt-debug-archive
187 TESTS+= opt-debug-curdir
188 TESTS+= opt-debug-cond
189 TESTS+= opt-debug-dir
190 TESTS+= opt-debug-errors
191 TESTS+= opt-debug-file
192 TESTS+= opt-debug-for
193 TESTS+= opt-debug-graph1
194 TESTS+= opt-debug-graph2
195 TESTS+= opt-debug-graph3
196 TESTS+= opt-debug-hash
197 TESTS+= opt-debug-jobs
198 TESTS+= opt-debug-lint
199 TESTS+= opt-debug-loud
200 TESTS+= opt-debug-meta
201 TESTS+= opt-debug-making
202 TESTS+= opt-debug-no-rm
203 TESTS+= opt-debug-parse
204 TESTS+= opt-debug-suff
205 TESTS+= opt-debug-targets
206 TESTS+= opt-debug-varraw
207 TESTS+= opt-debug-var
208 TESTS+= opt-debug-x-trace
209 TESTS+= opt-define
210 TESTS+= opt-env
211 TESTS+= opt-file
212 TESTS+= opt-ignore
213 TESTS+= opt-include-dir
214 TESTS+= opt-jobs
215 TESTS+= opt-jobs-internal
216 TESTS+= opt-keep-going
217 TESTS+= opt-m-include-dir
218 TESTS+= opt-no-action
219 TESTS+= opt-no-action-at-all
220 TESTS+= opt-query
221 TESTS+= opt-raw
222 TESTS+= opt-silent
223 TESTS+= opt-touch
224 TESTS+= opt-tracefile
225 TESTS+= opt-var-expanded
226 TESTS+= opt-var-literal
227 TESTS+= opt-warnings-as-errors
228 TESTS+= opt-where-am-i
229 TESTS+= opt-x-reduce-exported
230 TESTS+= order
231 TESTS+= phony-end
232 TESTS+= posix
233 TESTS+= # posix1 # broken by reverting POSIX changes
234 TESTS+= qequals
235 TESTS+= recursive
236 TESTS+= sh
237 TESTS+= sh-dots
238 TESTS+= sh-jobs
239 TESTS+= sh-jobs-error
240 TESTS+= sh-leading-at
241 TESTS+= sh-leading-hyphen
242 TESTS+= sh-leading-plus
243 TESTS+= sh-meta-chars
244 TESTS+= sh-multi-line
245 TESTS+= sh-single-line
246 TESTS+= # suffixes # runs into an endless loop (try -dA)
247 TESTS+= suff-rebuild
248 TESTS+= sunshcmd
249 TESTS+= sysv
250 TESTS+= ternary
251 TESTS+= unexport
252 TESTS+= unexport-env
253 TESTS+= use-inference
254 TESTS+= var-class
255 TESTS+= var-class-cmdline
256 TESTS+= var-class-env
257 TESTS+= var-class-global
258 TESTS+= var-class-local
259 TESTS+= var-class-local-legacy
260 TESTS+= var-op
261 TESTS+= var-op-append
262 TESTS+= var-op-assign
263 TESTS+= var-op-default
264 TESTS+= var-op-expand
265 TESTS+= var-op-shell
266 TESTS+= varcmd
267 TESTS+= vardebug
268 TESTS+= varfind
269 TESTS+= varmisc
270 TESTS+= varmod
271 TESTS+= varmod-assign
272 TESTS+= varmod-defined
273 TESTS+= varmod-edge
274 TESTS+= varmod-exclam-shell
275 TESTS+= varmod-extension
276 TESTS+= varmod-gmtime
277 TESTS+= varmod-hash
278 TESTS+= varmod-head
279 TESTS+= varmod-ifelse
280 TESTS+= varmod-l-name-to-value
281 TESTS+= varmod-localtime
282 TESTS+= varmod-loop
283 TESTS+= varmod-match
284 TESTS+= varmod-match-escape
285 TESTS+= varmod-no-match
286 TESTS+= varmod-order
287 TESTS+= varmod-order-reverse
288 TESTS+= varmod-order-shuffle
289 TESTS+= varmod-path
290 TESTS+= varmod-quote
291 TESTS+= varmod-quote-dollar
292 TESTS+= varmod-range
293 TESTS+= varmod-remember
294 TESTS+= varmod-root
295 TESTS+= varmod-select-words
296 TESTS+= varmod-shell
297 TESTS+= varmod-subst
298 TESTS+= varmod-subst-regex
299 TESTS+= varmod-sysv
300 TESTS+= varmod-tail
301 TESTS+= varmod-to-abs
302 TESTS+= varmod-to-lower
303 TESTS+= varmod-to-many-words
304 TESTS+= varmod-to-one-word
305 TESTS+= varmod-to-separator
306 TESTS+= varmod-to-upper
307 TESTS+= varmod-undefined
308 TESTS+= varmod-unique
309 TESTS+= varname
310 TESTS+= varname-dollar
311 TESTS+= varname-dot-alltargets
312 TESTS+= varname-dot-curdir
313 TESTS+= varname-dot-includes
314 TESTS+= varname-dot-includedfromdir
315 TESTS+= varname-dot-includedfromfile
316 TESTS+= varname-dot-libs
317 TESTS+= varname-dot-make-dependfile
318 TESTS+= varname-dot-make-expand_variables
319 TESTS+= varname-dot-make-exported
320 TESTS+= varname-dot-make-jobs
321 TESTS+= varname-dot-make-jobs-prefix
322 TESTS+= varname-dot-make-level
323 TESTS+= varname-dot-make-makefile_preference
324 TESTS+= varname-dot-make-makefiles
325 TESTS+= varname-dot-make-meta-bailiwick
326 TESTS+= varname-dot-make-meta-created
327 TESTS+= varname-dot-make-meta-files
328 TESTS+= varname-dot-make-meta-ignore_filter
329 TESTS+= varname-dot-make-meta-ignore_paths
330 TESTS+= varname-dot-make-meta-ignore_patterns
331 TESTS+= varname-dot-make-meta-prefix
332 TESTS+= varname-dot-make-mode
333 TESTS+= varname-dot-make-path_filemon
334 TESTS+= varname-dot-make-pid
335 TESTS+= varname-dot-make-ppid
336 TESTS+= varname-dot-make-save_dollars
337 TESTS+= varname-dot-makeoverrides
338 TESTS+= varname-dot-newline
339 TESTS+= varname-dot-objdir
340 TESTS+= varname-dot-parsedir
341 TESTS+= varname-dot-parsefile
342 TESTS+= varname-dot-path
343 TESTS+= varname-dot-shell
344 TESTS+= varname-dot-targets
345 TESTS+= varname-empty
346 TESTS+= varname-make
347 TESTS+= varname-make_print_var_on_error
348 TESTS+= varname-makefile
349 TESTS+= varname-makeflags
350 TESTS+= varname-pwd
351 TESTS+= varname-vpath
352 TESTS+= varparse-dynamic
353 TESTS+= varparse-undef-partial
354 TESTS+= varquote
355 TESTS+= varshell
356
357 # Additional environment variables for some of the tests.
358 # The base environment is -i PATH="$PATH".
359 ENV.envfirst= FROM_ENV=value-from-env
360 ENV.varmisc= FROM_ENV=env
361 ENV.varmisc+= FROM_ENV_BEFORE=env
362 ENV.varmisc+= FROM_ENV_AFTER=env
363
364 # Override make flags for some of the tests; default is -k.
365 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
366 # settings FLAGS.test=-dv here, since that is closer to the test code.
367 FLAGS.cond-func-make= via-cmdline
368 FLAGS.directive-ifmake= first second
369 FLAGS.doterror= # none
370 FLAGS.envfirst= -e
371 FLAGS.export= # none
372 FLAGS.opt-ignore= -i
373 FLAGS.opt-keep-going= -k
374 FLAGS.opt-no-action= -n
375 FLAGS.opt-query= -q
376 FLAGS.opt-var-expanded= -v VAR -v VALUE
377 FLAGS.opt-var-literal= -V VAR -V VALUE
378 FLAGS.opt-warnings-as-errors= -W
379 FLAGS.order= -j1
380 FLAGS.recursive= -dL
381 FLAGS.sh-leading-plus= -n
382 FLAGS.vardebug= -k -dv FROM_CMDLINE=
383 FLAGS.varmod-match-escape= -dv
384 FLAGS.varname-dot-shell= -dpv
385 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
386
387 # Some tests need extra postprocessing.
388 SED_CMDS.job-output-long-lines= \
389 ${:D Job separators on their own line are ok. } \
390 -e '/^--- job-[ab] ---$$/d' \
391 ${:D Plain output lines are ok as well. } \
392 ${:D They may come in multiples of 1024 or as 10000. } \
393 -e '/^aa*$$/d' \
394 -e '/^bb*$$/d' \
395 ${:D The following lines should rather not occur since the job } \
396 ${:D marker should always be at the beginning of the line. } \
397 -e '/^aa*--- job-b ---$$/d' \
398 -e '/^bb*--- job-a ---$$/d'
399 SED_CMDS.opt-debug-graph1= \
400 -e 's,${.CURDIR},CURDIR,'
401 SED_CMDS.opt-debug-graph1+= \
402 -e '/Global Variables:/,/Suffixes:/d'
403 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
404 SED_CMDS.varmod-subst-regex+= \
405 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
406 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
407 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
408 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
409 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
410 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
411 SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),'
412 SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",'
413 SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],'
414
415 # Some tests need an additional round of postprocessing.
416 POSTPROC.deptgt-suffixes= \
417 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
418 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
419 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
420 POSTPROC.varname= ${TOOL_SED} -n -e '/^MAGIC/p' -e '/^ORDER_/p'
421 POSTPROC.varname-dot-shell= \
422 awk '/\.SHELL/ || /^ParseReadLine/'
423 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
424
425 # Some tests reuse other tests, which makes them unnecessarily fragile.
426 export-all.rawout: export.mk
427 unexport.rawout: export.mk
428 unexport-env.rawout: export.mk
429
430 # End of the configuration section.
431
432 .MAIN: all
433
434 UNIT_TESTS:= ${.PARSEDIR}
435 .PATH: ${UNIT_TESTS}
436
437 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
438 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@}
439 .else
440 OUTFILES= ${TESTS:=.out}
441 .endif
442
443 all: ${OUTFILES}
444
445 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
446 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
447 CLEANFILES+= issue* .[ab]* # suffixes.mk
448 CLEANDIRS= dir dummy # posix1.mk
449
450 clean:
451 rm -f ${CLEANFILES}
452 rm -rf ${CLEANDIRS}
453
454 TEST_MAKE?= ${.MAKE}
455 TOOL_SED?= sed
456
457 # ensure consistent results from sort(1)
458 LC_ALL= C
459 LANG= C
460 .export LANG LC_ALL
461
462 MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc
463
464 # Each test is run in a sub-make, to keep the tests for interfering with
465 # each other, and because they use different environment variables and
466 # command line options.
467 .SUFFIXES: .mk .rawout .out
468 .mk.rawout:
469 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
470 @set -eu; \
471 cd ${.OBJDIR}; \
472 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
473 ${TEST_MAKE} \
474 -r -C ${.CURDIR} -f ${.IMPSRC} \
475 ${FLAGS.${.PREFIX:T}:U-k} \
476 > ${.TARGET}.tmp 2>&1 \
477 && status=$$? || status=$$?; \
478 echo $$status > ${.TARGET:R}.status
479 @mv ${.TARGET}.tmp ${.TARGET}
480
481 # Postprocess the test output so that the results can be compared.
482 #
483 # always pretend .MAKE was called 'make'
484 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
485 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
486 # replace anything after 'stopped in' with unit-tests
487 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
488 # strip ${.CURDIR}/ from the output
489 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
490 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
491
492 .rawout.out:
493 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
494 < ${.IMPSRC} > ${.TARGET}.tmp1
495 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
496 @rm ${.TARGET}.tmp1
497 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
498 @mv ${.TARGET}.tmp2 ${.TARGET}
499
500 # Compare all output files
501 test: ${OUTFILES} .PHONY
502 @failed= ; \
503 for test in ${TESTS}; do \
504 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
505 || failed="$${failed}$${failed:+ }$${test}" ; \
506 done ; \
507 if [ -n "$${failed}" ]; then \
508 echo "Failed tests: $${failed}" ; false ; \
509 else \
510 echo "All tests passed" ; \
511 fi
512
513 accept:
514 @for test in ${TESTS}; do \
515 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
516 || { echo "Replacing $${test}.exp" ; \
517 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
518 done
519
520 # Note: only works for adding tests.
521 # To remove a test, the $$mi file must be edited manually.
522 sync-mi:
523 @set -eu; \
524 cd "${MAKEFILE:tA:H}/../../.."; \
525 mi="distrib/sets/lists/tests/mi"; \
526 cvs update "$$mi"; \
527 testsdir="usr.bin/make/unit-tests"; \
528 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
529 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi"; \
530 distrib/sets/fmt-list "$$mi"; \
531 cvs diff "$$mi" || true
532
533 .if exists(${TEST_MAKE})
534 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
535 .endif
536
537 .-include <bsd.obj.mk>
538