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