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