xref: /freebsd/contrib/bmake/unit-tests/Makefile (revision d93b4d32034df7cd70e80b496e8fe8c1bc57c629)
1# $Id: Makefile,v 1.164 2021/12/12 22:50:00 sjg Exp $
2#
3# $NetBSD: Makefile,v 1.288 2021/12/12 22:16: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-if
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
206#TESTS+=		job-output-long-lines
207TESTS+=		job-output-null
208TESTS+=		jobs-empty-commands
209TESTS+=		jobs-empty-commands-error
210TESTS+=		jobs-error-indirect
211TESTS+=		jobs-error-nested
212TESTS+=		jobs-error-nested-make
213TESTS+=		lint
214TESTS+=		make-exported
215TESTS+=		meta-cmd-cmp
216TESTS+=		moderrs
217TESTS+=		modmatch
218TESTS+=		modmisc
219TESTS+=		modts
220TESTS+=		modword
221.if ${.MAKE.UID} > 0
222TESTS+=		objdir-writable
223.endif
224TESTS+=		opt
225TESTS+=		opt-backwards
226TESTS+=		opt-chdir
227TESTS+=		opt-debug
228TESTS+=		opt-debug-all
229TESTS+=		opt-debug-archive
230TESTS+=		opt-debug-curdir
231TESTS+=		opt-debug-cond
232TESTS+=		opt-debug-dir
233TESTS+=		opt-debug-errors
234TESTS+=		opt-debug-errors-jobs
235TESTS+=		opt-debug-file
236TESTS+=		opt-debug-for
237TESTS+=		opt-debug-graph1
238TESTS+=		opt-debug-graph2
239TESTS+=		opt-debug-graph3
240TESTS+=		opt-debug-hash
241#TESTS+=		opt-debug-jobs
242TESTS+=		opt-debug-lint
243TESTS+=		opt-debug-loud
244TESTS+=		opt-debug-meta
245TESTS+=		opt-debug-making
246TESTS+=		opt-debug-no-rm
247TESTS+=		opt-debug-parse
248TESTS+=		opt-debug-suff
249TESTS+=		opt-debug-targets
250TESTS+=		opt-debug-varraw
251TESTS+=		opt-debug-var
252TESTS+=		opt-debug-x-trace
253TESTS+=		opt-define
254TESTS+=		opt-env
255TESTS+=		opt-file
256TESTS+=		opt-ignore
257TESTS+=		opt-include-dir
258TESTS+=		opt-jobs
259TESTS+=		opt-jobs-internal
260TESTS+=		opt-jobs-no-action
261TESTS+=		opt-keep-going
262TESTS+=		opt-keep-going-multiple
263TESTS+=		opt-m-include-dir
264TESTS+=		opt-no-action
265TESTS+=		opt-no-action-at-all
266TESTS+=		opt-no-action-runflags
267TESTS+=		opt-no-action-touch
268TESTS+=		opt-query
269TESTS+=		opt-raw
270TESTS+=		opt-silent
271TESTS+=		opt-touch
272TESTS+=		opt-touch-jobs
273TESTS+=		opt-tracefile
274TESTS+=		opt-var-expanded
275TESTS+=		opt-var-literal
276TESTS+=		opt-warnings-as-errors
277TESTS+=		opt-where-am-i
278TESTS+=		opt-x-reduce-exported
279TESTS+=		order
280TESTS+=		parse-var
281TESTS+=		phony-end
282TESTS+=		posix
283TESTS+=		# posix1	# broken by reverting POSIX changes
284TESTS+=		recursive
285TESTS+=		sh
286TESTS+=		sh-dots
287TESTS+=		sh-errctl
288TESTS+=		sh-flags
289TESTS+=		sh-jobs
290TESTS+=		sh-jobs-error
291TESTS+=		sh-leading-at
292TESTS+=		sh-leading-hyphen
293TESTS+=		sh-leading-plus
294TESTS+=		sh-meta-chars
295TESTS+=		sh-multi-line
296TESTS+=		sh-single-line
297TESTS+=		shell-csh
298TESTS+=		shell-custom
299.if exists(/bin/ksh)
300TESTS+=		shell-ksh
301.endif
302TESTS+=		shell-sh
303TESTS+=		suff-add-later
304TESTS+=		suff-clear-regular
305TESTS+=		suff-clear-single
306TESTS+=		suff-incomplete
307TESTS+=		suff-lookup
308TESTS+=		suff-main
309TESTS+=		suff-main-several
310TESTS+=		suff-phony
311TESTS+=		suff-rebuild
312TESTS+=		suff-self
313TESTS+=		suff-transform-debug
314TESTS+=		suff-transform-endless
315TESTS+=		suff-transform-expand
316TESTS+=		suff-transform-select
317TESTS+=		sunshcmd
318TESTS+=		ternary
319TESTS+=		unexport
320TESTS+=		unexport-env
321TESTS+=		use-inference
322TESTS+=		var-class
323TESTS+=		var-class-cmdline
324TESTS+=		var-class-env
325TESTS+=		var-class-global
326TESTS+=		var-class-local
327TESTS+=		var-class-local-legacy
328TESTS+=		var-eval-short
329TESTS+=		var-op
330TESTS+=		var-op-append
331TESTS+=		var-op-assign
332TESTS+=		var-op-default
333TESTS+=		var-op-expand
334TESTS+=		var-op-shell
335TESTS+=		var-op-sunsh
336TESTS+=		var-recursive
337TESTS+=		varcmd
338TESTS+=		vardebug
339TESTS+=		varfind
340TESTS+=		varmisc
341TESTS+=		varmod
342TESTS+=		varmod-assign
343TESTS+=		varmod-defined
344TESTS+=		varmod-edge
345TESTS+=		varmod-exclam-shell
346TESTS+=		varmod-extension
347TESTS+=		varmod-gmtime
348TESTS+=		varmod-hash
349TESTS+=		varmod-head
350TESTS+=		varmod-ifelse
351TESTS+=		varmod-indirect
352TESTS+=		varmod-l-name-to-value
353TESTS+=		varmod-localtime
354TESTS+=		varmod-loop
355TESTS+=		varmod-loop-delete
356TESTS+=		varmod-loop-varname
357TESTS+=		varmod-match
358TESTS+=		varmod-match-escape
359TESTS+=		varmod-no-match
360TESTS+=		varmod-order
361TESTS+=		varmod-order-numeric
362TESTS+=		varmod-order-reverse
363TESTS+=		varmod-order-shuffle
364TESTS+=		varmod-order-string
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-suffixes
423TESTS+=		varname-dot-targets
424TESTS+=		varname-empty
425TESTS+=		varname-make
426TESTS+=		varname-make_print_var_on_error
427TESTS+=		varname-make_print_var_on_error-jobs
428TESTS+=		varname-makefile
429TESTS+=		varname-makeflags
430TESTS+=		varname-pwd
431TESTS+=		varname-vpath
432TESTS+=		varparse-dynamic
433TESTS+=		varparse-errors
434TESTS+=		varparse-mod
435TESTS+=		varparse-undef-partial
436TESTS+=		varquote
437
438# for now at least
439.if ${.SHELL:T} == "ksh"
440BROKEN_TESTS+= sh-flags
441.endif
442.if ${.MAKE.OS:NDarwin} == ""
443BROKEN_TESTS+= shell-ksh
444.endif
445.if ${.MAKE.OS} == "SCO_SV"
446BROKEN_TESTS+= \
447	opt-debug-graph[23] \
448	varmod-localtime \
449	varmod-to-separator \
450
451.if ${.SHELL:T} == "bash"
452BROKEN_TESTS+= job-output-null
453.else
454BROKEN_TESTS+= \
455	cmd-interrupt \
456	job-flags \
457
458.endif
459.endif
460
461# Some tests just do not work on some platforms or environments
462# so allow for some filtering.
463.if !empty(BROKEN_TESTS)
464.warning Skipping broken tests: ${BROKEN_TESTS:O:u}
465TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}}
466.endif
467
468# Ideas for more tests:
469#	char-0020-space.mk
470#	char-005C-backslash.mk
471#	escape-cond-str.mk
472#	escape-cond-func-arg.mk
473#	escape-varmod.mk
474#	escape-varmod-define.mk
475#	escape-varmod-match.mk
476#	escape-varname.mk
477#	escape-varassign-varname.mk
478#	escape-varassign-varname-cmdline.mk
479#	escape-varassign-value.mk
480#	escape-varassign-value-cmdline.mk
481#	escape-dependency-source.mk
482#	escape-dependency-target.mk
483#	escape-for-varname.mk
484#	escape-for-item.mk
485#	posix-*.mk (see posix.mk and posix1.mk)
486
487# Additional environment variables for some of the tests.
488# The base environment is -i PATH="$PATH".
489ENV.depsrc-optional+=   TZ=UTC
490ENV.envfirst=		FROM_ENV=value-from-env
491ENV.varmisc=		FROM_ENV=env
492ENV.varmisc+=		FROM_ENV_BEFORE=env
493ENV.varmisc+=		FROM_ENV_AFTER=env
494ENV.varmod-localtime+=	TZ=${UTC_1:UEurope/Berlin}
495ENV.varname-vpath+=	VPATH=varname-vpath.dir:varname-vpath.dir2
496
497# Override make flags for some of the tests; default is -k.
498# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
499# settings FLAGS.test=-dv here, since that is closer to the test code.
500FLAGS.cond-func-make=		via-cmdline
501FLAGS.directive-ifmake=		first second
502FLAGS.doterror=			# none, especially not -k
503FLAGS.jobs-error-indirect=	# none, especially not -k
504FLAGS.jobs-error-nested=	# none, especially not -k
505FLAGS.jobs-error-nested-make=	# none, especially not -k
506FLAGS.varname-empty=		-dv '$${:U}=cmdline-u' '=cmdline-plain'
507
508# Some tests need extra postprocessing.
509SED_CMDS.dir=		${:D remove output from -DCLEANUP mode }
510SED_CMDS.dir+=		-e '/^OpenDirs_Done:/d'
511SED_CMDS.dir+=		-e '/^CachedDir /d'
512SED_CMDS.export=	-e '/^[^=_A-Za-z0-9]*=/d'
513SED_CMDS.export-all=	${SED_CMDS.export}
514SED_CMDS.export-env=	${SED_CMDS.export}
515SED_CMDS.cmdline=	-e 's,uid${.MAKE.UID}/,,'
516SED_CMDS.job-output-long-lines= \
517	${:D Job separators on their own line are ok. } \
518	-e '/^--- job-[ab] ---$$/d' \
519	${:D Plain output lines are ok as well. } \
520	${:D They may come in multiples of 1024 or as 10000. } \
521	-e '/^aa*$$/d' \
522	-e '/^bb*$$/d' \
523	${:D The following lines should rather not occur since the job } \
524	${:D marker should always be at the beginning of the line. } \
525	-e '/^aa*--- job-b ---$$/d' \
526	-e '/^bb*--- job-a ---$$/d'
527SED_CMDS.opt-chdir=		-e 's,\(nonexistent\).[1-9][0-9]*,\1,' \
528	-e '/name/s,file,File,' \
529	-e 's,no such,No such,' \
530	-e 's,Filename,File name,'
531SED_CMDS.opt-debug-graph1=	${STD_SED_CMDS.dg1}
532SED_CMDS.opt-debug-graph2=	${STD_SED_CMDS.dg2}
533SED_CMDS.opt-debug-graph3=	${STD_SED_CMDS.dg3}
534SED_CMDS.opt-debug-jobs=	-e 's,([0-9][0-9]*),(<pid>),'
535SED_CMDS.opt-debug-jobs+=	-e 's,pid [0-9][0-9]*,pid <pid>,'
536SED_CMDS.opt-debug-jobs+=	-e 's,Process [0-9][0-9]*,Process <pid>,'
537SED_CMDS.opt-debug-jobs+=	-e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
538SED_CMDS.opt-debug-jobs+=	-e 's,Command: ${.SHELL:T},Command: <shell>,'
539# The "-q" may be there or not, see jobs.c, variable shells.
540SED_CMDS.opt-debug-jobs+=	-e 's,^\(.Command: <shell>\) -q,\1,'
541SED_CMDS.opt-debug-lint+=	${STD_SED_CMDS.regex}
542SED_CMDS.opt-jobs-no-action=	${STD_SED_CMDS.hide-from-output}
543SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
544# For Compat_RunCommand, useShell == false.
545SED_CMDS.sh-dots=		-e 's,^.*\.\.\.:.*,<not found: ...>,'
546# For Compat_RunCommand, useShell == true.
547SED_CMDS.sh-dots+=		-e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
548SED_CMDS.sh-dots+=		-e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
549SED_CMDS.sh-errctl=		${STD_SED_CMDS.dj}
550SED_CMDS.sh-flags=		${STD_SED_CMDS.hide-from-output}
551SED_CMDS.shell-csh=		${STD_SED_CMDS.white-space}
552SED_CMDS.suff-main+=		${STD_SED_CMDS.dg1}
553SED_CMDS.suff-main-several+=	${STD_SED_CMDS.dg1}
554SED_CMDS.suff-transform-debug+=	${STD_SED_CMDS.dg1}
555SED_CMDS.var-op-shell+=		${STD_SED_CMDS.shell}
556SED_CMDS.var-op-shell+=		-e '/command/s,No such.*,not found,'
557SED_CMDS.var-op-shell+=		${STD_SED_CMDS.white-space}
558SED_CMDS.vardebug+=		-e 's,${.SHELL},</path/to/shell>,'
559SED_CMDS.varmod-subst-regex+=	${STD_SED_CMDS.regex}
560SED_CMDS.varname-dot-parsedir=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
561SED_CMDS.varname-dot-parsefile=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
562SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
563SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
564SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'
565SED_CMDS.varname-empty=		${.OBJDIR .PARSEDIR .PATH .SHELL:L:@v@-e '/\\$v/d'@}
566
567# Some tests need an additional round of postprocessing.
568POSTPROC.deptgt-suffixes=	awk '/^\#\*\*\* Suffixes/,/^never-stop/'
569POSTPROC.gnode-submake=		awk '/Input graph/, /^$$/'
570
571# Some tests reuse other tests, which makes them unnecessarily fragile.
572export-all.rawout: export.mk
573unexport.rawout: export.mk
574unexport-env.rawout: export.mk
575
576# End of the configuration section.
577
578# Some standard sed commands, to be used in the SED_CMDS above.
579
580# Omit details such as process IDs from the output of the -dg1 option.
581STD_SED_CMDS.dg1=	-e '/\#.* \.$$/d'
582STD_SED_CMDS.dg1+=	-e '/\.MAKE.PATH_FILEMON/d'
583STD_SED_CMDS.dg1+=	-e '/^MAKE_VERSION/d;/^\#.*\/mk/d'
584STD_SED_CMDS.dg1+=	-e 's,  ${DEFSYSPATH:U/usr/share/mk}$$,  <defsyspath>,'
585STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
586STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
587STD_SED_CMDS.dg1+=	-e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
588STD_SED_CMDS.dg1+=	-e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
589STD_SED_CMDS.dg1+=	-e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
590
591STD_SED_CMDS.dg2=	${STD_SED_CMDS.dg1}
592STD_SED_CMDS.dg2+=	-e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'
593STD_SED_CMDS.dg3=	${STD_SED_CMDS.dg2}
594
595# Omit details such as process IDs from the output of the -dj option.
596STD_SED_CMDS.dj= \
597	-e '/Process/d;/JobFinish:/d' \
598	-e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \
599	-e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \
600	-e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \
601	-e 's,^\(	Command:\) .*,\1 <shell>,'
602
603# Reduce the noise for tests running with the -n option, since there is no
604# other way to suppress the echoing of the commands.
605STD_SED_CMDS.hide-from-output= \
606	-e '/^echo hide-from-output/d' \
607	-e 's,hide-from-output ,,' \
608	-e 's,hide-from-output,,'
609
610# Normalize the output for error messages from the shell.
611#
612# $shell -c '...'
613#	NetBSD sh	...: not found
614#	NetBSD ksh	ksh: ...: not found
615#	bash 5.0.18	bash: ...: command not found
616#	bash 5.1.0	bash: line 1: ...: command not found
617#	dash		dash: 1: ...: not found
618#
619# $shell -c '< /nonexistent'
620#	NetBSD sh	sh: cannot open /nonexistent: no such file
621#	NetBSD ksh	ksh: cannot open /nonexistent: No such file or directory
622#	bash 5.0.18	bash: /nonexistent: No such file or directory
623#	bash 5.1.0	bash: line 1: /nonexistent: No such file or directory
624#	dash		dash: 1: cannot open /nonexistent: No such file
625#
626# echo '< /nonexistent' | $shell
627#	NetBSD sh	sh: cannot open /nonexistent: no such file
628#	NetBSD ksh	ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory
629#	bash 5.0.18	bash: line 1: /nonexistent: No such file or directory
630#	bash 5.1.0	bash: line 1: /nonexistent: No such file or directory
631#	dash		dash: 1: cannot open /nonexistent: No such file
632#
633STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
634STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
635STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: ,,'
636
637STD_SED_CMDS.white-space=	-e 's,   *, ,g' -e 's,  *$$,,'
638
639# The actual error messages for a failed regcomp or regexec differ between the
640# implementations.
641STD_SED_CMDS.regex= \
642	-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
643
644# End of the configuration helpers section.
645
646.-include "Makefile.inc"
647.-include "Makefile.config"
648
649UNIT_TESTS:=	${.PARSEDIR}
650.PATH: ${UNIT_TESTS}
651
652.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
653OUTFILES=	${TESTS:@test@${.CURDIR:tA}/${test}.out@}
654.else
655OUTFILES=	${TESTS:=.out}
656.endif
657
658all: ${OUTFILES}
659
660CLEANFILES=		*.rawout *.out *.status *.tmp *.core *.tmp
661CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
662CLEANFILES+=		issue* .[ab]*		# suffixes.mk
663CLEANDIRS=		dir dummy		# posix1.mk
664
665clean:
666	rm -f ${CLEANFILES}
667	rm -rf ${CLEANDIRS}
668
669TEST_MAKE?=	${.MAKE}
670TOOL_SED?=	sed
671TOOL_TR?=	tr
672TOOL_DIFF?=	diff
673DIFF_FLAGS?=	-u
674
675.if defined(.PARSEDIR)
676# ensure consistent results from sort(1)
677LC_ALL=		C
678LANG=		C
679.export LANG LC_ALL
680.endif
681
682.if ${.MAKE.MODE:Unormal:Mmeta} != ""
683# we don't need the noise
684_MKMSG_TEST= :
685.endif
686
687
688# for many tests we need a TMPDIR that will not collide
689# with other users.
690.if ${.OBJDIR} != ${.CURDIR}
691# easy
692TMPDIR:=	${.OBJDIR}/tmp
693.elif defined(TMPDIR)
694TMPDIR:=	${TMPDIR}/uid${.MAKE.UID}
695.else
696TMPDIR:=	/tmp/uid${.MAKE.UID}
697.endif
698# make sure it exists
699.if !exist(${TMPDIR})
700x!= echo; mkdir -p ${TMPDIR}
701.endif
702
703MAKE_TEST_ENV=	MALLOC_OPTIONS="JA"	# for jemalloc 100
704MAKE_TEST_ENV+=	MALLOC_CONF="junk:true"	# for jemalloc 510
705MAKE_TEST_ENV+= TMPDIR=${TMPDIR}
706
707.if ${.MAKE.OS} == "NetBSD"
708LIMIT_RESOURCES?=	ulimit -v 200000
709.endif
710LIMIT_RESOURCES?=	:
711
712# Each test is run in a sub-make, to keep the tests for interfering with
713# each other, and because they use different environment variables and
714# command line options.
715.SUFFIXES: .mk .rawout .out
716.mk.rawout:
717	@${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
718	@set -eu; \
719	${LIMIT_RESOURCES}; \
720	cd ${.OBJDIR}; \
721	env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
722	  ${TEST_MAKE} \
723	    -r -C ${.CURDIR} -f ${.IMPSRC} \
724	    ${FLAGS.${.PREFIX:T}:U-k} \
725	    > ${.TARGET}.tmp 2>&1 \
726	&& status=$$? || status=$$?; \
727	echo $$status > ${.TARGET:R}.status
728	@mv ${.TARGET}.tmp ${.TARGET}
729
730# Postprocess the test output so that the results can be compared.
731#
732# always pretend .MAKE was called 'make'
733_SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
734_SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
735_SED_CMDS+=	-e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
736_SED_CMDS+=	-e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
737# replace anything after 'stopped in' with unit-tests
738_SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
739_SED_CMDS+=	-e 's,${TMPDIR},TMPDIR,g'
740# canonicalize ${.OBJDIR} and ${.CURDIR}
741.if ${.OBJDIR} != ${.CURDIR}
742# yes this is inaccurate but none of the tests expect <objdir> anywhere
743# which we get depending on how MAKEOBJDIR is set.
744_SED_CMDS+=	-e 's,${.OBJDIR},<curdir>,g'
745.endif
746_SED_CMDS+=	-e 's,${.CURDIR},<curdir>,g'
747_SED_CMDS+=	-e 's,<curdir>/,,g'
748_SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
749# on AT&T derived systems: false exits 255 not 1
750.if ${.MAKE.OS:N*BSD} != ""
751_SED_CMDS+=	-e 's,\(Error code\) 255,\1 1,'
752.endif
753.if ${.SHELL:T} == "ksh"
754_SED_CMDS+=	-e '/^set [+-]v/d'
755.endif
756
757.rawout.out:
758	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
759	  < ${.IMPSRC} > ${.TARGET}.tmp1
760	@${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
761	@rm ${.TARGET}.tmp1
762	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
763	@mv ${.TARGET}.tmp2 ${.TARGET}
764
765.if empty(DIFF_FLAGS)
766DIFF_ECHO= echo
767.else
768DIFF_ECHO= :
769.endif
770
771# Compare all output files
772test:	${OUTFILES} .PHONY
773	@failed= ; \
774	for test in ${TESTS}; do \
775	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out && continue || \
776	  ${DIFF_ECHO} diff ${UNIT_TESTS}/$${test}.exp $${test}.out; \
777	  ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
778	  || failed="$${failed}$${failed:+ }$${test}" ; \
779	done ; \
780	if [ -n "$${failed}" ]; then \
781	  echo "Failed tests: $${failed}" ; false ; \
782	else \
783	  echo "All tests passed" ; \
784	fi
785
786accept:
787	@for test in ${TESTS}; do \
788	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
789	  || { echo "Replacing $${test}.exp" ; \
790	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
791	done
792
793.if exists(${TEST_MAKE})
794${TESTS:=.rawout}: ${TEST_MAKE}
795# in meta mode, we *know* if a target script is impacted
796# by a makefile change.
797.if ${.MAKE.MODE:Unormal:Mmeta} == ""
798${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
799.endif
800.endif
801
802.-include <obj.mk>
803