xref: /freebsd/contrib/bmake/unit-tests/Makefile (revision 13ec1e3155c7e9bf037b12af186351b7fa9b9450)
1# $Id: Makefile,v 1.174 2022/02/09 02:42:59 sjg Exp $
2#
3# $NetBSD: Makefile,v 1.303 2022/02/07 22:43:50 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-duplicate
95TESTS+=		dep-exclam
96TESTS+=		dep-none
97TESTS+=		dep-op-missing
98TESTS+=		dep-percent
99TESTS+=		dep-var
100TESTS+=		dep-wildcards
101TESTS+=		depsrc
102TESTS+=		depsrc-end
103TESTS+=		depsrc-exec
104TESTS+=		depsrc-ignore
105TESTS+=		depsrc-made
106TESTS+=		depsrc-make
107TESTS+=		depsrc-meta
108TESTS+=		depsrc-nometa
109TESTS+=		depsrc-nometa_cmp
110TESTS+=		depsrc-nopath
111TESTS+=		depsrc-notmain
112TESTS+=		depsrc-optional
113TESTS+=		depsrc-phony
114TESTS+=		depsrc-precious
115TESTS+=		depsrc-recursive
116TESTS+=		depsrc-silent
117TESTS+=		depsrc-use
118TESTS+=		depsrc-usebefore
119TESTS+=		depsrc-usebefore-double-colon
120TESTS+=		depsrc-wait
121TESTS+=		deptgt
122TESTS+=		deptgt-begin
123TESTS+=		deptgt-begin-fail
124TESTS+=		deptgt-begin-fail-indirect
125TESTS+=		deptgt-default
126TESTS+=		deptgt-delete_on_error
127TESTS+=		deptgt-end
128TESTS+=		deptgt-end-fail
129TESTS+=		deptgt-end-fail-all
130TESTS+=		deptgt-end-fail-indirect
131TESTS+=		deptgt-end-jobs
132TESTS+=		deptgt-error
133TESTS+=		deptgt-ignore
134TESTS+=		deptgt-interrupt
135TESTS+=		deptgt-main
136TESTS+=		deptgt-makeflags
137TESTS+=		deptgt-no_parallel
138TESTS+=		deptgt-nopath
139TESTS+=		deptgt-notparallel
140TESTS+=		deptgt-objdir
141TESTS+=		deptgt-order
142TESTS+=		deptgt-path
143TESTS+=		deptgt-path-suffix
144TESTS+=		deptgt-phony
145TESTS+=		deptgt-precious
146TESTS+=		deptgt-shell
147TESTS+=		deptgt-silent
148TESTS+=		deptgt-stale
149TESTS+=		deptgt-suffixes
150TESTS+=		dir
151TESTS+=		dir-expand-path
152TESTS+=		directive
153TESTS+=		directive-dinclude
154TESTS+=		directive-elif
155TESTS+=		directive-elifdef
156TESTS+=		directive-elifmake
157TESTS+=		directive-elifndef
158TESTS+=		directive-elifnmake
159TESTS+=		directive-else
160TESTS+=		directive-endfor
161TESTS+=		directive-endif
162TESTS+=		directive-error
163TESTS+=		directive-export
164TESTS+=		directive-export-env
165TESTS+=		directive-export-impl
166TESTS+=		directive-export-gmake
167TESTS+=		directive-export-literal
168TESTS+=		directive-for
169TESTS+=		directive-for-errors
170TESTS+=		directive-for-escape
171TESTS+=		directive-for-generating-endif
172TESTS+=		directive-for-if
173TESTS+=		directive-for-lines
174TESTS+=		directive-for-null
175TESTS+=		directive-hyphen-include
176TESTS+=		directive-if
177TESTS+=		directive-if-nested
178TESTS+=		directive-ifdef
179TESTS+=		directive-ifmake
180TESTS+=		directive-ifndef
181TESTS+=		directive-ifnmake
182TESTS+=		directive-include
183TESTS+=		directive-include-fatal
184TESTS+=		directive-info
185TESTS+=		directive-misspellings
186TESTS+=		directive-sinclude
187TESTS+=		directive-undef
188TESTS+=		directive-unexport
189TESTS+=		directive-unexport-env
190TESTS+=		directive-warning
191TESTS+=		dollar
192TESTS+=		doterror
193TESTS+=		dotwait
194TESTS+=		error
195TESTS+=		# escape	# broken by reverting POSIX changes
196TESTS+=		export
197TESTS+=		export-all
198TESTS+=		export-env
199TESTS+=		export-variants
200TESTS+=		forloop
201TESTS+=		forsubst
202TESTS+=		gnode-submake
203TESTS+=		hanoi-include
204TESTS+=		impsrc
205TESTS+=		include-main
206TESTS+=		job-flags
207#TESTS+=		job-output-long-lines
208TESTS+=		job-output-null
209TESTS+=		jobs-empty-commands
210TESTS+=		jobs-empty-commands-error
211TESTS+=		jobs-error-indirect
212TESTS+=		jobs-error-nested
213TESTS+=		jobs-error-nested-make
214TESTS+=		lint
215TESTS+=		make-exported
216TESTS+=		meta-cmd-cmp
217TESTS+=		moderrs
218TESTS+=		modmatch
219TESTS+=		modmisc
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-version
276TESTS+=		opt-warnings-as-errors
277TESTS+=		opt-where-am-i
278TESTS+=		opt-x-reduce-exported
279TESTS+=		order
280TESTS+=		parse
281TESTS+=		parse-var
282TESTS+=		phony-end
283TESTS+=		posix
284TESTS+=		# posix1	# broken by reverting POSIX changes
285TESTS+=		recursive
286TESTS+=		sh
287TESTS+=		sh-dots
288TESTS+=		sh-errctl
289TESTS+=		sh-flags
290TESTS+=		sh-jobs
291TESTS+=		sh-jobs-error
292TESTS+=		sh-leading-at
293TESTS+=		sh-leading-hyphen
294TESTS+=		sh-leading-plus
295TESTS+=		sh-meta-chars
296TESTS+=		sh-multi-line
297TESTS+=		sh-single-line
298TESTS+=		shell-csh
299TESTS+=		shell-custom
300.if exists(/bin/ksh)
301TESTS+=		shell-ksh
302.endif
303TESTS+=		shell-sh
304TESTS+=		suff-add-later
305TESTS+=		suff-clear-regular
306TESTS+=		suff-clear-single
307TESTS+=		suff-incomplete
308TESTS+=		suff-lookup
309TESTS+=		suff-main
310TESTS+=		suff-main-several
311TESTS+=		suff-phony
312TESTS+=		suff-rebuild
313TESTS+=		suff-self
314TESTS+=		suff-transform-debug
315TESTS+=		suff-transform-endless
316TESTS+=		suff-transform-expand
317TESTS+=		suff-transform-select
318TESTS+=		suff-use
319TESTS+=		sunshcmd
320TESTS+=		ternary
321TESTS+=		unexport
322TESTS+=		unexport-env
323TESTS+=		use-inference
324TESTS+=		var-scope
325TESTS+=		var-scope-cmdline
326TESTS+=		var-scope-env
327TESTS+=		var-scope-global
328TESTS+=		var-scope-local
329TESTS+=		var-scope-local-legacy
330TESTS+=		var-eval-short
331TESTS+=		var-op
332TESTS+=		var-op-append
333TESTS+=		var-op-assign
334TESTS+=		var-op-default
335TESTS+=		var-op-expand
336TESTS+=		var-op-shell
337TESTS+=		var-op-sunsh
338TESTS+=		var-recursive
339TESTS+=		varcmd
340TESTS+=		vardebug
341TESTS+=		varfind
342TESTS+=		varmisc
343TESTS+=		varmod
344TESTS+=		varmod-assign
345TESTS+=		varmod-assign-shell
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-delete
359TESTS+=		varmod-loop-varname
360TESTS+=		varmod-match
361TESTS+=		varmod-match-escape
362TESTS+=		varmod-no-match
363TESTS+=		varmod-order
364TESTS+=		varmod-order-numeric
365TESTS+=		varmod-order-reverse
366TESTS+=		varmod-order-shuffle
367TESTS+=		varmod-order-string
368TESTS+=		varmod-path
369TESTS+=		varmod-quote
370TESTS+=		varmod-quote-dollar
371TESTS+=		varmod-range
372TESTS+=		varmod-remember
373TESTS+=		varmod-root
374TESTS+=		varmod-select-words
375TESTS+=		varmod-shell
376TESTS+=		varmod-subst
377TESTS+=		varmod-subst-regex
378TESTS+=		varmod-sun-shell
379TESTS+=		varmod-sysv
380TESTS+=		varmod-tail
381TESTS+=		varmod-to-abs
382TESTS+=		varmod-to-lower
383TESTS+=		varmod-to-many-words
384TESTS+=		varmod-to-one-word
385TESTS+=		varmod-to-separator
386TESTS+=		varmod-to-upper
387TESTS+=		varmod-undefined
388TESTS+=		varmod-unique
389TESTS+=		varname
390TESTS+=		varname-dollar
391TESTS+=		varname-dot-alltargets
392TESTS+=		varname-dot-curdir
393TESTS+=		varname-dot-includes
394TESTS+=		varname-dot-includedfromdir
395TESTS+=		varname-dot-includedfromfile
396TESTS+=		varname-dot-libs
397TESTS+=		varname-dot-make-dependfile
398TESTS+=		varname-dot-make-expand_variables
399TESTS+=		varname-dot-make-exported
400TESTS+=		varname-dot-make-jobs
401TESTS+=		varname-dot-make-jobs-prefix
402TESTS+=		varname-dot-make-level
403TESTS+=		varname-dot-make-makefile_preference
404TESTS+=		varname-dot-make-makefiles
405TESTS+=		varname-dot-make-meta-bailiwick
406TESTS+=		varname-dot-make-meta-created
407TESTS+=		varname-dot-make-meta-files
408TESTS+=		varname-dot-make-meta-ignore_filter
409TESTS+=		varname-dot-make-meta-ignore_paths
410TESTS+=		varname-dot-make-meta-ignore_patterns
411TESTS+=		varname-dot-make-meta-prefix
412TESTS+=		varname-dot-make-mode
413TESTS+=		varname-dot-make-path_filemon
414TESTS+=		varname-dot-make-pid
415TESTS+=		varname-dot-make-ppid
416TESTS+=		varname-dot-make-save_dollars
417TESTS+=		varname-dot-makeflags
418TESTS+=		varname-dot-makeoverrides
419TESTS+=		varname-dot-newline
420TESTS+=		varname-dot-objdir
421TESTS+=		varname-dot-parsedir
422TESTS+=		varname-dot-parsefile
423TESTS+=		varname-dot-path
424TESTS+=		varname-dot-shell
425TESTS+=		varname-dot-suffixes
426TESTS+=		varname-dot-targets
427TESTS+=		varname-empty
428TESTS+=		varname-make
429TESTS+=		varname-make_print_var_on_error
430TESTS+=		varname-make_print_var_on_error-jobs
431TESTS+=		varname-makefile
432TESTS+=		varname-makeflags
433TESTS+=		varname-pwd
434TESTS+=		varname-vpath
435TESTS+=		varparse-dynamic
436TESTS+=		varparse-errors
437TESTS+=		varparse-mod
438TESTS+=		varparse-undef-partial
439TESTS+=		varquote
440
441# for now at least
442.if ${.SHELL:T} == "ksh"
443BROKEN_TESTS+= sh-flags
444.endif
445.if ${.MAKE.OS:NDarwin} == ""
446BROKEN_TESTS+= shell-ksh
447.endif
448.if ${.MAKE.OS} == "Linux" && ${.SHELL:tA:T} != "bash"
449.if exists(/etc/os-release)
450distro!= . /etc/os-release && echo $$NAME
451.endif
452# dash fails -x output
453# .SHELL is not bash so may be dash
454# if distro is Ubuntu or we cannot tell, assume the worst
455.if ${distro:U:NUbuntu} == ""
456BROKEN_TESTS+= opt-debug-x-trace
457.endif
458.endif
459.if ${.MAKE.OS} == "SCO_SV"
460BROKEN_TESTS+= \
461	opt-debug-graph[23] \
462	varmod-localtime \
463	varmod-to-separator \
464
465.if ${.SHELL:T} == "bash"
466BROKEN_TESTS+= job-output-null
467.else
468BROKEN_TESTS+= \
469	cmd-interrupt \
470	job-flags \
471
472.endif
473.endif
474
475# Some tests just do not work on some platforms or environments
476# so allow for some filtering.
477.if !empty(BROKEN_TESTS)
478.warning Skipping broken tests: ${BROKEN_TESTS:O:u}
479TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}}
480.endif
481
482# Ideas for more tests:
483#	char-0020-space.mk
484#	char-005C-backslash.mk
485#	escape-cond-str.mk
486#	escape-cond-func-arg.mk
487#	escape-varmod.mk
488#	escape-varmod-define.mk
489#	escape-varmod-match.mk
490#	escape-varname.mk
491#	escape-varassign-varname.mk
492#	escape-varassign-varname-cmdline.mk
493#	escape-varassign-value.mk
494#	escape-varassign-value-cmdline.mk
495#	escape-dependency-source.mk
496#	escape-dependency-target.mk
497#	escape-for-varname.mk
498#	escape-for-item.mk
499#	posix-*.mk (see posix.mk and posix1.mk)
500
501# Additional environment variables for some of the tests.
502# The base environment is -i PATH="$PATH".
503ENV.depsrc-optional+=   TZ=UTC
504ENV.envfirst=		FROM_ENV=value-from-env
505ENV.varmisc=		FROM_ENV=env
506ENV.varmisc+=		FROM_ENV_BEFORE=env
507ENV.varmisc+=		FROM_ENV_AFTER=env
508ENV.varmod-localtime+=	TZ=${UTC_1:UEurope/Berlin}
509ENV.varname-vpath+=	VPATH=varname-vpath.dir:varname-vpath.dir2
510
511# Override make flags for some of the tests; default is -k.
512# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
513# settings FLAGS.test=-dv here, since that is closer to the test code.
514FLAGS.cond-func-make=		via-cmdline
515FLAGS.doterror=			# none, especially not -k
516FLAGS.jobs-error-indirect=	# none, especially not -k
517FLAGS.jobs-error-nested=	# none, especially not -k
518FLAGS.jobs-error-nested-make=	# none, especially not -k
519FLAGS.varname-empty=		-dv '$${:U}=cmdline-u' '=cmdline-plain'
520
521# Some tests need extra postprocessing.
522SED_CMDS.dir=		${:D remove output from -DCLEANUP mode }
523SED_CMDS.dir+=		-e '/^OpenDirs_Done:/d'
524SED_CMDS.dir+=		-e '/^CachedDir /d'
525SED_CMDS.export=	-e '/^[^=_A-Za-z0-9]*=/d'
526SED_CMDS.export-all=	${SED_CMDS.export}
527SED_CMDS.export-env=	${SED_CMDS.export}
528SED_CMDS.cmdline=	-e 's,uid${.MAKE.UID}/,,'
529SED_CMDS.job-output-long-lines= \
530	${:D Job separators on their own line are ok. } \
531	-e '/^--- job-[ab] ---$$/d' \
532	${:D Plain output lines are ok as well. } \
533	${:D They may come in multiples of 1024 or as 10000. } \
534	-e '/^aa*$$/d' \
535	-e '/^bb*$$/d' \
536	${:D The following lines should rather not occur since the job } \
537	${:D marker should always be at the beginning of the line. } \
538	-e '/^aa*--- job-b ---$$/d' \
539	-e '/^bb*--- job-a ---$$/d'
540SED_CMDS.opt-chdir=		-e 's,\(nonexistent\).[1-9][0-9]*,\1,' \
541	-e '/name/s,file,File,' \
542	-e 's,no such,No such,' \
543	-e 's,Filename,File name,'
544SED_CMDS.opt-debug-graph1=	${STD_SED_CMDS.dg1}
545SED_CMDS.opt-debug-graph2=	${STD_SED_CMDS.dg2}
546SED_CMDS.opt-debug-graph3=	${STD_SED_CMDS.dg3}
547SED_CMDS.opt-debug-hash=	-e 's,\(numEntries\)=[1-9][0-9],\1=<entries>,'
548SED_CMDS.opt-debug-jobs=	-e 's,([0-9][0-9]*),(<pid>),'
549SED_CMDS.opt-debug-jobs+=	-e 's,pid [0-9][0-9]*,pid <pid>,'
550SED_CMDS.opt-debug-jobs+=	-e 's,Process [0-9][0-9]*,Process <pid>,'
551SED_CMDS.opt-debug-jobs+=	-e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
552SED_CMDS.opt-debug-jobs+=	-e 's,Command: ${.SHELL:T},Command: <shell>,'
553# The "-q" may be there or not, see jobs.c, variable shells.
554SED_CMDS.opt-debug-jobs+=	-e 's,^\(.Command: <shell>\) -q,\1,'
555SED_CMDS.opt-debug-lint+=	${STD_SED_CMDS.regex}
556SED_CMDS.opt-jobs-no-action=	${STD_SED_CMDS.hide-from-output}
557SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
558SED_CMDS.opt-where-am-i=	-e '/usr.obj/d'
559# For Compat_RunCommand, useShell == false.
560SED_CMDS.sh-dots=		-e 's,^.*\.\.\.:.*,<not found: ...>,'
561# For Compat_RunCommand, useShell == true.
562SED_CMDS.sh-dots+=		-e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
563SED_CMDS.sh-dots+=		-e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
564SED_CMDS.sh-errctl=		${STD_SED_CMDS.dj}
565SED_CMDS.sh-flags=		${STD_SED_CMDS.hide-from-output}
566SED_CMDS.shell-csh=		${STD_SED_CMDS.white-space}
567SED_CMDS.suff-main+=		${STD_SED_CMDS.dg1}
568SED_CMDS.suff-main-several+=	${STD_SED_CMDS.dg1}
569SED_CMDS.suff-transform-debug+=	${STD_SED_CMDS.dg1}
570SED_CMDS.var-op-shell+=		${STD_SED_CMDS.shell}
571SED_CMDS.var-op-shell+=		-e '/command/s,No such.*,not found,'
572SED_CMDS.var-op-shell+=		${STD_SED_CMDS.white-space}
573SED_CMDS.vardebug+=		-e 's,${.SHELL},</path/to/shell>,'
574SED_CMDS.varmod-subst-regex+=	${STD_SED_CMDS.regex}
575SED_CMDS.varname-dot-parsedir=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
576SED_CMDS.varname-dot-parsefile=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
577SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
578SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
579SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'
580SED_CMDS.varname-empty=		${.OBJDIR .PARSEDIR .PATH .SHELL:L:@v@-e '/\\$v/d'@}
581
582# Some tests need an additional round of postprocessing.
583POSTPROC.deptgt-suffixes=	awk '/^\#\*\*\* Suffixes/,/^never-stop/'
584POSTPROC.gnode-submake=		awk '/Input graph/, /^$$/'
585
586# Some tests reuse other tests, which makes them unnecessarily fragile.
587export-all.rawout: export.mk
588unexport.rawout: export.mk
589unexport-env.rawout: export.mk
590
591# End of the configuration section.
592
593# Some standard sed commands, to be used in the SED_CMDS above.
594
595# Omit details such as process IDs from the output of the -dg1 option.
596STD_SED_CMDS.dg1=	-e '/\#.* \.$$/d'
597STD_SED_CMDS.dg1+=	-e '/\.MAKE.PATH_FILEMON/d'
598STD_SED_CMDS.dg1+=	-e '/^MAKE_VERSION/d;/^\#.*\/mk/d'
599STD_SED_CMDS.dg1+=	-e 's,  ${DEFSYSPATH:U/usr/share/mk}$$,  <defsyspath>,'
600STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
601STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
602STD_SED_CMDS.dg1+=	-e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
603STD_SED_CMDS.dg1+=	-e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
604STD_SED_CMDS.dg1+=	-e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
605
606STD_SED_CMDS.dg2=	${STD_SED_CMDS.dg1}
607STD_SED_CMDS.dg2+=	-e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'
608STD_SED_CMDS.dg3=	${STD_SED_CMDS.dg2}
609
610# Omit details such as process IDs from the output of the -dj option.
611STD_SED_CMDS.dj= \
612	-e '/Process/d;/JobFinish:/d' \
613	-e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \
614	-e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \
615	-e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \
616	-e 's,^\(	Command:\) .*,\1 <shell>,'
617
618# Reduce the noise for tests running with the -n option, since there is no
619# other way to suppress the echoing of the commands.
620STD_SED_CMDS.hide-from-output= \
621	-e '/^echo hide-from-output/d' \
622	-e 's,hide-from-output ,,' \
623	-e 's,hide-from-output,,'
624
625# Normalize the output for error messages from the shell.
626#
627# $shell -c '...'
628#	NetBSD sh	...: not found
629#	NetBSD ksh	ksh: ...: not found
630#	bash 5.0.18	bash: ...: command not found
631#	bash 5.1.0	bash: line 1: ...: command not found
632#	dash		dash: 1: ...: not found
633#
634# $shell -c '< /nonexistent'
635#	NetBSD sh	sh: cannot open /nonexistent: no such file
636#	NetBSD ksh	ksh: cannot open /nonexistent: No such file or directory
637#	bash 5.0.18	bash: /nonexistent: No such file or directory
638#	bash 5.1.0	bash: line 1: /nonexistent: No such file or directory
639#	dash		dash: 1: cannot open /nonexistent: No such file
640#
641# echo '< /nonexistent' | $shell
642#	NetBSD sh	sh: cannot open /nonexistent: no such file
643#	NetBSD ksh	ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory
644#	bash 5.0.18	bash: line 1: /nonexistent: No such file or directory
645#	bash 5.1.0	bash: line 1: /nonexistent: No such file or directory
646#	dash		dash: 1: cannot open /nonexistent: No such file
647#
648STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
649STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
650STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: ,,'
651
652STD_SED_CMDS.white-space=	-e 's,   *, ,g' -e 's,  *$$,,'
653
654# The actual error messages for a failed regcomp or regexec differ between the
655# implementations.
656STD_SED_CMDS.regex= \
657	-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
658
659# End of the configuration helpers section.
660
661.-include "Makefile.inc"
662.-include "Makefile.config"
663
664UNIT_TESTS:=	${.PARSEDIR}
665.PATH: ${UNIT_TESTS}
666
667.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
668OUTFILES=	${TESTS:@test@${.CURDIR:tA}/${test}.out@}
669.else
670OUTFILES=	${TESTS:=.out}
671.endif
672
673all: ${OUTFILES}
674
675CLEANFILES=		*.rawout *.out *.status *.tmp *.core *.tmp
676CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
677CLEANFILES+=		issue* .[ab]*		# suffixes.mk
678CLEANDIRS=		dir dummy		# posix1.mk
679
680clean:
681	rm -f ${CLEANFILES}
682	rm -rf ${CLEANDIRS}
683
684TEST_MAKE?=	${.MAKE}
685TOOL_SED?=	sed
686TOOL_TR?=	tr
687TOOL_DIFF?=	diff
688DIFF_FLAGS?=	-u
689
690.if defined(.PARSEDIR)
691# ensure consistent results from sort(1)
692LC_ALL=		C
693LANG=		C
694.export LANG LC_ALL
695.endif
696
697.if ${.MAKE.MODE:Unormal:Mmeta} != ""
698# we don't need the noise
699_MKMSG_TEST= :
700.endif
701
702
703# for many tests we need a TMPDIR that will not collide
704# with other users.
705.if ${.OBJDIR} != ${.CURDIR}
706# easy
707TMPDIR:=	${.OBJDIR}/tmp
708.elif defined(TMPDIR)
709TMPDIR:=	${TMPDIR}/uid${.MAKE.UID}
710.else
711TMPDIR:=	/tmp/uid${.MAKE.UID}
712.endif
713# make sure it exists
714.if !exist(${TMPDIR})
715x!= echo; mkdir -p ${TMPDIR}
716.endif
717
718MAKE_TEST_ENV=	MALLOC_OPTIONS="JA"	# for jemalloc 100
719MAKE_TEST_ENV+=	MALLOC_CONF="junk:true"	# for jemalloc 510
720MAKE_TEST_ENV+= TMPDIR=${TMPDIR}
721
722.if ${.MAKE.OS} == "NetBSD"
723LIMIT_RESOURCES?=	ulimit -v 200000
724.endif
725LIMIT_RESOURCES?=	:
726
727# Each test is run in a sub-make, to keep the tests for interfering with
728# each other, and because they use different environment variables and
729# command line options.
730.SUFFIXES: .mk .rawout .out
731.mk.rawout:
732	@${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
733	@set -eu; \
734	${LIMIT_RESOURCES}; \
735	cd ${.OBJDIR}; \
736	env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
737	  ${TEST_MAKE} \
738	    -r -C ${.CURDIR} -f ${.IMPSRC} \
739	    ${FLAGS.${.PREFIX:T}:U-k} \
740	    > ${.TARGET}.tmp 2>&1 \
741	&& status=$$? || status=$$?; \
742	echo $$status > ${.TARGET:R}.status
743	@mv ${.TARGET}.tmp ${.TARGET}
744
745# Postprocess the test output so that the results can be compared.
746#
747# always pretend .MAKE was called 'make'
748_SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
749_SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
750_SED_CMDS+=	-e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
751_SED_CMDS+=	-e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
752# replace anything after 'stopped in' with unit-tests
753_SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
754# Allow the test files to be placed anywhere.
755_SED_CMDS+=	-e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
756_SED_CMDS+=	-e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
757_SED_CMDS+=	-e 's,${TMPDIR},TMPDIR,g'
758# canonicalize ${.OBJDIR} and ${.CURDIR}
759.if ${.OBJDIR} != ${.CURDIR}
760# yes this is inaccurate but none of the tests expect <objdir> anywhere
761# which we get depending on how MAKEOBJDIR is set.
762_SED_CMDS+=	-e 's,${.OBJDIR},<curdir>,g'
763.endif
764_SED_CMDS+=	-e 's,${.CURDIR},<curdir>,g'
765_SED_CMDS+=	-e 's,<curdir>/,,g'
766_SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
767# on AT&T derived systems: false exits 255 not 1
768.if ${.MAKE.OS:N*BSD} != ""
769_SED_CMDS+=	-e 's,\(Error code\) 255,\1 1,'
770.endif
771.if ${.SHELL:T} == "ksh"
772_SED_CMDS+=	-e '/^set [+-]v/d'
773.endif
774
775.rawout.out:
776	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
777	  < ${.IMPSRC} > ${.TARGET}.tmp1
778	@${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
779	@rm ${.TARGET}.tmp1
780	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
781	@mv ${.TARGET}.tmp2 ${.TARGET}
782
783.if empty(DIFF_FLAGS)
784DIFF_ECHO= echo
785.else
786DIFF_ECHO= :
787.endif
788
789# Compare all output files
790test:	${OUTFILES} .PHONY
791	@failed= ; \
792	for test in ${TESTS}; do \
793	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out && continue || \
794	  ${DIFF_ECHO} diff ${UNIT_TESTS}/$${test}.exp $${test}.out; \
795	  ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
796	  || failed="$${failed}$${failed:+ }$${test}" ; \
797	done ; \
798	if [ -n "$${failed}" ]; then \
799	  echo "Failed tests: $${failed}" ; false ; \
800	else \
801	  echo "All tests passed" ; \
802	fi
803
804accept:
805	@for test in ${TESTS}; do \
806	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
807	  || { echo "Replacing $${test}.exp" ; \
808	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
809	done
810
811.if exists(${TEST_MAKE})
812${TESTS:=.rawout}: ${TEST_MAKE}
813# in meta mode, we *know* if a target script is impacted
814# by a makefile change.
815.if ${.MAKE.MODE:Unormal:Mmeta} == ""
816${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
817.endif
818.endif
819
820.-include <obj.mk>
821