Makefile revision 1.146 1 # $NetBSD: Makefile,v 1.146 2020/09/23 03:06:38 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+= dep
75 TESTS+= dep-colon
76 TESTS+= dep-double-colon
77 TESTS+= dep-exclam
78 TESTS+= dep-none
79 TESTS+= dep-var
80 TESTS+= dep-wildcards
81 TESTS+= depsrc
82 TESTS+= depsrc-exec
83 TESTS+= depsrc-ignore
84 TESTS+= depsrc-made
85 TESTS+= depsrc-make
86 TESTS+= depsrc-meta
87 TESTS+= depsrc-nometa
88 TESTS+= depsrc-nometa_cmp
89 TESTS+= depsrc-nopath
90 TESTS+= depsrc-notmain
91 TESTS+= depsrc-optional
92 TESTS+= depsrc-phony
93 TESTS+= depsrc-precious
94 TESTS+= depsrc-recursive
95 TESTS+= depsrc-silent
96 TESTS+= depsrc-use
97 TESTS+= depsrc-usebefore
98 TESTS+= depsrc-usebefore-double-colon
99 TESTS+= depsrc-wait
100 TESTS+= deptgt
101 TESTS+= deptgt-begin
102 TESTS+= deptgt-default
103 TESTS+= deptgt-delete_on_error
104 TESTS+= deptgt-end
105 TESTS+= deptgt-end-jobs
106 TESTS+= deptgt-error
107 TESTS+= deptgt-ignore
108 TESTS+= deptgt-interrupt
109 TESTS+= deptgt-main
110 TESTS+= deptgt-makeflags
111 TESTS+= deptgt-no_parallel
112 TESTS+= deptgt-nopath
113 TESTS+= deptgt-notparallel
114 TESTS+= deptgt-objdir
115 TESTS+= deptgt-order
116 TESTS+= deptgt-path
117 TESTS+= deptgt-path-suffix
118 TESTS+= deptgt-phony
119 TESTS+= deptgt-precious
120 TESTS+= deptgt-shell
121 TESTS+= deptgt-silent
122 TESTS+= deptgt-stale
123 TESTS+= deptgt-suffixes
124 TESTS+= dir
125 TESTS+= dir-expand-path
126 TESTS+= directive
127 TESTS+= directive-dinclude
128 TESTS+= directive-elif
129 TESTS+= directive-elifdef
130 TESTS+= directive-elifmake
131 TESTS+= directive-elifndef
132 TESTS+= directive-elifnmake
133 TESTS+= directive-else
134 TESTS+= directive-endif
135 TESTS+= directive-error
136 TESTS+= directive-export
137 TESTS+= directive-export-env
138 TESTS+= directive-export-literal
139 TESTS+= directive-for
140 TESTS+= directive-for-generating-endif
141 TESTS+= directive-hyphen-include
142 TESTS+= directive-if
143 TESTS+= directive-ifdef
144 TESTS+= directive-ifmake
145 TESTS+= directive-ifndef
146 TESTS+= directive-ifnmake
147 TESTS+= directive-include
148 TESTS+= directive-include-fatal
149 TESTS+= directive-info
150 TESTS+= directive-sinclude
151 TESTS+= directive-undef
152 TESTS+= directive-unexport
153 TESTS+= directive-unexport-env
154 TESTS+= directive-warning
155 TESTS+= directives
156 TESTS+= dollar
157 TESTS+= doterror
158 TESTS+= dotwait
159 TESTS+= envfirst
160 TESTS+= error
161 TESTS+= # escape # broken by reverting POSIX changes
162 TESTS+= export
163 TESTS+= export-all
164 TESTS+= export-env
165 TESTS+= export-variants
166 TESTS+= forloop
167 TESTS+= forsubst
168 TESTS+= impsrc
169 TESTS+= include-main
170 TESTS+= lint
171 TESTS+= make-exported
172 TESTS+= misc
173 TESTS+= moderrs
174 TESTS+= modmatch
175 TESTS+= modmisc
176 TESTS+= modts
177 TESTS+= modword
178 TESTS+= opt
179 TESTS+= opt-backwards
180 TESTS+= opt-chdir
181 TESTS+= opt-debug
182 TESTS+= opt-debug-all
183 TESTS+= opt-debug-archive
184 TESTS+= opt-debug-curdir
185 TESTS+= opt-debug-cond
186 TESTS+= opt-debug-dir
187 TESTS+= opt-debug-errors
188 TESTS+= opt-debug-file
189 TESTS+= opt-debug-for
190 TESTS+= opt-debug-graph1
191 TESTS+= opt-debug-graph2
192 TESTS+= opt-debug-graph3
193 TESTS+= opt-debug-hash
194 TESTS+= opt-debug-jobs
195 TESTS+= opt-debug-lint
196 TESTS+= opt-debug-loud
197 TESTS+= opt-debug-meta
198 TESTS+= opt-debug-making
199 TESTS+= opt-debug-no-rm
200 TESTS+= opt-debug-parse
201 TESTS+= opt-debug-suff
202 TESTS+= opt-debug-targets
203 TESTS+= opt-debug-varraw
204 TESTS+= opt-debug-var
205 TESTS+= opt-debug-x-trace
206 TESTS+= opt-define
207 TESTS+= opt-env
208 TESTS+= opt-file
209 TESTS+= opt-ignore
210 TESTS+= opt-include-dir
211 TESTS+= opt-jobs
212 TESTS+= opt-jobs-internal
213 TESTS+= opt-keep-going
214 TESTS+= opt-m-include-dir
215 TESTS+= opt-no-action
216 TESTS+= opt-no-action-at-all
217 TESTS+= opt-query
218 TESTS+= opt-raw
219 TESTS+= opt-silent
220 TESTS+= opt-touch
221 TESTS+= opt-tracefile
222 TESTS+= opt-var-expanded
223 TESTS+= opt-var-literal
224 TESTS+= opt-warnings-as-errors
225 TESTS+= opt-where-am-i
226 TESTS+= opt-x-reduce-exported
227 TESTS+= order
228 TESTS+= phony-end
229 TESTS+= posix
230 TESTS+= # posix1 # broken by reverting POSIX changes
231 TESTS+= qequals
232 TESTS+= recursive
233 TESTS+= sh
234 TESTS+= sh-dots
235 TESTS+= sh-jobs
236 TESTS+= sh-jobs-error
237 TESTS+= sh-leading-at
238 TESTS+= sh-leading-hyphen
239 TESTS+= sh-leading-plus
240 TESTS+= sh-meta-chars
241 TESTS+= sh-multi-line
242 TESTS+= sh-single-line
243 TESTS+= # suffixes # runs into an endless loop (try -dA)
244 TESTS+= sunshcmd
245 TESTS+= sysv
246 TESTS+= ternary
247 TESTS+= unexport
248 TESTS+= unexport-env
249 TESTS+= use-inference
250 TESTS+= var-class
251 TESTS+= var-class-cmdline
252 TESTS+= var-class-env
253 TESTS+= var-class-global
254 TESTS+= var-class-local
255 TESTS+= var-class-local-legacy
256 TESTS+= var-op
257 TESTS+= var-op-append
258 TESTS+= var-op-assign
259 TESTS+= var-op-default
260 TESTS+= var-op-expand
261 TESTS+= var-op-shell
262 TESTS+= varcmd
263 TESTS+= vardebug
264 TESTS+= varfind
265 TESTS+= varmisc
266 TESTS+= varmod
267 TESTS+= varmod-assign
268 TESTS+= varmod-defined
269 TESTS+= varmod-edge
270 TESTS+= varmod-exclam-shell
271 TESTS+= varmod-extension
272 TESTS+= varmod-gmtime
273 TESTS+= varmod-hash
274 TESTS+= varmod-head
275 TESTS+= varmod-ifelse
276 TESTS+= varmod-l-name-to-value
277 TESTS+= varmod-localtime
278 TESTS+= varmod-loop
279 TESTS+= varmod-match
280 TESTS+= varmod-match-escape
281 TESTS+= varmod-no-match
282 TESTS+= varmod-order
283 TESTS+= varmod-order-reverse
284 TESTS+= varmod-order-shuffle
285 TESTS+= varmod-path
286 TESTS+= varmod-quote
287 TESTS+= varmod-quote-dollar
288 TESTS+= varmod-range
289 TESTS+= varmod-remember
290 TESTS+= varmod-root
291 TESTS+= varmod-select-words
292 TESTS+= varmod-shell
293 TESTS+= varmod-subst
294 TESTS+= varmod-subst-regex
295 TESTS+= varmod-sysv
296 TESTS+= varmod-tail
297 TESTS+= varmod-to-abs
298 TESTS+= varmod-to-lower
299 TESTS+= varmod-to-many-words
300 TESTS+= varmod-to-one-word
301 TESTS+= varmod-to-separator
302 TESTS+= varmod-to-upper
303 TESTS+= varmod-undefined
304 TESTS+= varmod-unique
305 TESTS+= varname
306 TESTS+= varname-dollar
307 TESTS+= varname-dot-alltargets
308 TESTS+= varname-dot-curdir
309 TESTS+= varname-dot-includes
310 TESTS+= varname-dot-includedfromdir
311 TESTS+= varname-dot-includedfromfile
312 TESTS+= varname-dot-libs
313 TESTS+= varname-dot-make-dependfile
314 TESTS+= varname-dot-make-expand_variables
315 TESTS+= varname-dot-make-exported
316 TESTS+= varname-dot-make-jobs
317 TESTS+= varname-dot-make-jobs-prefix
318 TESTS+= varname-dot-make-level
319 TESTS+= varname-dot-make-makefile_preference
320 TESTS+= varname-dot-make-makefiles
321 TESTS+= varname-dot-make-meta-bailiwick
322 TESTS+= varname-dot-make-meta-created
323 TESTS+= varname-dot-make-meta-files
324 TESTS+= varname-dot-make-meta-ignore_filter
325 TESTS+= varname-dot-make-meta-ignore_paths
326 TESTS+= varname-dot-make-meta-ignore_patterns
327 TESTS+= varname-dot-make-meta-prefix
328 TESTS+= varname-dot-make-mode
329 TESTS+= varname-dot-make-path_filemon
330 TESTS+= varname-dot-make-pid
331 TESTS+= varname-dot-make-ppid
332 TESTS+= varname-dot-make-save_dollars
333 TESTS+= varname-dot-makeoverrides
334 TESTS+= varname-dot-newline
335 TESTS+= varname-dot-objdir
336 TESTS+= varname-dot-parsedir
337 TESTS+= varname-dot-parsefile
338 TESTS+= varname-dot-path
339 TESTS+= varname-dot-shell
340 TESTS+= varname-dot-targets
341 TESTS+= varname-empty
342 TESTS+= varname-make
343 TESTS+= varname-make_print_var_on_error
344 TESTS+= varname-makefile
345 TESTS+= varname-makeflags
346 TESTS+= varname-pwd
347 TESTS+= varname-vpath
348 TESTS+= varparse-dynamic
349 TESTS+= varquote
350 TESTS+= varshell
351
352 # Additional environment variables for some of the tests.
353 # The base environment is -i PATH="$PATH".
354 ENV.envfirst= FROM_ENV=value-from-env
355 ENV.varmisc= FROM_ENV=env
356 ENV.varmisc+= FROM_ENV_BEFORE=env
357 ENV.varmisc+= FROM_ENV_AFTER=env
358
359 # Override make flags for some of the tests; default is -k.
360 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
361 # settings FLAGS.test=-dv here, since that is closer to the test code.
362 FLAGS.counter= -dv
363 FLAGS.directive-ifmake= first second
364 FLAGS.doterror= # none
365 FLAGS.envfirst= -e
366 FLAGS.export= # none
367 FLAGS.opt-ignore= -i
368 FLAGS.opt-keep-going= -k
369 FLAGS.opt-no-action= -n
370 FLAGS.opt-query= -q
371 FLAGS.opt-var-expanded= -v VAR -v VALUE
372 FLAGS.opt-var-literal= -V VAR -V VALUE
373 FLAGS.opt-warnings-as-errors= -W
374 FLAGS.order= -j1
375 FLAGS.recursive= -dL
376 FLAGS.sh-leading-plus= -n
377 FLAGS.vardebug= -k -dv FROM_CMDLINE=
378 FLAGS.varmod-match-escape= -dv
379 FLAGS.varname-dot-shell= -dpv
380 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
381
382 # Some tests need extra postprocessing.
383 SED_CMDS.opt-debug-graph1= \
384 -e 's,${.CURDIR},CURDIR,'
385 SED_CMDS.opt-debug-graph1+= \
386 -e '/Global Variables:/,/Suffixes:/d'
387 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
388 SED_CMDS.varmod-subst-regex+= \
389 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
390 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
391 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
392 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
393 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
394 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
395 SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),'
396 SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",'
397 SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],'
398
399 # Some tests need an additional round of postprocessing.
400 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
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