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