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