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