Makefile revision 1.259
1# $NetBSD: Makefile,v 1.259 2020/12/30 14:50:08 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# we use these below but we might be an older make
35.MAKE.OS?= ${uname -s:L:sh}
36.MAKE.UID?= ${id -u:L:sh}
37
38# Each test is in a sub-makefile.
39# Keep the list sorted.
40# Any test that is commented out must be ignored in
41# src/tests/usr.bin/make/t_make.sh as well.
42TESTS+=		archive
43TESTS+=		archive-suffix
44TESTS+=		cmd-errors
45TESTS+=		cmd-errors-jobs
46TESTS+=		cmd-errors-lint
47TESTS+=		cmd-interrupt
48TESTS+=		cmdline
49TESTS+=		cmdline-undefined
50TESTS+=		comment
51TESTS+=		compat-error
52TESTS+=		cond-cmp-numeric
53TESTS+=		cond-cmp-numeric-eq
54TESTS+=		cond-cmp-numeric-ge
55TESTS+=		cond-cmp-numeric-gt
56TESTS+=		cond-cmp-numeric-le
57TESTS+=		cond-cmp-numeric-lt
58TESTS+=		cond-cmp-numeric-ne
59TESTS+=		cond-cmp-string
60TESTS+=		cond-cmp-unary
61TESTS+=		cond-eof
62TESTS+=		cond-func
63TESTS+=		cond-func-commands
64TESTS+=		cond-func-defined
65TESTS+=		cond-func-empty
66TESTS+=		cond-func-exists
67TESTS+=		cond-func-make
68TESTS+=		cond-func-make-main
69TESTS+=		cond-func-target
70TESTS+=		cond-late
71TESTS+=		cond-op
72TESTS+=		cond-op-and
73TESTS+=		cond-op-and-lint
74TESTS+=		cond-op-not
75TESTS+=		cond-op-or
76TESTS+=		cond-op-or-lint
77TESTS+=		cond-op-parentheses
78TESTS+=		cond-short
79TESTS+=		cond-token-number
80TESTS+=		cond-token-plain
81TESTS+=		cond-token-string
82TESTS+=		cond-token-var
83TESTS+=		cond-undef-lint
84TESTS+=		cond1
85TESTS+=		counter
86TESTS+=		counter-append
87TESTS+=		dep
88TESTS+=		dep-colon
89TESTS+=		dep-colon-bug-cross-file
90TESTS+=		dep-double-colon
91TESTS+=		dep-double-colon-indep
92TESTS+=		dep-exclam
93TESTS+=		dep-none
94TESTS+=		dep-percent
95TESTS+=		dep-var
96TESTS+=		dep-wildcards
97TESTS+=		depsrc
98TESTS+=		depsrc-end
99TESTS+=		depsrc-exec
100TESTS+=		depsrc-ignore
101TESTS+=		depsrc-made
102TESTS+=		depsrc-make
103TESTS+=		depsrc-meta
104TESTS+=		depsrc-nometa
105TESTS+=		depsrc-nometa_cmp
106TESTS+=		depsrc-nopath
107TESTS+=		depsrc-notmain
108TESTS+=		depsrc-optional
109TESTS+=		depsrc-phony
110TESTS+=		depsrc-precious
111TESTS+=		depsrc-recursive
112TESTS+=		depsrc-silent
113TESTS+=		depsrc-use
114TESTS+=		depsrc-usebefore
115TESTS+=		depsrc-usebefore-double-colon
116TESTS+=		depsrc-wait
117TESTS+=		deptgt
118TESTS+=		deptgt-begin
119TESTS+=		deptgt-begin-fail
120TESTS+=		deptgt-begin-fail-indirect
121TESTS+=		deptgt-default
122TESTS+=		deptgt-delete_on_error
123TESTS+=		deptgt-end
124TESTS+=		deptgt-end-fail
125TESTS+=		deptgt-end-fail-all
126TESTS+=		deptgt-end-fail-indirect
127TESTS+=		deptgt-end-jobs
128TESTS+=		deptgt-error
129TESTS+=		deptgt-ignore
130TESTS+=		deptgt-interrupt
131TESTS+=		deptgt-main
132TESTS+=		deptgt-makeflags
133TESTS+=		deptgt-no_parallel
134TESTS+=		deptgt-nopath
135TESTS+=		deptgt-notparallel
136TESTS+=		deptgt-objdir
137TESTS+=		deptgt-order
138TESTS+=		deptgt-path
139TESTS+=		deptgt-path-suffix
140TESTS+=		deptgt-phony
141TESTS+=		deptgt-precious
142TESTS+=		deptgt-shell
143TESTS+=		deptgt-silent
144TESTS+=		deptgt-stale
145TESTS+=		deptgt-suffixes
146TESTS+=		dir
147TESTS+=		dir-expand-path
148TESTS+=		directive
149TESTS+=		directive-dinclude
150TESTS+=		directive-elif
151TESTS+=		directive-elifdef
152TESTS+=		directive-elifmake
153TESTS+=		directive-elifndef
154TESTS+=		directive-elifnmake
155TESTS+=		directive-else
156TESTS+=		directive-endfor
157TESTS+=		directive-endif
158TESTS+=		directive-error
159TESTS+=		directive-export
160TESTS+=		directive-export-env
161TESTS+=		directive-export-impl
162TESTS+=		directive-export-gmake
163TESTS+=		directive-export-literal
164TESTS+=		directive-for
165TESTS+=		directive-for-generating-endif
166TESTS+=		directive-for-lines
167TESTS+=		directive-for-null
168TESTS+=		directive-hyphen-include
169TESTS+=		directive-if
170TESTS+=		directive-if-nested
171TESTS+=		directive-ifdef
172TESTS+=		directive-ifmake
173TESTS+=		directive-ifndef
174TESTS+=		directive-ifnmake
175TESTS+=		directive-include
176TESTS+=		directive-include-fatal
177TESTS+=		directive-info
178TESTS+=		directive-misspellings
179TESTS+=		directive-sinclude
180TESTS+=		directive-undef
181TESTS+=		directive-unexport
182TESTS+=		directive-unexport-env
183TESTS+=		directive-warning
184TESTS+=		dollar
185TESTS+=		doterror
186TESTS+=		dotwait
187TESTS+=		envfirst
188TESTS+=		error
189TESTS+=		# escape	# broken by reverting POSIX changes
190TESTS+=		export
191TESTS+=		export-all
192TESTS+=		export-env
193TESTS+=		export-variants
194TESTS+=		forloop
195TESTS+=		forsubst
196TESTS+=		gnode-submake
197TESTS+=		hanoi-include
198TESTS+=		impsrc
199TESTS+=		include-main
200TESTS+=		job-flags
201TESTS+=		job-output-long-lines
202TESTS+=		jobs-error-indirect
203TESTS+=		jobs-error-nested
204TESTS+=		jobs-error-nested-make
205TESTS+=		lint
206TESTS+=		make-exported
207TESTS+=		meta-cmd-cmp
208TESTS+=		moderrs
209TESTS+=		modmatch
210TESTS+=		modmisc
211TESTS+=		modts
212TESTS+=		modword
213.if ${.MAKE.UID} > 0
214TESTS+=		objdir-writable
215.endif
216TESTS+=		opt
217TESTS+=		opt-backwards
218TESTS+=		opt-chdir
219TESTS+=		opt-debug
220TESTS+=		opt-debug-all
221TESTS+=		opt-debug-archive
222TESTS+=		opt-debug-curdir
223TESTS+=		opt-debug-cond
224TESTS+=		opt-debug-dir
225TESTS+=		opt-debug-errors
226TESTS+=		opt-debug-file
227TESTS+=		opt-debug-for
228TESTS+=		opt-debug-graph1
229TESTS+=		opt-debug-graph2
230TESTS+=		opt-debug-graph3
231TESTS+=		opt-debug-hash
232TESTS+=		opt-debug-jobs
233TESTS+=		opt-debug-lint
234TESTS+=		opt-debug-loud
235TESTS+=		opt-debug-meta
236TESTS+=		opt-debug-making
237TESTS+=		opt-debug-no-rm
238TESTS+=		opt-debug-parse
239TESTS+=		opt-debug-suff
240TESTS+=		opt-debug-targets
241TESTS+=		opt-debug-varraw
242TESTS+=		opt-debug-var
243TESTS+=		opt-debug-x-trace
244TESTS+=		opt-define
245TESTS+=		opt-env
246TESTS+=		opt-file
247TESTS+=		opt-ignore
248TESTS+=		opt-include-dir
249TESTS+=		opt-jobs
250TESTS+=		opt-jobs-internal
251TESTS+=		opt-jobs-no-action
252TESTS+=		opt-keep-going
253TESTS+=		opt-keep-going-multiple
254TESTS+=		opt-m-include-dir
255TESTS+=		opt-no-action
256TESTS+=		opt-no-action-at-all
257TESTS+=		opt-no-action-runflags
258TESTS+=		opt-query
259TESTS+=		opt-raw
260TESTS+=		opt-silent
261TESTS+=		opt-touch
262TESTS+=		opt-touch-jobs
263TESTS+=		opt-tracefile
264TESTS+=		opt-var-expanded
265TESTS+=		opt-var-literal
266TESTS+=		opt-warnings-as-errors
267TESTS+=		opt-where-am-i
268TESTS+=		opt-x-reduce-exported
269TESTS+=		order
270TESTS+=		parse-var
271TESTS+=		phony-end
272TESTS+=		posix
273TESTS+=		# posix1	# broken by reverting POSIX changes
274TESTS+=		recursive
275TESTS+=		sh
276TESTS+=		sh-dots
277TESTS+=		sh-errctl
278TESTS+=		sh-flags
279TESTS+=		sh-jobs
280TESTS+=		sh-jobs-error
281TESTS+=		sh-leading-at
282TESTS+=		sh-leading-hyphen
283TESTS+=		sh-leading-plus
284TESTS+=		sh-meta-chars
285TESTS+=		sh-multi-line
286TESTS+=		sh-single-line
287TESTS+=		shell-csh
288TESTS+=		shell-custom
289TESTS+=		shell-ksh
290TESTS+=		shell-sh
291TESTS+=		suff-add-later
292TESTS+=		suff-clear-regular
293TESTS+=		suff-clear-single
294TESTS+=		suff-incomplete
295TESTS+=		suff-lookup
296TESTS+=		suff-main
297TESTS+=		suff-main-several
298TESTS+=		suff-phony
299TESTS+=		suff-rebuild
300TESTS+=		suff-self
301TESTS+=		suff-transform-debug
302TESTS+=		suff-transform-endless
303TESTS+=		suff-transform-expand
304TESTS+=		suff-transform-select
305TESTS+=		sunshcmd
306TESTS+=		ternary
307TESTS+=		unexport
308TESTS+=		unexport-env
309TESTS+=		use-inference
310TESTS+=		var-class
311TESTS+=		var-class-cmdline
312TESTS+=		var-class-env
313TESTS+=		var-class-global
314TESTS+=		var-class-local
315TESTS+=		var-class-local-legacy
316TESTS+=		var-op
317TESTS+=		var-op-append
318TESTS+=		var-op-assign
319TESTS+=		var-op-default
320TESTS+=		var-op-expand
321TESTS+=		var-op-shell
322TESTS+=		var-op-sunsh
323TESTS+=		var-recursive
324TESTS+=		varcmd
325TESTS+=		vardebug
326TESTS+=		varfind
327TESTS+=		varmisc
328TESTS+=		varmod
329TESTS+=		varmod-assign
330TESTS+=		varmod-defined
331TESTS+=		varmod-edge
332TESTS+=		varmod-exclam-shell
333TESTS+=		varmod-extension
334TESTS+=		varmod-gmtime
335TESTS+=		varmod-hash
336TESTS+=		varmod-head
337TESTS+=		varmod-ifelse
338TESTS+=		varmod-indirect
339TESTS+=		varmod-l-name-to-value
340TESTS+=		varmod-localtime
341TESTS+=		varmod-loop
342TESTS+=		varmod-match
343TESTS+=		varmod-match-escape
344TESTS+=		varmod-no-match
345TESTS+=		varmod-order
346TESTS+=		varmod-order-reverse
347TESTS+=		varmod-order-shuffle
348TESTS+=		varmod-path
349TESTS+=		varmod-quote
350TESTS+=		varmod-quote-dollar
351TESTS+=		varmod-range
352TESTS+=		varmod-remember
353TESTS+=		varmod-root
354TESTS+=		varmod-select-words
355TESTS+=		varmod-shell
356TESTS+=		varmod-subst
357TESTS+=		varmod-subst-regex
358TESTS+=		varmod-sysv
359TESTS+=		varmod-tail
360TESTS+=		varmod-to-abs
361TESTS+=		varmod-to-lower
362TESTS+=		varmod-to-many-words
363TESTS+=		varmod-to-one-word
364TESTS+=		varmod-to-separator
365TESTS+=		varmod-to-upper
366TESTS+=		varmod-undefined
367TESTS+=		varmod-unique
368TESTS+=		varname
369TESTS+=		varname-dollar
370TESTS+=		varname-dot-alltargets
371TESTS+=		varname-dot-curdir
372TESTS+=		varname-dot-includes
373TESTS+=		varname-dot-includedfromdir
374TESTS+=		varname-dot-includedfromfile
375TESTS+=		varname-dot-libs
376TESTS+=		varname-dot-make-dependfile
377TESTS+=		varname-dot-make-expand_variables
378TESTS+=		varname-dot-make-exported
379TESTS+=		varname-dot-make-jobs
380TESTS+=		varname-dot-make-jobs-prefix
381TESTS+=		varname-dot-make-level
382TESTS+=		varname-dot-make-makefile_preference
383TESTS+=		varname-dot-make-makefiles
384TESTS+=		varname-dot-make-meta-bailiwick
385TESTS+=		varname-dot-make-meta-created
386TESTS+=		varname-dot-make-meta-files
387TESTS+=		varname-dot-make-meta-ignore_filter
388TESTS+=		varname-dot-make-meta-ignore_paths
389TESTS+=		varname-dot-make-meta-ignore_patterns
390TESTS+=		varname-dot-make-meta-prefix
391TESTS+=		varname-dot-make-mode
392TESTS+=		varname-dot-make-path_filemon
393TESTS+=		varname-dot-make-pid
394TESTS+=		varname-dot-make-ppid
395TESTS+=		varname-dot-make-save_dollars
396TESTS+=		varname-dot-makeflags
397TESTS+=		varname-dot-makeoverrides
398TESTS+=		varname-dot-newline
399TESTS+=		varname-dot-objdir
400TESTS+=		varname-dot-parsedir
401TESTS+=		varname-dot-parsefile
402TESTS+=		varname-dot-path
403TESTS+=		varname-dot-shell
404TESTS+=		varname-dot-targets
405TESTS+=		varname-empty
406TESTS+=		varname-make
407TESTS+=		varname-make_print_var_on_error
408TESTS+=		varname-make_print_var_on_error-jobs
409TESTS+=		varname-makefile
410TESTS+=		varname-makeflags
411TESTS+=		varname-pwd
412TESTS+=		varname-vpath
413TESTS+=		varparse-dynamic
414TESTS+=		varparse-errors
415TESTS+=		varparse-mod
416TESTS+=		varparse-undef-partial
417TESTS+=		varquote
418
419# Ideas for more tests:
420#	char-0020-space.mk
421#	char-005C-backslash.mk
422#	escape-cond-str.mk
423#	escape-cond-func-arg.mk
424#	escape-cond-func-arg.mk
425#	escape-varmod.mk
426#	escape-varmod-define.mk
427#	escape-varmod-match.mk
428#	escape-varname.mk
429#	escape-varassign-varname.mk
430#	escape-varassign-varname-cmdline.mk
431#	escape-varassign-value.mk
432#	escape-varassign-value-cmdline.mk
433#	escape-dependency-source.mk
434#	escape-dependency-target.mk
435#	escape-for-varname.mk
436#	escape-for-item.mk
437#	posix-*.mk (see posix.mk and posix1.mk)
438
439.if ${.OBJDIR} != ${.CURDIR}
440RO_OBJDIR:=	${.OBJDIR}/roobj
441.else
442RO_OBJDIR:=	${TMPDIR:U/tmp}/roobj
443.endif
444# Additional environment variables for some of the tests.
445# The base environment is -i PATH="$PATH".
446ENV.depsrc-optional+=   TZ=UTC
447ENV.envfirst=		FROM_ENV=value-from-env
448ENV.objdir-writable+=	RO_OBJDIR=${RO_OBJDIR}
449ENV.varmisc=		FROM_ENV=env
450ENV.varmisc+=		FROM_ENV_BEFORE=env
451ENV.varmisc+=		FROM_ENV_AFTER=env
452ENV.varmod-localtime+=	TZ=Europe/Berlin
453ENV.varname-vpath+=	VPATH=varname-vpath.dir:varname-vpath.dir2
454
455# Override make flags for some of the tests; default is -k.
456# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
457# settings FLAGS.test=-dv here, since that is closer to the test code.
458FLAGS.cond-func-make=		via-cmdline
459FLAGS.directive-ifmake=		first second
460FLAGS.doterror=			# none, especially not -k
461FLAGS.jobs-error-indirect=	# none, especially not -k
462FLAGS.jobs-error-nested=	# none, especially not -k
463FLAGS.jobs-error-nested-make=	# none, especially not -k
464FLAGS.varname-empty=		-dv '$${:U}=cmdline-u' '=cmdline-plain'
465
466# Some tests need extra postprocessing.
467SED_CMDS.dir=		${:D remove output from -DCLEANUP mode }
468SED_CMDS.dir+=		-e '/^OpenDirs_Done:/d'
469SED_CMDS.dir+=		-e '/^CachedDir /d'
470SED_CMDS.export=	-e '/^[^=_A-Za-z0-9]*=/d'
471SED_CMDS.export-all=	${SED_CMDS.export}
472SED_CMDS.export-env=	${SED_CMDS.export}
473SED_CMDS.job-output-long-lines= \
474	${:D Job separators on their own line are ok. } \
475	-e '/^--- job-[ab] ---$$/d' \
476	${:D Plain output lines are ok as well. } \
477	${:D They may come in multiples of 1024 or as 10000. } \
478	-e '/^aa*$$/d' \
479	-e '/^bb*$$/d' \
480	${:D The following lines should rather not occur since the job } \
481	${:D marker should always be at the beginning of the line. } \
482	-e '/^aa*--- job-b ---$$/d' \
483	-e '/^bb*--- job-a ---$$/d'
484SED_CMDS.objdir-writable=	-e 's,${RO_OBJDIR},OBJDIR/roobj,g'
485SED_CMDS.opt-debug-graph1=	${STD_SED_CMDS.dg1}
486SED_CMDS.opt-debug-jobs=	-e 's,([0-9][0-9]*),(<pid>),'
487SED_CMDS.opt-debug-jobs+=	-e 's,pid [0-9][0-9]*,pid <pid>,'
488SED_CMDS.opt-debug-jobs+=	-e 's,Process [0-9][0-9]*,Process <pid>,'
489SED_CMDS.opt-debug-jobs+=	-e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
490SED_CMDS.opt-debug-jobs+=	-e 's,Command: ${.SHELL:T},Command: <shell>,'
491# The "-q" may be there or not, see jobs.c, variable shells.
492SED_CMDS.opt-debug-jobs+=	-e 's,^\(.Command: <shell>\) -q,\1,'
493SED_CMDS.opt-jobs-no-action=	${STD_SED_CMDS.hide-from-output}
494SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
495# For Compat_RunCommand, useShell == FALSE.
496SED_CMDS.sh-dots=		-e 's,^.*\.\.\.:.*,<not found: ...>,'
497# For Compat_RunCommand, useShell == TRUE.
498SED_CMDS.sh-dots+=		-e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
499SED_CMDS.sh-dots+=		-e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
500SED_CMDS.sh-errctl=		${STD_SED_CMDS.dj}
501SED_CMDS.sh-flags=		${STD_SED_CMDS.hide-from-output}
502SED_CMDS.suff-main+=		${STD_SED_CMDS.dg1}
503SED_CMDS.suff-main-several+=	${STD_SED_CMDS.dg1}
504SED_CMDS.suff-transform-debug+=	${STD_SED_CMDS.dg1}
505SED_CMDS.var-op-shell+=	\
506	-e 's,^${.SHELL:T}: [ 0-9:]*,,' \
507	-e '/command/s,No such.*,not found,'
508SED_CMDS.vardebug+=	-e 's,${.SHELL},</path/to/shell>,'
509SED_CMDS.varmod-subst-regex+= \
510			-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
511SED_CMDS.varname-dot-parsedir=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
512SED_CMDS.varname-dot-parsefile=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
513SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
514SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
515SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'
516
517# Some tests need an additional round of postprocessing.
518POSTPROC.deptgt-suffixes=	awk '/^\#\*\*\* Suffixes/,/^never-stop/'
519POSTPROC.gnode-submake=		awk '/Input graph/, /^$$/'
520POSTPROC.varname-empty=		${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
521
522# Some tests reuse other tests, which makes them unnecessarily fragile.
523export-all.rawout: export.mk
524unexport.rawout: export.mk
525unexport-env.rawout: export.mk
526
527# End of the configuration section.
528
529# Some standard sed commands, to be used in the SED_CMDS above.
530
531# Omit details such as process IDs from the output of the -dg1 option.
532STD_SED_CMDS.dg1=	-e 's,${.CURDIR}$$,<curdir>,'
533STD_SED_CMDS.dg1+=	-e 's,  ${DEFSYSPATH:U/usr/share/mk}$$,  <defsyspath>,'
534STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
535STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
536STD_SED_CMDS.dg1+=	-e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
537STD_SED_CMDS.dg1+=	-e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
538
539# Omit details such as process IDs from the output of the -dj option.
540STD_SED_CMDS.dj= \
541	-e '/Process/d;/JobFinish:/d' \
542	-e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \
543	-e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \
544	-e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \
545	-e 's,^\(	Command:\) .*,\1 <shell>,'
546
547# Reduce the noise for tests running with the -n option, since there is no
548# other way to suppress the echoing of the commands.
549STD_SED_CMDS.hide-from-output= \
550	-e '/^echo hide-from-output/d' \
551	-e 's,hide-from-output ,,' \
552	-e 's,hide-from-output,,'
553
554# End of the configuration helpers section.
555
556.MAIN: all
557
558UNIT_TESTS:=	${.PARSEDIR}
559.PATH: ${UNIT_TESTS}
560
561.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
562OUTFILES=	${TESTS:@test@${.CURDIR:tA}/${test}.out@}
563.else
564OUTFILES=	${TESTS:=.out}
565.endif
566
567all: ${OUTFILES}
568
569CLEANFILES=		*.rawout *.out *.status *.tmp *.core *.tmp
570CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
571CLEANFILES+=		issue* .[ab]*		# suffixes.mk
572CLEANDIRS=		dir dummy		# posix1.mk
573
574clean:
575	rm -f ${CLEANFILES}
576	rm -rf ${CLEANDIRS}
577
578TEST_MAKE?=	${.MAKE}
579TOOL_SED?=	sed
580
581# ensure consistent results from sort(1)
582LC_ALL=		C
583LANG=		C
584.export LANG LC_ALL
585
586MAKE_TEST_ENV?=	MALLOC_OPTIONS="JA"	# for jemalloc
587
588.if ${.MAKE.OS} == "NetBSD"
589LIMIT_RESOURCES?=	ulimit -v 200000
590.endif
591LIMIT_RESOURCES?=	:
592
593# Each test is run in a sub-make, to keep the tests for interfering with
594# each other, and because they use different environment variables and
595# command line options.
596.SUFFIXES: .mk .rawout .out
597.mk.rawout:
598	@${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
599	@set -eu; \
600	${LIMIT_RESOURCES}; \
601	cd ${.OBJDIR}; \
602	env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
603	  ${TEST_MAKE} \
604	    -r -C ${.CURDIR} -f ${.IMPSRC} \
605	    ${FLAGS.${.PREFIX:T}:U-k} \
606	    > ${.TARGET}.tmp 2>&1 \
607	&& status=$$? || status=$$?; \
608	echo $$status > ${.TARGET:R}.status
609	@mv ${.TARGET}.tmp ${.TARGET}
610
611# Postprocess the test output so that the results can be compared.
612#
613# always pretend .MAKE was called 'make'
614_SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
615_SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
616_SED_CMDS+=	-e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
617_SED_CMDS+=	-e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
618# replace anything after 'stopped in' with unit-tests
619_SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
620# strip ${.CURDIR}/ from the output
621_SED_CMDS+=	-e 's,${.CURDIR:S,.,\\.,g}/,,g'
622_SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
623
624.rawout.out:
625	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
626	  < ${.IMPSRC} > ${.TARGET}.tmp1
627	@${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
628	@rm ${.TARGET}.tmp1
629	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
630	@mv ${.TARGET}.tmp2 ${.TARGET}
631
632# Compare all output files
633test:	${OUTFILES} .PHONY
634	@failed= ; \
635	for test in ${TESTS}; do \
636	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
637	  || failed="$${failed}$${failed:+ }$${test}" ; \
638	done ; \
639	if [ -n "$${failed}" ]; then \
640	  echo "Failed tests: $${failed}" ; false ; \
641	else \
642	  echo "All tests passed" ; \
643	fi
644
645accept:
646	@for test in ${TESTS}; do \
647	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
648	  || { echo "Replacing $${test}.exp" ; \
649	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
650	done
651
652# Note: only works for adding tests.
653# To remove a test, the $$mi file must be edited manually.
654sync-mi:
655	@set -eu;							\
656	cd "${MAKEFILE:tA:H}/../../..";					\
657	mi="distrib/sets/lists/tests/mi";				\
658	cvs update "$$mi";						\
659	testsdir="usr.bin/make/unit-tests";				\
660	fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
661	cat "$$mi" > "$$mi.tmp";					\
662	(cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \
663	distrib/sets/fmt-list "$$mi.tmp";				\
664	mv "$$mi.tmp" "$$mi";						\
665	cvs diff "$$mi" || true
666
667.if exists(${TEST_MAKE})
668${TESTS:=.rawout}: ${TEST_MAKE}
669# in meta mode, we *know* if a target script is impacted
670# by a makefile change.
671.if ${.MAKE.MODE:Unormal:Mmeta} == ""
672${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
673.endif
674.endif
675
676.-include <bsd.obj.mk>
677