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