Makefile revision 1.162 1 # $NetBSD: Makefile,v 1.162 2020/10/05 19:27:48 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-gmake
141 TESTS+= directive-export-literal
142 TESTS+= directive-for
143 TESTS+= directive-for-generating-endif
144 TESTS+= directive-hyphen-include
145 TESTS+= directive-if
146 TESTS+= directive-ifdef
147 TESTS+= directive-ifmake
148 TESTS+= directive-ifndef
149 TESTS+= directive-ifnmake
150 TESTS+= directive-include
151 TESTS+= directive-include-fatal
152 TESTS+= directive-info
153 TESTS+= directive-sinclude
154 TESTS+= directive-undef
155 TESTS+= directive-unexport
156 TESTS+= directive-unexport-env
157 TESTS+= directive-warning
158 TESTS+= directives
159 TESTS+= dollar
160 TESTS+= doterror
161 TESTS+= dotwait
162 TESTS+= envfirst
163 TESTS+= error
164 TESTS+= # escape # broken by reverting POSIX changes
165 TESTS+= export
166 TESTS+= export-all
167 TESTS+= export-env
168 TESTS+= export-variants
169 TESTS+= forloop
170 TESTS+= forsubst
171 TESTS+= hanoi-include
172 TESTS+= impsrc
173 TESTS+= include-main
174 TESTS+= job-output-long-lines
175 TESTS+= lint
176 TESTS+= make-exported
177 TESTS+= misc
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+= # suffixes # runs into an endless loop (try -dA)
254 TESTS+= suff-rebuild
255 TESTS+= sunshcmd
256 TESTS+= sysv
257 TESTS+= ternary
258 TESTS+= unexport
259 TESTS+= unexport-env
260 TESTS+= use-inference
261 TESTS+= var-class
262 TESTS+= var-class-cmdline
263 TESTS+= var-class-env
264 TESTS+= var-class-global
265 TESTS+= var-class-local
266 TESTS+= var-class-local-legacy
267 TESTS+= var-op
268 TESTS+= var-op-append
269 TESTS+= var-op-assign
270 TESTS+= var-op-default
271 TESTS+= var-op-expand
272 TESTS+= var-op-shell
273 TESTS+= var-op-sunsh
274 TESTS+= varcmd
275 TESTS+= vardebug
276 TESTS+= varfind
277 TESTS+= varmisc
278 TESTS+= varmod
279 TESTS+= varmod-assign
280 TESTS+= varmod-defined
281 TESTS+= varmod-edge
282 TESTS+= varmod-exclam-shell
283 TESTS+= varmod-extension
284 TESTS+= varmod-gmtime
285 TESTS+= varmod-hash
286 TESTS+= varmod-head
287 TESTS+= varmod-ifelse
288 TESTS+= varmod-l-name-to-value
289 TESTS+= varmod-localtime
290 TESTS+= varmod-loop
291 TESTS+= varmod-match
292 TESTS+= varmod-match-escape
293 TESTS+= varmod-no-match
294 TESTS+= varmod-order
295 TESTS+= varmod-order-reverse
296 TESTS+= varmod-order-shuffle
297 TESTS+= varmod-path
298 TESTS+= varmod-quote
299 TESTS+= varmod-quote-dollar
300 TESTS+= varmod-range
301 TESTS+= varmod-remember
302 TESTS+= varmod-root
303 TESTS+= varmod-select-words
304 TESTS+= varmod-shell
305 TESTS+= varmod-subst
306 TESTS+= varmod-subst-regex
307 TESTS+= varmod-sysv
308 TESTS+= varmod-tail
309 TESTS+= varmod-to-abs
310 TESTS+= varmod-to-lower
311 TESTS+= varmod-to-many-words
312 TESTS+= varmod-to-one-word
313 TESTS+= varmod-to-separator
314 TESTS+= varmod-to-upper
315 TESTS+= varmod-undefined
316 TESTS+= varmod-unique
317 TESTS+= varname
318 TESTS+= varname-dollar
319 TESTS+= varname-dot-alltargets
320 TESTS+= varname-dot-curdir
321 TESTS+= varname-dot-includes
322 TESTS+= varname-dot-includedfromdir
323 TESTS+= varname-dot-includedfromfile
324 TESTS+= varname-dot-libs
325 TESTS+= varname-dot-make-dependfile
326 TESTS+= varname-dot-make-expand_variables
327 TESTS+= varname-dot-make-exported
328 TESTS+= varname-dot-make-jobs
329 TESTS+= varname-dot-make-jobs-prefix
330 TESTS+= varname-dot-make-level
331 TESTS+= varname-dot-make-makefile_preference
332 TESTS+= varname-dot-make-makefiles
333 TESTS+= varname-dot-make-meta-bailiwick
334 TESTS+= varname-dot-make-meta-created
335 TESTS+= varname-dot-make-meta-files
336 TESTS+= varname-dot-make-meta-ignore_filter
337 TESTS+= varname-dot-make-meta-ignore_paths
338 TESTS+= varname-dot-make-meta-ignore_patterns
339 TESTS+= varname-dot-make-meta-prefix
340 TESTS+= varname-dot-make-mode
341 TESTS+= varname-dot-make-path_filemon
342 TESTS+= varname-dot-make-pid
343 TESTS+= varname-dot-make-ppid
344 TESTS+= varname-dot-make-save_dollars
345 TESTS+= varname-dot-makeoverrides
346 TESTS+= varname-dot-newline
347 TESTS+= varname-dot-objdir
348 TESTS+= varname-dot-parsedir
349 TESTS+= varname-dot-parsefile
350 TESTS+= varname-dot-path
351 TESTS+= varname-dot-shell
352 TESTS+= varname-dot-targets
353 TESTS+= varname-empty
354 TESTS+= varname-make
355 TESTS+= varname-make_print_var_on_error
356 TESTS+= varname-makefile
357 TESTS+= varname-makeflags
358 TESTS+= varname-pwd
359 TESTS+= varname-vpath
360 TESTS+= varparse-dynamic
361 TESTS+= varparse-mod
362 TESTS+= varparse-undef-partial
363 TESTS+= varquote
364 TESTS+= varshell
365
366 # Additional environment variables for some of the tests.
367 # The base environment is -i PATH="$PATH".
368 ENV.envfirst= FROM_ENV=value-from-env
369 ENV.varmisc= FROM_ENV=env
370 ENV.varmisc+= FROM_ENV_BEFORE=env
371 ENV.varmisc+= FROM_ENV_AFTER=env
372
373 # Override make flags for some of the tests; default is -k.
374 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
375 # settings FLAGS.test=-dv here, since that is closer to the test code.
376 FLAGS.cond-func-make= via-cmdline
377 FLAGS.directive-ifmake= first second
378 FLAGS.doterror= # none
379 FLAGS.envfirst= -e
380 FLAGS.export= # none
381 FLAGS.opt-ignore= -i
382 FLAGS.opt-keep-going= -k
383 FLAGS.opt-no-action= -n
384 FLAGS.opt-query= -q
385 FLAGS.opt-var-expanded= -v VAR -v VALUE
386 FLAGS.opt-var-literal= -V VAR -V VALUE
387 FLAGS.opt-warnings-as-errors= -W
388 FLAGS.order= -j1
389 FLAGS.recursive= -dL
390 FLAGS.sh-leading-plus= -n
391 FLAGS.vardebug= -k -dv FROM_CMDLINE=
392 FLAGS.varmod-match-escape= -dv
393 FLAGS.varname-dot-shell= -dpv
394 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
395
396 # Some tests need extra postprocessing.
397 SED_CMDS.job-output-long-lines= \
398 ${:D Job separators on their own line are ok. } \
399 -e '/^--- job-[ab] ---$$/d' \
400 ${:D Plain output lines are ok as well. } \
401 ${:D They may come in multiples of 1024 or as 10000. } \
402 -e '/^aa*$$/d' \
403 -e '/^bb*$$/d' \
404 ${:D The following lines should rather not occur since the job } \
405 ${:D marker should always be at the beginning of the line. } \
406 -e '/^aa*--- job-b ---$$/d' \
407 -e '/^bb*--- job-a ---$$/d'
408 SED_CMDS.opt-debug-graph1= \
409 -e 's,${.CURDIR},CURDIR,'
410 SED_CMDS.opt-debug-graph1+= \
411 -e '/Global Variables:/,/Suffixes:/d'
412 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
413 SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
414 SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
415 SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
416 SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
417 SED_CMDS.varmod-subst-regex+= \
418 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
419 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
420 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
421 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
422 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
423 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
424 SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),'
425 SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",'
426 SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],'
427
428 # Some tests need an additional round of postprocessing.
429 POSTPROC.deptgt-suffixes= \
430 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
431 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
432 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
433 POSTPROC.varname= ${TOOL_SED} -n -e '/^MAGIC/p' -e '/^ORDER_/p'
434 POSTPROC.varname-dot-shell= \
435 awk '/\.SHELL/ || /^ParseReadLine/'
436 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
437
438 # Some tests reuse other tests, which makes them unnecessarily fragile.
439 export-all.rawout: export.mk
440 unexport.rawout: export.mk
441 unexport-env.rawout: export.mk
442
443 # End of the configuration section.
444
445 .MAIN: all
446
447 UNIT_TESTS:= ${.PARSEDIR}
448 .PATH: ${UNIT_TESTS}
449
450 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
451 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@}
452 .else
453 OUTFILES= ${TESTS:=.out}
454 .endif
455
456 all: ${OUTFILES}
457
458 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
459 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
460 CLEANFILES+= issue* .[ab]* # suffixes.mk
461 CLEANDIRS= dir dummy # posix1.mk
462
463 clean:
464 rm -f ${CLEANFILES}
465 rm -rf ${CLEANDIRS}
466
467 TEST_MAKE?= ${.MAKE}
468 TOOL_SED?= sed
469
470 # ensure consistent results from sort(1)
471 LC_ALL= C
472 LANG= C
473 .export LANG LC_ALL
474
475 MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc
476
477 # Each test is run in a sub-make, to keep the tests for interfering with
478 # each other, and because they use different environment variables and
479 # command line options.
480 .SUFFIXES: .mk .rawout .out
481 .mk.rawout:
482 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
483 @set -eu; \
484 cd ${.OBJDIR}; \
485 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
486 ${TEST_MAKE} \
487 -r -C ${.CURDIR} -f ${.IMPSRC} \
488 ${FLAGS.${.PREFIX:T}:U-k} \
489 > ${.TARGET}.tmp 2>&1 \
490 && status=$$? || status=$$?; \
491 echo $$status > ${.TARGET:R}.status
492 @mv ${.TARGET}.tmp ${.TARGET}
493
494 # Postprocess the test output so that the results can be compared.
495 #
496 # always pretend .MAKE was called 'make'
497 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
498 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
499 # replace anything after 'stopped in' with unit-tests
500 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
501 # strip ${.CURDIR}/ from the output
502 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
503 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
504
505 .rawout.out:
506 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
507 < ${.IMPSRC} > ${.TARGET}.tmp1
508 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
509 @rm ${.TARGET}.tmp1
510 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
511 @mv ${.TARGET}.tmp2 ${.TARGET}
512
513 # Compare all output files
514 test: ${OUTFILES} .PHONY
515 @failed= ; \
516 for test in ${TESTS}; do \
517 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
518 || failed="$${failed}$${failed:+ }$${test}" ; \
519 done ; \
520 if [ -n "$${failed}" ]; then \
521 echo "Failed tests: $${failed}" ; false ; \
522 else \
523 echo "All tests passed" ; \
524 fi
525
526 accept:
527 @for test in ${TESTS}; do \
528 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
529 || { echo "Replacing $${test}.exp" ; \
530 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
531 done
532
533 # Note: only works for adding tests.
534 # To remove a test, the $$mi file must be edited manually.
535 sync-mi:
536 @set -eu; \
537 cd "${MAKEFILE:tA:H}/../../.."; \
538 mi="distrib/sets/lists/tests/mi"; \
539 cvs update "$$mi"; \
540 testsdir="usr.bin/make/unit-tests"; \
541 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
542 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi"; \
543 distrib/sets/fmt-list "$$mi"; \
544 cvs diff "$$mi" || true
545
546 .if exists(${TEST_MAKE})
547 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
548 .endif
549
550 .-include <bsd.obj.mk>
551