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