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