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