1 # $Id: Makefile,v 1.92 2020/09/02 18:39:29 sjg Exp $
3 # $NetBSD: Makefile,v 1.130 2020/09/02 05:33:57 rillig Exp $
5 # Unit tests for make(1)
7 # The main targets are:
12 # run 'all', and compare to expected results
14 # move generated output to expected results
19 # The make program to be tested.
24 # Each feature should get its own set of tests in its own suitably
25 # named makefile (*.mk), with its own set of expected results (*.exp),
26 # and it should be added to the TESTS list.
28 # A few *.mk files are helper files for other tests (such as include-sub.mk)
29 # and are thus not added to TESTS. Such files must be ignored in
30 # src/tests/usr.bin/make/t_make.sh.
33 # Each test is in a sub-makefile.
34 # Keep the list sorted.
35 # Any test that is commented out must be ignored in
36 # src/tests/usr.bin/make/t_make.sh as well.
37 TESTS+= # archive # broken on FreeBSD, enabled in t_make.sh
38 TESTS+= archive-suffix
42 TESTS+= cond-cmp-numeric
43 TESTS+= cond-cmp-numeric-eq
44 TESTS+= cond-cmp-numeric-ge
45 TESTS+= cond-cmp-numeric-gt
46 TESTS+= cond-cmp-numeric-le
47 TESTS+= cond-cmp-numeric-lt
48 TESTS+= cond-cmp-numeric-ne
49 TESTS+= cond-cmp-string
51 TESTS+= cond-func-commands
52 TESTS+= cond-func-defined
53 TESTS+= cond-func-empty
54 TESTS+= cond-func-exists
55 TESTS+= cond-func-make
56 TESTS+= cond-func-target
62 TESTS+= cond-op-parentheses
64 TESTS+= cond-token-number
65 TESTS+= cond-token-plain
66 TESTS+= cond-token-string
67 TESTS+= cond-token-var
73 TESTS+= dep-double-colon
85 TESTS+= depsrc-nometa_cmp
87 TESTS+= depsrc-notmain
88 TESTS+= depsrc-optional
90 TESTS+= depsrc-precious
91 TESTS+= depsrc-recursive
94 TESTS+= depsrc-usebefore
95 TESTS+= depsrc-usebefore-double-colon
99 TESTS+= deptgt-default
100 TESTS+= deptgt-delete_on_error
103 TESTS+= deptgt-ignore
104 TESTS+= deptgt-interrupt
106 TESTS+= deptgt-makeflags
107 TESTS+= deptgt-no_parallel
108 TESTS+= deptgt-nopath
109 TESTS+= deptgt-notparallel
110 TESTS+= deptgt-objdir
113 TESTS+= deptgt-path-suffix
115 TESTS+= deptgt-precious
117 TESTS+= deptgt-silent
119 TESTS+= deptgt-suffixes
121 TESTS+= dir-expand-path
123 TESTS+= directive-elif
124 TESTS+= directive-elifdef
125 TESTS+= directive-elifmake
126 TESTS+= directive-elifndef
127 TESTS+= directive-elifnmake
128 TESTS+= directive-else
129 TESTS+= directive-endif
130 TESTS+= directive-error
131 TESTS+= directive-export
132 TESTS+= directive-export-env
133 TESTS+= directive-export-literal
134 TESTS+= directive-for
135 TESTS+= directive-for-generating-endif
137 TESTS+= directive-ifdef
138 TESTS+= directive-ifmake
139 TESTS+= directive-ifndef
140 TESTS+= directive-ifnmake
141 TESTS+= directive-info
142 TESTS+= directive-undef
143 TESTS+= directive-unexport
144 TESTS+= directive-unexport-env
145 TESTS+= directive-warning
152 TESTS+= # escape # broken by reverting POSIX changes
156 TESTS+= export-variants
163 TESTS+= make-exported
171 TESTS+= opt-backwards
179 TESTS+= opt-include-dir
181 TESTS+= opt-jobs-internal
182 TESTS+= opt-keep-going
183 TESTS+= opt-m-include-dir
184 TESTS+= opt-no-action
185 TESTS+= opt-no-action-at-all
190 TESTS+= opt-tracefile
191 TESTS+= opt-var-expanded
192 TESTS+= opt-var-literal
193 TESTS+= opt-warnings-as-errors
194 TESTS+= opt-where-am-i
195 TESTS+= opt-x-reduce-exported
199 TESTS+= # posix1 # broken by reverting POSIX changes
205 TESTS+= sh-jobs-error
206 TESTS+= sh-leading-at
207 TESTS+= sh-leading-hyphen
208 TESTS+= sh-leading-plus
209 TESTS+= sh-meta-chars
210 TESTS+= sh-multi-line
211 TESTS+= sh-single-line
212 TESTS+= # suffixes # runs into an endless loop (try -dA)
218 TESTS+= use-inference
220 TESTS+= var-class-cmdline
221 TESTS+= var-class-env
222 TESTS+= var-class-global
223 TESTS+= var-class-local
224 TESTS+= var-class-local-legacy
226 TESTS+= var-op-append
227 TESTS+= var-op-assign
228 TESTS+= var-op-default
229 TESTS+= var-op-expand
236 TESTS+= varmod-assign
237 TESTS+= varmod-defined
239 TESTS+= varmod-exclam-shell
240 TESTS+= varmod-extension
241 TESTS+= varmod-gmtime
244 TESTS+= varmod-ifelse
245 TESTS+= varmod-l-name-to-value
246 TESTS+= varmod-localtime
249 TESTS+= varmod-match-escape
250 TESTS+= varmod-no-match
252 TESTS+= varmod-order-reverse
253 TESTS+= varmod-order-shuffle
256 TESTS+= varmod-quote-dollar
258 TESTS+= varmod-remember
260 TESTS+= varmod-select-words
263 TESTS+= varmod-subst-regex
266 TESTS+= varmod-to-abs
267 TESTS+= varmod-to-lower
268 TESTS+= varmod-to-many-words
269 TESTS+= varmod-to-one-word
270 TESTS+= varmod-to-separator
271 TESTS+= varmod-to-upper
272 TESTS+= varmod-undefined
273 TESTS+= varmod-unique
275 TESTS+= varname-dollar
276 TESTS+= varname-dot-alltargets
277 TESTS+= varname-dot-curdir
278 TESTS+= varname-dot-includes
279 TESTS+= varname-dot-includedfromdir
280 TESTS+= varname-dot-includedfromfile
281 TESTS+= varname-dot-libs
282 TESTS+= varname-dot-make-dependfile
283 TESTS+= varname-dot-make-expand_variables
284 TESTS+= varname-dot-make-exported
285 TESTS+= varname-dot-make-jobs
286 TESTS+= varname-dot-make-jobs-prefix
287 TESTS+= varname-dot-make-level
288 TESTS+= varname-dot-make-makefile_preference
289 TESTS+= varname-dot-make-makefiles
290 TESTS+= varname-dot-make-meta-bailiwick
291 TESTS+= varname-dot-make-meta-created
292 TESTS+= varname-dot-make-meta-files
293 TESTS+= varname-dot-make-meta-ignore_filter
294 TESTS+= varname-dot-make-meta-ignore_paths
295 TESTS+= varname-dot-make-meta-ignore_patterns
296 TESTS+= varname-dot-make-meta-prefix
297 TESTS+= varname-dot-make-mode
298 TESTS+= varname-dot-make-path_filemon
299 TESTS+= varname-dot-make-pid
300 TESTS+= varname-dot-make-ppid
301 TESTS+= varname-dot-make-save_dollars
302 TESTS+= varname-dot-makeoverrides
303 TESTS+= varname-dot-newline
304 TESTS+= varname-dot-objdir
305 TESTS+= varname-dot-parsedir
306 TESTS+= varname-dot-parsefile
307 TESTS+= varname-dot-path
308 TESTS+= varname-dot-shell
309 TESTS+= varname-dot-targets
310 TESTS+= varname-empty
312 TESTS+= varname-make_print_var_on_error
313 TESTS+= varname-makeflags
315 TESTS+= varname-vpath
316 TESTS+= varparse-dynamic
320 # Additional environment variables for some of the tests.
321 # The base environment is -i PATH="$PATH".
322 ENV.envfirst= FROM_ENV=value-from-env
323 ENV.varmisc= FROM_ENV=env
324 ENV.varmisc+= FROM_ENV_BEFORE=env
325 ENV.varmisc+= FROM_ENV_AFTER=env
327 # Override make flags for some of the tests; default is -k.
328 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
329 # settings FLAGS.test=-dv here, since that is closer to the test code.
332 FLAGS.directive-ifmake= first second
333 FLAGS.doterror= # none
337 FLAGS.opt-debug-g1= -dg1
339 FLAGS.opt-keep-going= -k
340 FLAGS.opt-no-action= -n
342 FLAGS.opt-var-expanded= -v VAR -v VALUE
343 FLAGS.opt-var-literal= -V VAR -V VALUE
344 FLAGS.opt-warnings-as-errors= -W
347 FLAGS.sh-leading-plus= -n
348 FLAGS.vardebug= -k -dv FROM_CMDLINE=
349 FLAGS.varmod-match-escape= -dv
350 FLAGS.varname-dot-shell= -dpv
351 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
353 # Some tests need extra post-processing.
354 SED_CMDS.opt-debug-g1= -e 's,${.CURDIR},CURDIR,'
355 SED_CMDS.opt-debug-g1+= -e '/Global Variables:/,/Suffixes:/d'
356 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
357 SED_CMDS.varmod-subst-regex+= \
358 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
359 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
360 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
361 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
362 SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),'
363 SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",'
364 SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],'
366 # Some tests need an additional round of postprocessing.
367 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
368 POSTPROC.deptgt-suffixes= \
369 ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
370 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
371 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
372 POSTPROC.varname-dot-shell= \
373 awk '/\.SHELL/ || /^ParseReadLine/'
374 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
376 # Some tests reuse other tests, which makes them unnecessarily fragile.
377 export-all.rawout: export.mk
378 unexport.rawout: export.mk
379 unexport-env.rawout: export.mk
381 # End of the configuration section.
385 .-include "Makefile.inc"
386 .-include "Makefile.config"
388 UNIT_TESTS:= ${.PARSEDIR}
391 OUTFILES= ${TESTS:=.out}
395 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
396 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
397 CLEANFILES+= issue* .[ab]* # suffixes.mk
398 CLEANDIRS= dir dummy # posix1.mk
410 .if defined(.PARSEDIR)
411 # ensure consistent results from sort(1)
417 .if ${.MAKE.MODE:Unormal:Mmeta} != ""
418 # we don't need the noise
422 # the tests are actually done with sub-makes.
423 .SUFFIXES: .mk .rawout .out
425 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
428 env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \
430 -r -C ${.CURDIR} -f ${.IMPSRC} \
431 ${FLAGS.${.TARGET:R}:U-k} \
432 > ${.TARGET}.tmp 2>&1 \
433 && status=$$? || status=$$?; \
434 echo $$status > ${.TARGET:R}.status
435 @mv ${.TARGET}.tmp ${.TARGET}
437 # Post-process the test output so that the results can be compared.
439 # always pretend .MAKE was called 'make'
440 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
441 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
442 # replace anything after 'stopped in' with unit-tests
443 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
444 # strip ${.CURDIR}/ from the output
445 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
446 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
449 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
450 < ${.IMPSRC} > ${.TARGET}.tmp1
451 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
453 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
454 @mv ${.TARGET}.tmp2 ${.TARGET}
456 # Compare all output files
457 test: ${OUTFILES} .PHONY
459 for test in ${TESTS}; do \
460 ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
461 || failed="$${failed}$${failed:+ }$${test}" ; \
463 if [ -n "$${failed}" ]; then \
464 echo "Failed tests: $${failed}" ; false ; \
466 echo "All tests passed" ; \
470 @for test in ${TESTS}; do \
471 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
472 || { echo "Replacing $${test}.exp" ; \
473 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
476 .if exists(${TEST_MAKE})
477 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile