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