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