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