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