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