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