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