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