Makefile revision 1.190 1 # $NetBSD: Makefile,v 1.190 2020/11/07 23:25:06 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-not
66 TESTS+= cond-op-or
67 TESTS+= cond-op-parentheses
68 TESTS+= cond-short
69 TESTS+= cond-token-number
70 TESTS+= cond-token-plain
71 TESTS+= cond-token-string
72 TESTS+= cond-token-var
73 TESTS+= cond-undef-lint
74 TESTS+= cond1
75 TESTS+= counter
76 TESTS+= counter-append
77 TESTS+= dep
78 TESTS+= dep-colon
79 TESTS+= dep-colon-bug-cross-file
80 TESTS+= dep-double-colon
81 TESTS+= dep-double-colon-indep
82 TESTS+= dep-exclam
83 TESTS+= dep-none
84 TESTS+= dep-percent
85 TESTS+= dep-var
86 TESTS+= dep-wildcards
87 TESTS+= depsrc
88 TESTS+= depsrc-end
89 TESTS+= depsrc-exec
90 TESTS+= depsrc-ignore
91 TESTS+= depsrc-made
92 TESTS+= depsrc-make
93 TESTS+= depsrc-meta
94 TESTS+= depsrc-nometa
95 TESTS+= depsrc-nometa_cmp
96 TESTS+= depsrc-nopath
97 TESTS+= depsrc-notmain
98 TESTS+= depsrc-optional
99 TESTS+= depsrc-phony
100 TESTS+= depsrc-precious
101 TESTS+= depsrc-recursive
102 TESTS+= depsrc-silent
103 TESTS+= depsrc-use
104 TESTS+= depsrc-usebefore
105 TESTS+= depsrc-usebefore-double-colon
106 TESTS+= depsrc-wait
107 TESTS+= deptgt
108 TESTS+= deptgt-begin
109 TESTS+= deptgt-default
110 TESTS+= deptgt-delete_on_error
111 TESTS+= deptgt-end
112 TESTS+= deptgt-end-jobs
113 TESTS+= deptgt-error
114 TESTS+= deptgt-ignore
115 TESTS+= deptgt-interrupt
116 TESTS+= deptgt-main
117 TESTS+= deptgt-makeflags
118 TESTS+= deptgt-no_parallel
119 TESTS+= deptgt-nopath
120 TESTS+= deptgt-notparallel
121 TESTS+= deptgt-objdir
122 TESTS+= deptgt-order
123 TESTS+= deptgt-path
124 TESTS+= deptgt-path-suffix
125 TESTS+= deptgt-phony
126 TESTS+= deptgt-precious
127 TESTS+= deptgt-shell
128 TESTS+= deptgt-silent
129 TESTS+= deptgt-stale
130 TESTS+= deptgt-suffixes
131 TESTS+= dir
132 TESTS+= dir-expand-path
133 TESTS+= directive
134 TESTS+= directive-dinclude
135 TESTS+= directive-elif
136 TESTS+= directive-elifdef
137 TESTS+= directive-elifmake
138 TESTS+= directive-elifndef
139 TESTS+= directive-elifnmake
140 TESTS+= directive-else
141 TESTS+= directive-endif
142 TESTS+= directive-error
143 TESTS+= directive-export
144 TESTS+= directive-export-env
145 TESTS+= directive-export-gmake
146 TESTS+= directive-export-literal
147 TESTS+= directive-for
148 TESTS+= directive-for-generating-endif
149 TESTS+= directive-hyphen-include
150 TESTS+= directive-if
151 TESTS+= directive-ifdef
152 TESTS+= directive-ifmake
153 TESTS+= directive-ifndef
154 TESTS+= directive-ifnmake
155 TESTS+= directive-include
156 TESTS+= directive-include-fatal
157 TESTS+= directive-info
158 TESTS+= directive-sinclude
159 TESTS+= directive-undef
160 TESTS+= directive-unexport
161 TESTS+= directive-unexport-env
162 TESTS+= directive-warning
163 TESTS+= dollar
164 TESTS+= doterror
165 TESTS+= dotwait
166 TESTS+= envfirst
167 TESTS+= error
168 TESTS+= # escape # broken by reverting POSIX changes
169 TESTS+= export
170 TESTS+= export-all
171 TESTS+= export-env
172 TESTS+= export-variants
173 TESTS+= forloop
174 TESTS+= forsubst
175 TESTS+= gnode-submake
176 TESTS+= hanoi-include
177 TESTS+= impsrc
178 TESTS+= include-main
179 TESTS+= job-flags
180 TESTS+= job-output-long-lines
181 TESTS+= lint
182 TESTS+= make-exported
183 TESTS+= moderrs
184 TESTS+= modmatch
185 TESTS+= modmisc
186 TESTS+= modts
187 TESTS+= modword
188 TESTS+= opt
189 TESTS+= opt-backwards
190 TESTS+= opt-chdir
191 TESTS+= opt-debug
192 TESTS+= opt-debug-all
193 TESTS+= opt-debug-archive
194 TESTS+= opt-debug-curdir
195 TESTS+= opt-debug-cond
196 TESTS+= opt-debug-dir
197 TESTS+= opt-debug-errors
198 TESTS+= opt-debug-file
199 TESTS+= opt-debug-for
200 TESTS+= opt-debug-graph1
201 TESTS+= opt-debug-graph2
202 TESTS+= opt-debug-graph3
203 TESTS+= opt-debug-hash
204 TESTS+= opt-debug-jobs
205 TESTS+= opt-debug-lint
206 TESTS+= opt-debug-loud
207 TESTS+= opt-debug-meta
208 TESTS+= opt-debug-making
209 TESTS+= opt-debug-no-rm
210 TESTS+= opt-debug-parse
211 TESTS+= opt-debug-suff
212 TESTS+= opt-debug-targets
213 TESTS+= opt-debug-varraw
214 TESTS+= opt-debug-var
215 TESTS+= opt-debug-x-trace
216 TESTS+= opt-define
217 TESTS+= opt-env
218 TESTS+= opt-file
219 TESTS+= opt-ignore
220 TESTS+= opt-include-dir
221 TESTS+= opt-jobs
222 TESTS+= opt-jobs-internal
223 TESTS+= opt-keep-going
224 TESTS+= opt-m-include-dir
225 TESTS+= opt-no-action
226 TESTS+= opt-no-action-at-all
227 TESTS+= opt-query
228 TESTS+= opt-raw
229 TESTS+= opt-silent
230 TESTS+= opt-touch
231 TESTS+= opt-tracefile
232 TESTS+= opt-var-expanded
233 TESTS+= opt-var-literal
234 TESTS+= opt-warnings-as-errors
235 TESTS+= opt-where-am-i
236 TESTS+= opt-x-reduce-exported
237 TESTS+= order
238 TESTS+= parse-var
239 TESTS+= phony-end
240 TESTS+= posix
241 TESTS+= # posix1 # broken by reverting POSIX changes
242 TESTS+= qequals
243 TESTS+= recursive
244 TESTS+= sh
245 TESTS+= sh-dots
246 TESTS+= sh-jobs
247 TESTS+= sh-jobs-error
248 TESTS+= sh-leading-at
249 TESTS+= sh-leading-hyphen
250 TESTS+= sh-leading-plus
251 TESTS+= sh-meta-chars
252 TESTS+= sh-multi-line
253 TESTS+= sh-single-line
254 TESTS+= shell-csh
255 TESTS+= shell-custom
256 TESTS+= shell-ksh
257 TESTS+= shell-sh
258 TESTS+= suff-add-later
259 TESTS+= suff-clear-regular
260 TESTS+= suff-clear-single
261 TESTS+= suff-lookup
262 TESTS+= suff-main
263 TESTS+= suff-rebuild
264 TESTS+= suff-transform-endless
265 TESTS+= suff-transform-expand
266 TESTS+= suff-transform-select
267 TESTS+= sunshcmd
268 TESTS+= ternary
269 TESTS+= unexport
270 TESTS+= unexport-env
271 TESTS+= use-inference
272 TESTS+= var-class
273 TESTS+= var-class-cmdline
274 TESTS+= var-class-env
275 TESTS+= var-class-global
276 TESTS+= var-class-local
277 TESTS+= var-class-local-legacy
278 TESTS+= var-op
279 TESTS+= var-op-append
280 TESTS+= var-op-assign
281 TESTS+= var-op-default
282 TESTS+= var-op-expand
283 TESTS+= var-op-shell
284 TESTS+= var-op-sunsh
285 TESTS+= var-recursive
286 TESTS+= varcmd
287 TESTS+= vardebug
288 TESTS+= varfind
289 TESTS+= varmisc
290 TESTS+= varmod
291 TESTS+= varmod-assign
292 TESTS+= varmod-defined
293 TESTS+= varmod-edge
294 TESTS+= varmod-exclam-shell
295 TESTS+= varmod-extension
296 TESTS+= varmod-gmtime
297 TESTS+= varmod-hash
298 TESTS+= varmod-head
299 TESTS+= varmod-ifelse
300 TESTS+= varmod-l-name-to-value
301 TESTS+= varmod-localtime
302 TESTS+= varmod-loop
303 TESTS+= varmod-match
304 TESTS+= varmod-match-escape
305 TESTS+= varmod-no-match
306 TESTS+= varmod-order
307 TESTS+= varmod-order-reverse
308 TESTS+= varmod-order-shuffle
309 TESTS+= varmod-path
310 TESTS+= varmod-quote
311 TESTS+= varmod-quote-dollar
312 TESTS+= varmod-range
313 TESTS+= varmod-remember
314 TESTS+= varmod-root
315 TESTS+= varmod-select-words
316 TESTS+= varmod-shell
317 TESTS+= varmod-subst
318 TESTS+= varmod-subst-regex
319 TESTS+= varmod-sysv
320 TESTS+= varmod-tail
321 TESTS+= varmod-to-abs
322 TESTS+= varmod-to-lower
323 TESTS+= varmod-to-many-words
324 TESTS+= varmod-to-one-word
325 TESTS+= varmod-to-separator
326 TESTS+= varmod-to-upper
327 TESTS+= varmod-undefined
328 TESTS+= varmod-unique
329 TESTS+= varname
330 TESTS+= varname-dollar
331 TESTS+= varname-dot-alltargets
332 TESTS+= varname-dot-curdir
333 TESTS+= varname-dot-includes
334 TESTS+= varname-dot-includedfromdir
335 TESTS+= varname-dot-includedfromfile
336 TESTS+= varname-dot-libs
337 TESTS+= varname-dot-make-dependfile
338 TESTS+= varname-dot-make-expand_variables
339 TESTS+= varname-dot-make-exported
340 TESTS+= varname-dot-make-jobs
341 TESTS+= varname-dot-make-jobs-prefix
342 TESTS+= varname-dot-make-level
343 TESTS+= varname-dot-make-makefile_preference
344 TESTS+= varname-dot-make-makefiles
345 TESTS+= varname-dot-make-meta-bailiwick
346 TESTS+= varname-dot-make-meta-created
347 TESTS+= varname-dot-make-meta-files
348 TESTS+= varname-dot-make-meta-ignore_filter
349 TESTS+= varname-dot-make-meta-ignore_paths
350 TESTS+= varname-dot-make-meta-ignore_patterns
351 TESTS+= varname-dot-make-meta-prefix
352 TESTS+= varname-dot-make-mode
353 TESTS+= varname-dot-make-path_filemon
354 TESTS+= varname-dot-make-pid
355 TESTS+= varname-dot-make-ppid
356 TESTS+= varname-dot-make-save_dollars
357 TESTS+= varname-dot-makeoverrides
358 TESTS+= varname-dot-newline
359 TESTS+= varname-dot-objdir
360 TESTS+= varname-dot-parsedir
361 TESTS+= varname-dot-parsefile
362 TESTS+= varname-dot-path
363 TESTS+= varname-dot-shell
364 TESTS+= varname-dot-targets
365 TESTS+= varname-empty
366 TESTS+= varname-make
367 TESTS+= varname-make_print_var_on_error
368 TESTS+= varname-make_print_var_on_error-jobs
369 TESTS+= varname-makefile
370 TESTS+= varname-makeflags
371 TESTS+= varname-pwd
372 TESTS+= varname-vpath
373 TESTS+= varparse-dynamic
374 TESTS+= varparse-mod
375 TESTS+= varparse-undef-partial
376 TESTS+= varquote
377 TESTS+= varshell
378
379 # Additional environment variables for some of the tests.
380 # The base environment is -i PATH="$PATH".
381 ENV.envfirst= FROM_ENV=value-from-env
382 ENV.varmisc= FROM_ENV=env
383 ENV.varmisc+= FROM_ENV_BEFORE=env
384 ENV.varmisc+= FROM_ENV_AFTER=env
385 ENV.varmod-localtime+= TZ=Europe/Berlin
386
387 # Override make flags for some of the tests; default is -k.
388 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
389 # settings FLAGS.test=-dv here, since that is closer to the test code.
390 FLAGS.cond-func-make= via-cmdline
391 FLAGS.directive-ifmake= first second
392 FLAGS.doterror= # none
393 FLAGS.envfirst= -e
394 FLAGS.export= # none
395 FLAGS.opt-ignore= -i
396 FLAGS.opt-keep-going= -k
397 FLAGS.opt-no-action= -n
398 FLAGS.opt-query= -q
399 FLAGS.opt-var-expanded= -v VAR -v VALUE
400 FLAGS.opt-var-literal= -V VAR -V VALUE
401 FLAGS.opt-warnings-as-errors= -W
402 FLAGS.order= -j1
403 FLAGS.recursive= -dL
404 FLAGS.sh-leading-plus= -n
405 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
406
407 # Some tests need extra postprocessing.
408 SED_CMDS.job-output-long-lines= \
409 ${:D Job separators on their own line are ok. } \
410 -e '/^--- job-[ab] ---$$/d' \
411 ${:D Plain output lines are ok as well. } \
412 ${:D They may come in multiples of 1024 or as 10000. } \
413 -e '/^aa*$$/d' \
414 -e '/^bb*$$/d' \
415 ${:D The following lines should rather not occur since the job } \
416 ${:D marker should always be at the beginning of the line. } \
417 -e '/^aa*--- job-b ---$$/d' \
418 -e '/^bb*--- job-a ---$$/d'
419 SED_CMDS.opt-debug-graph1= \
420 -e 's,${.CURDIR},CURDIR,'
421 SED_CMDS.opt-debug-graph1+= \
422 -e '/Global Variables:/,/Suffixes:/d'
423 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
424 SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
425 SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
426 SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
427 SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
428 # The "-q" may be there or not, see jobs.c, variable shells.
429 SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: sh\) -q,\1,'
430 SED_CMDS.varmod-subst-regex+= \
431 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
432 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
433 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
434 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
435 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
436 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
437 SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g'
438 SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g'
439 SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g'
440
441 # Some tests need an additional round of postprocessing.
442 POSTPROC.deptgt-suffixes= \
443 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
444 POSTPROC.gnode-submake= awk '/Input graph/, /^$$/'
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 cat "$$mi" > "$$mi.tmp"; \
552 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \
553 distrib/sets/fmt-list "$$mi.tmp"; \
554 mv "$$mi.tmp" "$$mi"; \
555 cvs diff "$$mi" || true
556
557 .if exists(${TEST_MAKE})
558 ${TESTS:=.rawout}: ${TEST_MAKE}
559 # in meta mode, we *know* if a target script is impacted
560 # by a makefile change.
561 .if ${.MAKE.MODE:Unormal:Mmeta} == ""
562 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
563 .endif
564 .endif
565
566 .-include <bsd.obj.mk>
567