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