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