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