Makefile revision 1.143 1 # $NetBSD: Makefile,v 1.143 2020/09/15 16:22:04 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-error
106 TESTS+= deptgt-ignore
107 TESTS+= deptgt-interrupt
108 TESTS+= deptgt-main
109 TESTS+= deptgt-makeflags
110 TESTS+= deptgt-no_parallel
111 TESTS+= deptgt-nopath
112 TESTS+= deptgt-notparallel
113 TESTS+= deptgt-objdir
114 TESTS+= deptgt-order
115 TESTS+= deptgt-path
116 TESTS+= deptgt-path-suffix
117 TESTS+= deptgt-phony
118 TESTS+= deptgt-precious
119 TESTS+= deptgt-shell
120 TESTS+= deptgt-silent
121 TESTS+= deptgt-stale
122 TESTS+= deptgt-suffixes
123 TESTS+= dir
124 TESTS+= dir-expand-path
125 TESTS+= directive
126 TESTS+= directive-dinclude
127 TESTS+= directive-elif
128 TESTS+= directive-elifdef
129 TESTS+= directive-elifmake
130 TESTS+= directive-elifndef
131 TESTS+= directive-elifnmake
132 TESTS+= directive-else
133 TESTS+= directive-endif
134 TESTS+= directive-error
135 TESTS+= directive-export
136 TESTS+= directive-export-env
137 TESTS+= directive-export-literal
138 TESTS+= directive-for
139 TESTS+= directive-for-generating-endif
140 TESTS+= directive-hyphen-include
141 TESTS+= directive-if
142 TESTS+= directive-ifdef
143 TESTS+= directive-ifmake
144 TESTS+= directive-ifndef
145 TESTS+= directive-ifnmake
146 TESTS+= directive-include
147 TESTS+= directive-include-fatal
148 TESTS+= directive-info
149 TESTS+= directive-sinclude
150 TESTS+= directive-undef
151 TESTS+= directive-unexport
152 TESTS+= directive-unexport-env
153 TESTS+= directive-warning
154 TESTS+= directives
155 TESTS+= dollar
156 TESTS+= doterror
157 TESTS+= dotwait
158 TESTS+= envfirst
159 TESTS+= error
160 TESTS+= # escape # broken by reverting POSIX changes
161 TESTS+= export
162 TESTS+= export-all
163 TESTS+= export-env
164 TESTS+= export-variants
165 TESTS+= forloop
166 TESTS+= forsubst
167 TESTS+= impsrc
168 TESTS+= include-main
169 TESTS+= lint
170 TESTS+= make-exported
171 TESTS+= misc
172 TESTS+= moderrs
173 TESTS+= modmatch
174 TESTS+= modmisc
175 TESTS+= modts
176 TESTS+= modword
177 TESTS+= opt
178 TESTS+= opt-backwards
179 TESTS+= opt-chdir
180 TESTS+= opt-debug
181 TESTS+= opt-debug-all
182 TESTS+= opt-debug-archive
183 TESTS+= opt-debug-curdir
184 TESTS+= opt-debug-cond
185 TESTS+= opt-debug-dir
186 TESTS+= opt-debug-errors
187 TESTS+= opt-debug-file
188 TESTS+= opt-debug-for
189 TESTS+= opt-debug-graph1
190 TESTS+= opt-debug-graph2
191 TESTS+= opt-debug-graph3
192 TESTS+= opt-debug-hash
193 TESTS+= opt-debug-jobs
194 TESTS+= opt-debug-lint
195 TESTS+= opt-debug-loud
196 TESTS+= opt-debug-meta
197 TESTS+= opt-debug-making
198 TESTS+= opt-debug-no-rm
199 TESTS+= opt-debug-parse
200 TESTS+= opt-debug-suff
201 TESTS+= opt-debug-targets
202 TESTS+= opt-debug-varraw
203 TESTS+= opt-debug-var
204 TESTS+= opt-debug-x-trace
205 TESTS+= opt-define
206 TESTS+= opt-env
207 TESTS+= opt-file
208 TESTS+= opt-ignore
209 TESTS+= opt-include-dir
210 TESTS+= opt-jobs
211 TESTS+= opt-jobs-internal
212 TESTS+= opt-keep-going
213 TESTS+= opt-m-include-dir
214 TESTS+= opt-no-action
215 TESTS+= opt-no-action-at-all
216 TESTS+= opt-query
217 TESTS+= opt-raw
218 TESTS+= opt-silent
219 TESTS+= opt-touch
220 TESTS+= opt-tracefile
221 TESTS+= opt-var-expanded
222 TESTS+= opt-var-literal
223 TESTS+= opt-warnings-as-errors
224 TESTS+= opt-where-am-i
225 TESTS+= opt-x-reduce-exported
226 TESTS+= order
227 TESTS+= phony-end
228 TESTS+= posix
229 TESTS+= # posix1 # broken by reverting POSIX changes
230 TESTS+= qequals
231 TESTS+= recursive
232 TESTS+= sh
233 TESTS+= sh-dots
234 TESTS+= sh-jobs
235 TESTS+= sh-jobs-error
236 TESTS+= sh-leading-at
237 TESTS+= sh-leading-hyphen
238 TESTS+= sh-leading-plus
239 TESTS+= sh-meta-chars
240 TESTS+= sh-multi-line
241 TESTS+= sh-single-line
242 TESTS+= # suffixes # runs into an endless loop (try -dA)
243 TESTS+= sunshcmd
244 TESTS+= sysv
245 TESTS+= ternary
246 TESTS+= unexport
247 TESTS+= unexport-env
248 TESTS+= use-inference
249 TESTS+= var-class
250 TESTS+= var-class-cmdline
251 TESTS+= var-class-env
252 TESTS+= var-class-global
253 TESTS+= var-class-local
254 TESTS+= var-class-local-legacy
255 TESTS+= var-op
256 TESTS+= var-op-append
257 TESTS+= var-op-assign
258 TESTS+= var-op-default
259 TESTS+= var-op-expand
260 TESTS+= var-op-shell
261 TESTS+= varcmd
262 TESTS+= vardebug
263 TESTS+= varfind
264 TESTS+= varmisc
265 TESTS+= varmod
266 TESTS+= varmod-assign
267 TESTS+= varmod-defined
268 TESTS+= varmod-edge
269 TESTS+= varmod-exclam-shell
270 TESTS+= varmod-extension
271 TESTS+= varmod-gmtime
272 TESTS+= varmod-hash
273 TESTS+= varmod-head
274 TESTS+= varmod-ifelse
275 TESTS+= varmod-l-name-to-value
276 TESTS+= varmod-localtime
277 TESTS+= varmod-loop
278 TESTS+= varmod-match
279 TESTS+= varmod-match-escape
280 TESTS+= varmod-no-match
281 TESTS+= varmod-order
282 TESTS+= varmod-order-reverse
283 TESTS+= varmod-order-shuffle
284 TESTS+= varmod-path
285 TESTS+= varmod-quote
286 TESTS+= varmod-quote-dollar
287 TESTS+= varmod-range
288 TESTS+= varmod-remember
289 TESTS+= varmod-root
290 TESTS+= varmod-select-words
291 TESTS+= varmod-shell
292 TESTS+= varmod-subst
293 TESTS+= varmod-subst-regex
294 TESTS+= varmod-sysv
295 TESTS+= varmod-tail
296 TESTS+= varmod-to-abs
297 TESTS+= varmod-to-lower
298 TESTS+= varmod-to-many-words
299 TESTS+= varmod-to-one-word
300 TESTS+= varmod-to-separator
301 TESTS+= varmod-to-upper
302 TESTS+= varmod-undefined
303 TESTS+= varmod-unique
304 TESTS+= varname
305 TESTS+= varname-dollar
306 TESTS+= varname-dot-alltargets
307 TESTS+= varname-dot-curdir
308 TESTS+= varname-dot-includes
309 TESTS+= varname-dot-includedfromdir
310 TESTS+= varname-dot-includedfromfile
311 TESTS+= varname-dot-libs
312 TESTS+= varname-dot-make-dependfile
313 TESTS+= varname-dot-make-expand_variables
314 TESTS+= varname-dot-make-exported
315 TESTS+= varname-dot-make-jobs
316 TESTS+= varname-dot-make-jobs-prefix
317 TESTS+= varname-dot-make-level
318 TESTS+= varname-dot-make-makefile_preference
319 TESTS+= varname-dot-make-makefiles
320 TESTS+= varname-dot-make-meta-bailiwick
321 TESTS+= varname-dot-make-meta-created
322 TESTS+= varname-dot-make-meta-files
323 TESTS+= varname-dot-make-meta-ignore_filter
324 TESTS+= varname-dot-make-meta-ignore_paths
325 TESTS+= varname-dot-make-meta-ignore_patterns
326 TESTS+= varname-dot-make-meta-prefix
327 TESTS+= varname-dot-make-mode
328 TESTS+= varname-dot-make-path_filemon
329 TESTS+= varname-dot-make-pid
330 TESTS+= varname-dot-make-ppid
331 TESTS+= varname-dot-make-save_dollars
332 TESTS+= varname-dot-makeoverrides
333 TESTS+= varname-dot-newline
334 TESTS+= varname-dot-objdir
335 TESTS+= varname-dot-parsedir
336 TESTS+= varname-dot-parsefile
337 TESTS+= varname-dot-path
338 TESTS+= varname-dot-shell
339 TESTS+= varname-dot-targets
340 TESTS+= varname-empty
341 TESTS+= varname-make
342 TESTS+= varname-make_print_var_on_error
343 TESTS+= varname-makefile
344 TESTS+= varname-makeflags
345 TESTS+= varname-pwd
346 TESTS+= varname-vpath
347 TESTS+= varparse-dynamic
348 TESTS+= varquote
349 TESTS+= varshell
350
351 # Additional environment variables for some of the tests.
352 # The base environment is -i PATH="$PATH".
353 ENV.envfirst= FROM_ENV=value-from-env
354 ENV.varmisc= FROM_ENV=env
355 ENV.varmisc+= FROM_ENV_BEFORE=env
356 ENV.varmisc+= FROM_ENV_AFTER=env
357
358 # Override make flags for some of the tests; default is -k.
359 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
360 # settings FLAGS.test=-dv here, since that is closer to the test code.
361 FLAGS.counter= -dv
362 FLAGS.directive-ifmake= first second
363 FLAGS.doterror= # none
364 FLAGS.envfirst= -e
365 FLAGS.export= # none
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