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