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