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