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