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