Makefile revision 1.190
1# $NetBSD: Makefile,v 1.190 2020/11/07 23:25:06 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-errors
41TESTS+=		cmd-errors-lint
42TESTS+=		cmd-interrupt
43TESTS+=		cmdline
44TESTS+=		cmdline-undefined
45TESTS+=		comment
46TESTS+=		cond-cmp-numeric
47TESTS+=		cond-cmp-numeric-eq
48TESTS+=		cond-cmp-numeric-ge
49TESTS+=		cond-cmp-numeric-gt
50TESTS+=		cond-cmp-numeric-le
51TESTS+=		cond-cmp-numeric-lt
52TESTS+=		cond-cmp-numeric-ne
53TESTS+=		cond-cmp-string
54TESTS+=		cond-cmp-unary
55TESTS+=		cond-func
56TESTS+=		cond-func-commands
57TESTS+=		cond-func-defined
58TESTS+=		cond-func-empty
59TESTS+=		cond-func-exists
60TESTS+=		cond-func-make
61TESTS+=		cond-func-target
62TESTS+=		cond-late
63TESTS+=		cond-op
64TESTS+=		cond-op-and
65TESTS+=		cond-op-not
66TESTS+=		cond-op-or
67TESTS+=		cond-op-parentheses
68TESTS+=		cond-short
69TESTS+=		cond-token-number
70TESTS+=		cond-token-plain
71TESTS+=		cond-token-string
72TESTS+=		cond-token-var
73TESTS+=		cond-undef-lint
74TESTS+=		cond1
75TESTS+=		counter
76TESTS+=		counter-append
77TESTS+=		dep
78TESTS+=		dep-colon
79TESTS+=		dep-colon-bug-cross-file
80TESTS+=		dep-double-colon
81TESTS+=		dep-double-colon-indep
82TESTS+=		dep-exclam
83TESTS+=		dep-none
84TESTS+=		dep-percent
85TESTS+=		dep-var
86TESTS+=		dep-wildcards
87TESTS+=		depsrc
88TESTS+=		depsrc-end
89TESTS+=		depsrc-exec
90TESTS+=		depsrc-ignore
91TESTS+=		depsrc-made
92TESTS+=		depsrc-make
93TESTS+=		depsrc-meta
94TESTS+=		depsrc-nometa
95TESTS+=		depsrc-nometa_cmp
96TESTS+=		depsrc-nopath
97TESTS+=		depsrc-notmain
98TESTS+=		depsrc-optional
99TESTS+=		depsrc-phony
100TESTS+=		depsrc-precious
101TESTS+=		depsrc-recursive
102TESTS+=		depsrc-silent
103TESTS+=		depsrc-use
104TESTS+=		depsrc-usebefore
105TESTS+=		depsrc-usebefore-double-colon
106TESTS+=		depsrc-wait
107TESTS+=		deptgt
108TESTS+=		deptgt-begin
109TESTS+=		deptgt-default
110TESTS+=		deptgt-delete_on_error
111TESTS+=		deptgt-end
112TESTS+=		deptgt-end-jobs
113TESTS+=		deptgt-error
114TESTS+=		deptgt-ignore
115TESTS+=		deptgt-interrupt
116TESTS+=		deptgt-main
117TESTS+=		deptgt-makeflags
118TESTS+=		deptgt-no_parallel
119TESTS+=		deptgt-nopath
120TESTS+=		deptgt-notparallel
121TESTS+=		deptgt-objdir
122TESTS+=		deptgt-order
123TESTS+=		deptgt-path
124TESTS+=		deptgt-path-suffix
125TESTS+=		deptgt-phony
126TESTS+=		deptgt-precious
127TESTS+=		deptgt-shell
128TESTS+=		deptgt-silent
129TESTS+=		deptgt-stale
130TESTS+=		deptgt-suffixes
131TESTS+=		dir
132TESTS+=		dir-expand-path
133TESTS+=		directive
134TESTS+=		directive-dinclude
135TESTS+=		directive-elif
136TESTS+=		directive-elifdef
137TESTS+=		directive-elifmake
138TESTS+=		directive-elifndef
139TESTS+=		directive-elifnmake
140TESTS+=		directive-else
141TESTS+=		directive-endif
142TESTS+=		directive-error
143TESTS+=		directive-export
144TESTS+=		directive-export-env
145TESTS+=		directive-export-gmake
146TESTS+=		directive-export-literal
147TESTS+=		directive-for
148TESTS+=		directive-for-generating-endif
149TESTS+=		directive-hyphen-include
150TESTS+=		directive-if
151TESTS+=		directive-ifdef
152TESTS+=		directive-ifmake
153TESTS+=		directive-ifndef
154TESTS+=		directive-ifnmake
155TESTS+=		directive-include
156TESTS+=		directive-include-fatal
157TESTS+=		directive-info
158TESTS+=		directive-sinclude
159TESTS+=		directive-undef
160TESTS+=		directive-unexport
161TESTS+=		directive-unexport-env
162TESTS+=		directive-warning
163TESTS+=		dollar
164TESTS+=		doterror
165TESTS+=		dotwait
166TESTS+=		envfirst
167TESTS+=		error
168TESTS+=		# escape	# broken by reverting POSIX changes
169TESTS+=		export
170TESTS+=		export-all
171TESTS+=		export-env
172TESTS+=		export-variants
173TESTS+=		forloop
174TESTS+=		forsubst
175TESTS+=		gnode-submake
176TESTS+=		hanoi-include
177TESTS+=		impsrc
178TESTS+=		include-main
179TESTS+=		job-flags
180TESTS+=		job-output-long-lines
181TESTS+=		lint
182TESTS+=		make-exported
183TESTS+=		moderrs
184TESTS+=		modmatch
185TESTS+=		modmisc
186TESTS+=		modts
187TESTS+=		modword
188TESTS+=		opt
189TESTS+=		opt-backwards
190TESTS+=		opt-chdir
191TESTS+=		opt-debug
192TESTS+=		opt-debug-all
193TESTS+=		opt-debug-archive
194TESTS+=		opt-debug-curdir
195TESTS+=		opt-debug-cond
196TESTS+=		opt-debug-dir
197TESTS+=		opt-debug-errors
198TESTS+=		opt-debug-file
199TESTS+=		opt-debug-for
200TESTS+=		opt-debug-graph1
201TESTS+=		opt-debug-graph2
202TESTS+=		opt-debug-graph3
203TESTS+=		opt-debug-hash
204TESTS+=		opt-debug-jobs
205TESTS+=		opt-debug-lint
206TESTS+=		opt-debug-loud
207TESTS+=		opt-debug-meta
208TESTS+=		opt-debug-making
209TESTS+=		opt-debug-no-rm
210TESTS+=		opt-debug-parse
211TESTS+=		opt-debug-suff
212TESTS+=		opt-debug-targets
213TESTS+=		opt-debug-varraw
214TESTS+=		opt-debug-var
215TESTS+=		opt-debug-x-trace
216TESTS+=		opt-define
217TESTS+=		opt-env
218TESTS+=		opt-file
219TESTS+=		opt-ignore
220TESTS+=		opt-include-dir
221TESTS+=		opt-jobs
222TESTS+=		opt-jobs-internal
223TESTS+=		opt-keep-going
224TESTS+=		opt-m-include-dir
225TESTS+=		opt-no-action
226TESTS+=		opt-no-action-at-all
227TESTS+=		opt-query
228TESTS+=		opt-raw
229TESTS+=		opt-silent
230TESTS+=		opt-touch
231TESTS+=		opt-tracefile
232TESTS+=		opt-var-expanded
233TESTS+=		opt-var-literal
234TESTS+=		opt-warnings-as-errors
235TESTS+=		opt-where-am-i
236TESTS+=		opt-x-reduce-exported
237TESTS+=		order
238TESTS+=		parse-var
239TESTS+=		phony-end
240TESTS+=		posix
241TESTS+=		# posix1	# broken by reverting POSIX changes
242TESTS+=		qequals
243TESTS+=		recursive
244TESTS+=		sh
245TESTS+=		sh-dots
246TESTS+=		sh-jobs
247TESTS+=		sh-jobs-error
248TESTS+=		sh-leading-at
249TESTS+=		sh-leading-hyphen
250TESTS+=		sh-leading-plus
251TESTS+=		sh-meta-chars
252TESTS+=		sh-multi-line
253TESTS+=		sh-single-line
254TESTS+=		shell-csh
255TESTS+=		shell-custom
256TESTS+=		shell-ksh
257TESTS+=		shell-sh
258TESTS+=		suff-add-later
259TESTS+=		suff-clear-regular
260TESTS+=		suff-clear-single
261TESTS+=		suff-lookup
262TESTS+=		suff-main
263TESTS+=		suff-rebuild
264TESTS+=		suff-transform-endless
265TESTS+=		suff-transform-expand
266TESTS+=		suff-transform-select
267TESTS+=		sunshcmd
268TESTS+=		ternary
269TESTS+=		unexport
270TESTS+=		unexport-env
271TESTS+=		use-inference
272TESTS+=		var-class
273TESTS+=		var-class-cmdline
274TESTS+=		var-class-env
275TESTS+=		var-class-global
276TESTS+=		var-class-local
277TESTS+=		var-class-local-legacy
278TESTS+=		var-op
279TESTS+=		var-op-append
280TESTS+=		var-op-assign
281TESTS+=		var-op-default
282TESTS+=		var-op-expand
283TESTS+=		var-op-shell
284TESTS+=		var-op-sunsh
285TESTS+=		var-recursive
286TESTS+=		varcmd
287TESTS+=		vardebug
288TESTS+=		varfind
289TESTS+=		varmisc
290TESTS+=		varmod
291TESTS+=		varmod-assign
292TESTS+=		varmod-defined
293TESTS+=		varmod-edge
294TESTS+=		varmod-exclam-shell
295TESTS+=		varmod-extension
296TESTS+=		varmod-gmtime
297TESTS+=		varmod-hash
298TESTS+=		varmod-head
299TESTS+=		varmod-ifelse
300TESTS+=		varmod-l-name-to-value
301TESTS+=		varmod-localtime
302TESTS+=		varmod-loop
303TESTS+=		varmod-match
304TESTS+=		varmod-match-escape
305TESTS+=		varmod-no-match
306TESTS+=		varmod-order
307TESTS+=		varmod-order-reverse
308TESTS+=		varmod-order-shuffle
309TESTS+=		varmod-path
310TESTS+=		varmod-quote
311TESTS+=		varmod-quote-dollar
312TESTS+=		varmod-range
313TESTS+=		varmod-remember
314TESTS+=		varmod-root
315TESTS+=		varmod-select-words
316TESTS+=		varmod-shell
317TESTS+=		varmod-subst
318TESTS+=		varmod-subst-regex
319TESTS+=		varmod-sysv
320TESTS+=		varmod-tail
321TESTS+=		varmod-to-abs
322TESTS+=		varmod-to-lower
323TESTS+=		varmod-to-many-words
324TESTS+=		varmod-to-one-word
325TESTS+=		varmod-to-separator
326TESTS+=		varmod-to-upper
327TESTS+=		varmod-undefined
328TESTS+=		varmod-unique
329TESTS+=		varname
330TESTS+=		varname-dollar
331TESTS+=		varname-dot-alltargets
332TESTS+=		varname-dot-curdir
333TESTS+=		varname-dot-includes
334TESTS+=		varname-dot-includedfromdir
335TESTS+=		varname-dot-includedfromfile
336TESTS+=		varname-dot-libs
337TESTS+=		varname-dot-make-dependfile
338TESTS+=		varname-dot-make-expand_variables
339TESTS+=		varname-dot-make-exported
340TESTS+=		varname-dot-make-jobs
341TESTS+=		varname-dot-make-jobs-prefix
342TESTS+=		varname-dot-make-level
343TESTS+=		varname-dot-make-makefile_preference
344TESTS+=		varname-dot-make-makefiles
345TESTS+=		varname-dot-make-meta-bailiwick
346TESTS+=		varname-dot-make-meta-created
347TESTS+=		varname-dot-make-meta-files
348TESTS+=		varname-dot-make-meta-ignore_filter
349TESTS+=		varname-dot-make-meta-ignore_paths
350TESTS+=		varname-dot-make-meta-ignore_patterns
351TESTS+=		varname-dot-make-meta-prefix
352TESTS+=		varname-dot-make-mode
353TESTS+=		varname-dot-make-path_filemon
354TESTS+=		varname-dot-make-pid
355TESTS+=		varname-dot-make-ppid
356TESTS+=		varname-dot-make-save_dollars
357TESTS+=		varname-dot-makeoverrides
358TESTS+=		varname-dot-newline
359TESTS+=		varname-dot-objdir
360TESTS+=		varname-dot-parsedir
361TESTS+=		varname-dot-parsefile
362TESTS+=		varname-dot-path
363TESTS+=		varname-dot-shell
364TESTS+=		varname-dot-targets
365TESTS+=		varname-empty
366TESTS+=		varname-make
367TESTS+=		varname-make_print_var_on_error
368TESTS+=		varname-make_print_var_on_error-jobs
369TESTS+=		varname-makefile
370TESTS+=		varname-makeflags
371TESTS+=		varname-pwd
372TESTS+=		varname-vpath
373TESTS+=		varparse-dynamic
374TESTS+=		varparse-mod
375TESTS+=		varparse-undef-partial
376TESTS+=		varquote
377TESTS+=		varshell
378
379# Additional environment variables for some of the tests.
380# The base environment is -i PATH="$PATH".
381ENV.envfirst=		FROM_ENV=value-from-env
382ENV.varmisc=		FROM_ENV=env
383ENV.varmisc+=		FROM_ENV_BEFORE=env
384ENV.varmisc+=		FROM_ENV_AFTER=env
385ENV.varmod-localtime+=	TZ=Europe/Berlin
386
387# Override make flags for some of the tests; default is -k.
388# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
389# settings FLAGS.test=-dv here, since that is closer to the test code.
390FLAGS.cond-func-make=	via-cmdline
391FLAGS.directive-ifmake=	first second
392FLAGS.doterror=		# none
393FLAGS.envfirst=		-e
394FLAGS.export=		# none
395FLAGS.opt-ignore=	-i
396FLAGS.opt-keep-going=	-k
397FLAGS.opt-no-action=	-n
398FLAGS.opt-query=	-q
399FLAGS.opt-var-expanded=	-v VAR -v VALUE
400FLAGS.opt-var-literal=	-V VAR -V VALUE
401FLAGS.opt-warnings-as-errors= -W
402FLAGS.order=		-j1
403FLAGS.recursive=	-dL
404FLAGS.sh-leading-plus=	-n
405FLAGS.varname-empty=	-dv '$${:U}=cmdline-u' '=cmline-plain'
406
407# Some tests need extra postprocessing.
408SED_CMDS.job-output-long-lines= \
409	${:D Job separators on their own line are ok. } \
410	-e '/^--- job-[ab] ---$$/d' \
411	${:D Plain output lines are ok as well. } \
412	${:D They may come in multiples of 1024 or as 10000. } \
413	-e '/^aa*$$/d' \
414	-e '/^bb*$$/d' \
415	${:D The following lines should rather not occur since the job } \
416	${:D marker should always be at the beginning of the line. } \
417	-e '/^aa*--- job-b ---$$/d' \
418	-e '/^bb*--- job-a ---$$/d'
419SED_CMDS.opt-debug-graph1= \
420			-e 's,${.CURDIR},CURDIR,'
421SED_CMDS.opt-debug-graph1+= \
422			-e '/Global Variables:/,/Suffixes:/d'
423SED_CMDS.sh-dots=	-e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
424SED_CMDS.opt-debug-jobs=	-e 's,([0-9][0-9]*),(<pid>),'
425SED_CMDS.opt-debug-jobs+=	-e 's,pid [0-9][0-9]*,pid <pid>,'
426SED_CMDS.opt-debug-jobs+=	-e 's,Process [0-9][0-9]*,Process <pid>,'
427SED_CMDS.opt-debug-jobs+=	-e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
428# The "-q" may be there or not, see jobs.c, variable shells.
429SED_CMDS.opt-debug-jobs+=	-e 's,^\(.Command: sh\) -q,\1,'
430SED_CMDS.varmod-subst-regex+= \
431			-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
432SED_CMDS.varmod-edge+=	-e 's, line [0-9]*:, line omitted:,'
433SED_CMDS.varshell+=	-e 's,^${.SHELL:T}: ,,'
434SED_CMDS.varshell+=	-e '/command/s,No such.*,not found,'
435SED_CMDS.varname-dot-parsedir=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
436SED_CMDS.varname-dot-parsefile=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
437SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
438SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
439SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'
440
441# Some tests need an additional round of postprocessing.
442POSTPROC.deptgt-suffixes= \
443			${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
444POSTPROC.gnode-submake=	awk '/Input graph/, /^$$/'
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	cat "$$mi" > "$$mi.tmp";					\
552	(cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \
553	distrib/sets/fmt-list "$$mi.tmp";				\
554	mv "$$mi.tmp" "$$mi";						\
555	cvs diff "$$mi" || true
556
557.if exists(${TEST_MAKE})
558${TESTS:=.rawout}: ${TEST_MAKE}
559# in meta mode, we *know* if a target script is impacted
560# by a makefile change.
561.if ${.MAKE.MODE:Unormal:Mmeta} == ""
562${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
563.endif
564.endif
565
566.-include <bsd.obj.mk>
567