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