xref: /freebsd/contrib/bmake/unit-tests/Makefile (revision f81cdf24ba5436367377f7c8e8f51f6df2a75ca7)
1# $Id: Makefile,v 1.210 2024/01/08 18:28:08 sjg Exp $
2#
3# $NetBSD: Makefile,v 1.342 2024/01/07 02:07:44 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
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-upper
402TESTS+=		varmod-undefined
403TESTS+=		varmod-unique
404TESTS+=		varname
405TESTS+=		varname-dollar
406TESTS+=		varname-dot-alltargets
407TESTS+=		varname-dot-curdir
408TESTS+=		varname-dot-includes
409TESTS+=		varname-dot-includedfromdir
410TESTS+=		varname-dot-includedfromfile
411TESTS+=		varname-dot-libs
412TESTS+=		varname-dot-make-dependfile
413TESTS+=		varname-dot-make-expand_variables
414TESTS+=		varname-dot-make-exported
415TESTS+=		varname-dot-make-jobs
416TESTS+=		varname-dot-make-jobs-prefix
417TESTS+=		varname-dot-make-level
418TESTS+=		varname-dot-make-makefile_preference
419TESTS+=		varname-dot-make-makefiles
420TESTS+=		varname-dot-make-meta-bailiwick
421TESTS+=		varname-dot-make-meta-created
422TESTS+=		varname-dot-make-meta-files
423.if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != ""
424# these tests will not work if TMPDIR is or is a subdir of
425# /tmp or /var/tmp
426.if ${.MAKE.PATH_FILEMON:N/dev/*} != "" || exists(${.MAKE.PATH_FILEMON})
427TESTS+=		varname-dot-make-meta-ignore_filter
428TESTS+=		varname-dot-make-meta-ignore_paths
429TESTS+=		varname-dot-make-meta-ignore_patterns
430TESTS+=		varname-dot-make-path_filemon
431.else
432.warning Skipping tests that require ${.MAKE.PATH_FILEMON}
433.endif
434.endif
435TESTS+=		varname-dot-make-meta-prefix
436TESTS+=		varname-dot-make-mode
437TESTS+=		varname-dot-make-pid
438TESTS+=		varname-dot-make-ppid
439TESTS+=		varname-dot-make-save_dollars
440TESTS+=		varname-dot-makeflags
441TESTS+=		varname-dot-makeoverrides
442TESTS+=		varname-dot-newline
443TESTS+=		varname-dot-objdir
444TESTS+=		varname-dot-parsedir
445TESTS+=		varname-dot-parsefile
446TESTS+=		varname-dot-path
447TESTS+=		varname-dot-shell
448TESTS+=		varname-dot-suffixes
449TESTS+=		varname-dot-targets
450TESTS+=		varname-empty
451TESTS+=		varname-make
452TESTS+=		varname-make_print_var_on_error
453TESTS+=		varname-make_print_var_on_error-jobs
454TESTS+=		varname-makefile
455TESTS+=		varname-makeflags
456TESTS+=		varname-pwd
457TESTS+=		varname-vpath
458TESTS+=		varparse-dynamic
459TESTS+=		varparse-errors
460TESTS+=		varparse-mod
461TESTS+=		varparse-undef-partial
462
463# some shells have quirks
464_shell := ${.SHELL:tA:T}
465.if ${_shell} == "dash"
466# dash fails -x output
467BROKEN_TESTS+= opt-debug-x-trace
468.elif ${_shell} == "ksh"
469BROKEN_TESTS+= sh-flags
470.endif
471
472.if ${UTC_1:Uno} == ""
473# this will not work if UTC_1 is set empty
474BROKEN_TESTS+= varmod-localtime
475.endif
476
477.if ${.MAKE.OS:NDarwin} == ""
478BROKEN_TESTS+= shell-ksh
479.endif
480
481.if ${.MAKE.OS:MIRIX*} != ""
482BROKEN_TESTS+= \
483	cmd-interrupt \
484	deptgt-interrupt \
485	job-output-null \
486	opt-chdir \
487	opt-debug-x-trace \
488	sh-leading-hyphen \
489
490.endif
491
492.if ${.MAKE.OS} == "SCO_SV"
493BROKEN_TESTS+= \
494	opt-debug-graph[23] \
495	varmod-localtime \
496	varmod-to-separator \
497
498.if ${_shell} == "bash"
499BROKEN_TESTS+= job-output-null
500.else
501BROKEN_TESTS+= \
502	cmd-interrupt \
503	job-flags \
504
505.endif
506.endif
507
508# Some tests just do not work on some platforms or environments
509# so allow for some filtering.
510.if !empty(BROKEN_TESTS)
511.warning Skipping broken tests: ${BROKEN_TESTS:O:u}
512TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}}
513.endif
514
515# Ideas for more tests:
516#	char-0020-space.mk
517#	char-005C-backslash.mk
518#	escape-cond-str.mk
519#	escape-cond-func-arg.mk
520#	escape-varmod.mk
521#	escape-varmod-define.mk
522#	escape-varmod-match.mk
523#	escape-varname.mk
524#	escape-varassign-varname.mk
525#	escape-varassign-varname-cmdline.mk
526#	escape-varassign-value.mk
527#	escape-varassign-value-cmdline.mk
528#	escape-dependency-source.mk
529#	escape-dependency-target.mk
530#	escape-for-varname.mk
531#	escape-for-item.mk
532#	posix-*.mk (see posix.mk and posix1.mk)
533
534# Additional environment variables for some of the tests.
535# The base environment is -i PATH="$PATH".
536ENV.depsrc-optional+=   TZ=UTC
537ENV.deptgt-phony+=	MAKESYSPATH=.
538ENV.directive-undef=	ENV_VAR=env-value
539ENV.opt-env=		FROM_ENV=value-from-env
540ENV.opt-m-include-dir=	${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}}
541ENV.varmisc=		FROM_ENV=env
542ENV.varmisc+=		FROM_ENV_BEFORE=env
543ENV.varmisc+=		FROM_ENV_AFTER=env
544ENV.varmod-localtime+=	TZ=${UTC_1:UEurope/Berlin}
545ENV.varname-vpath+=	VPATH=varname-vpath.dir:varname-vpath.dir2
546
547# Override make flags for some of the tests; default is -k.
548# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
549# settings FLAGS.test=-dv here, since that is closer to the test code.
550FLAGS.cond-func-make=		via-cmdline
551FLAGS.doterror=			# none, especially not -k
552FLAGS.jobs-error-indirect=	# none, especially not -k
553FLAGS.jobs-error-nested=	# none, especially not -k
554FLAGS.jobs-error-nested-make=	# none, especially not -k
555FLAGS.varname-empty=		-dv '$${:U}=cmdline-u' '=cmdline-plain'
556
557# Some tests need extra postprocessing.
558SED_CMDS.deptgt-phony=	${STD_SED_CMDS.dd}
559SED_CMDS.dir=		${STD_SED_CMDS.dd}
560SED_CMDS.directive-include-guard= \
561	-e '/\.MAKEFLAGS/d' \
562	-e '/^Parsing line/d' \
563	-e '/^SetFilenameVars:/d' \
564	-e '/^ParseDependency/d' \
565	-e '/^ParseEOF:/d'
566SED_CMDS.export=	-e '/^[^=_A-Za-z0-9]*=/d'
567SED_CMDS.export-all=	${SED_CMDS.export}
568SED_CMDS.export-env=	${SED_CMDS.export}
569SED_CMDS.cmdline=	-e 's,uid${.MAKE.UID}/,,'
570SED_CMDS.job-output-long-lines= \
571	${:D Job separators on their own line are ok. } \
572	-e '/^--- job-[ab] ---$$/d' \
573	${:D Plain output lines are ok as well. } \
574	${:D They may come in multiples of 1024 or as 10000. } \
575	-e '/^aa*$$/d' \
576	-e '/^bb*$$/d' \
577	${:D The following lines should rather not occur since the job } \
578	${:D marker should always be at the beginning of the line. } \
579	-e '/^aa*--- job-b ---$$/d' \
580	-e '/^bb*--- job-a ---$$/d'
581SED_CMDS.opt-chdir=		-e 's,\(nonexistent\).[1-9][0-9]*,\1,' \
582	-e '/name/s,file,File,' \
583	-e 's,no such,No such,' \
584	-e 's,Filename,File name,'
585
586# meta line numbers can vary based on filemon implementation
587SED_CMDS.meta-ignore= -e 's,\(\.meta:\) [1-9][0-9]*:,\1 <line>:,'
588SED_CMDS.opt-debug-graph1=	${STD_SED_CMDS.dg1}
589SED_CMDS.opt-debug-graph2=	${STD_SED_CMDS.dg2}
590SED_CMDS.opt-debug-graph3=	${STD_SED_CMDS.dg3}
591SED_CMDS.opt-debug-hash=	-e 's,\(numEntries\)=[1-9][0-9],\1=<entries>,'
592SED_CMDS.opt-debug-jobs=	-e 's,([0-9][0-9]*),(<pid>),'
593SED_CMDS.opt-debug-jobs+=	-e 's,pid [0-9][0-9]*,pid <pid>,'
594SED_CMDS.opt-debug-jobs+=	-e 's,Process [0-9][0-9]*,Process <pid>,'
595SED_CMDS.opt-debug-jobs+=	-e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
596SED_CMDS.opt-debug-jobs+=	-e 's,Command: ${.SHELL:T},Command: <shell>,'
597# The "-q" may be there or not, see jobs.c, variable shells.
598SED_CMDS.opt-debug-jobs+=	-e 's,^\(.Command: <shell>\) -q,\1,'
599SED_CMDS.opt-debug-lint+=	${STD_SED_CMDS.regex}
600SED_CMDS.opt-jobs-no-action=	${STD_SED_CMDS.hide-from-output}
601SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
602SED_CMDS.opt-where-am-i=	-e '/usr.obj/d'
603# For Compat_RunCommand, useShell == false.
604SED_CMDS.sh-dots=		-e 's,^.*\.\.\.:.*,<not found: ...>,'
605# For Compat_RunCommand, useShell == true.
606SED_CMDS.sh-dots+=		-e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
607SED_CMDS.sh-dots+=		-e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
608SED_CMDS.sh-errctl=		${STD_SED_CMDS.dj}
609SED_CMDS.sh-flags=		${STD_SED_CMDS.hide-from-output}
610SED_CMDS.shell-csh=		${STD_SED_CMDS.white-space}
611SED_CMDS.sh-leading-hyphen=	${STD_SED_CMDS.shell}
612SED_CMDS.suff-main+=		${STD_SED_CMDS.dg1}
613SED_CMDS.suff-main-several+=	${STD_SED_CMDS.dg1}
614SED_CMDS.suff-transform-debug+=	${STD_SED_CMDS.dg1}
615SED_CMDS.var-op-shell+=		${STD_SED_CMDS.shell}
616SED_CMDS.var-op-shell+=		-e '/command/s,No such.*,not found,'
617SED_CMDS.var-op-shell+=		${STD_SED_CMDS.white-space}
618SED_CMDS.vardebug+=		-e 's,${.SHELL},</path/to/shell>,'
619SED_CMDS.varmod-mtime+=		-e "s,': .*,': <ENOENT>,"
620SED_CMDS.varmod-subst-regex+=	${STD_SED_CMDS.regex}
621SED_CMDS.varparse-errors+=	${STD_SED_CMDS.timestamp}
622SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore}
623SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore}
624SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore}
625SED_CMDS.varname-dot-parsedir=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
626SED_CMDS.varname-dot-parsefile=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
627SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
628SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
629SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'
630SED_CMDS.varname-empty=		${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@}
631
632# Some tests need an additional round of postprocessing.
633POSTPROC.depsrc-wait=		sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,'
634POSTPROC.deptgt-suffixes=	awk '/^\#\*\*\* Suffixes/,/^never-stop/'
635POSTPROC.gnode-submake=		awk '/Input graph/, /^$$/'
636POSTPROC.varname-dot-make-mode=	sed 's,^\(: Making [abc]\)[123]$$,\1,'
637
638# Some tests reuse other tests, which makes them unnecessarily fragile.
639export-all.rawout: export.mk
640unexport.rawout: export.mk
641unexport-env.rawout: export.mk
642
643# End of the configuration section.
644
645# Some standard sed commands, to be used in the SED_CMDS above.
646
647# In tests that use the debugging option -dd, ignore debugging output that is
648# only logged in -DCLEANUP mode.
649STD_SED_CMDS.dd=		-e '/^OpenDirs_Done:/d'
650STD_SED_CMDS.dd+=		-e '/^CachedDir /d'
651
652# Omit details such as process IDs from the output of the -dg1 option.
653STD_SED_CMDS.dg1=	-e '/\#.* \.$$/d'
654STD_SED_CMDS.dg1+=	-e '/\.MAKE.PATH_FILEMON/d'
655STD_SED_CMDS.dg1+=	-e '/^\#.*\/mk/d'
656STD_SED_CMDS.dg1+=	-e 's,  ${DEFSYSPATH:U/usr/share/mk}$$,  <defsyspath>,'
657STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
658STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
659STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,'
660STD_SED_CMDS.dg1+=	-e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
661STD_SED_CMDS.dg1+=	-e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
662STD_SED_CMDS.dg1+=	-e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
663STD_SED_CMDS.dg1+=	-e '/\.SYSPATH/d'
664
665STD_SED_CMDS.dg2=	${STD_SED_CMDS.dg1}
666STD_SED_CMDS.dg2+=	-e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'
667STD_SED_CMDS.dg3=	${STD_SED_CMDS.dg2}
668
669# Omit details such as process IDs from the output of the -dj option.
670STD_SED_CMDS.dj= \
671	-e '/Process/d;/JobFinish:/d' \
672	-e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \
673	-e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \
674	-e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \
675	-e 's,^\(	Command:\) .*,\1 <shell>,'
676
677# Reduce the noise for tests running with the -n option, since there is no
678# other way to suppress the echoing of the commands.
679STD_SED_CMDS.hide-from-output= \
680	-e '/^echo hide-from-output/d' \
681	-e 's,hide-from-output ,,' \
682	-e 's,hide-from-output,,'
683
684# Normalize the output for error messages from the shell.
685#
686# $shell -c '...'
687#	NetBSD sh	...: not found
688#	NetBSD ksh	ksh: ...: not found
689#	bash 5.0.18	bash: ...: command not found
690#	bash 5.1.0	bash: line 1: ...: command not found
691#	dash		dash: 1: ...: not found
692#
693# $shell -c '< /nonexistent'
694#	NetBSD sh	sh: cannot open /nonexistent: no such file
695#	NetBSD ksh	ksh: cannot open /nonexistent: No such file or directory
696#	bash 5.0.18	bash: /nonexistent: No such file or directory
697#	bash 5.1.0	bash: line 1: /nonexistent: No such file or directory
698#	dash		dash: 1: cannot open /nonexistent: No such file
699#
700# echo '< /nonexistent' | $shell
701#	NetBSD sh	sh: cannot open /nonexistent: no such file
702#	NetBSD ksh	ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory
703#	bash 5.0.18	bash: line 1: /nonexistent: No such file or directory
704#	bash 5.1.0	bash: line 1: /nonexistent: No such file or directory
705#	dash		dash: 1: cannot open /nonexistent: No such file
706#
707STD_SED_CMDS.shell+=		-e 's,^${.SHELL},${.SHELL:T},'
708STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
709STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
710STD_SED_CMDS.shell+=		-e 's,^${.SHELL:T}: ,,'
711STD_SED_CMDS.shell+=		-e 's,: command not found,: not found,'
712
713STD_SED_CMDS.white-space=	-e 's,   *, ,g' -e 's,  *$$,,'
714
715# The actual error messages for a failed regcomp or regexec differ between the
716# implementations.
717STD_SED_CMDS.regex= \
718	-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
719
720# Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'.
721# See STD_SED_CMDS.dg2 for timestamps from the debug log.
722STD_SED_CMDS.timestamp= \
723	-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>,'
724
725# End of the configuration helpers section.
726
727.-include "Makefile.inc"
728.-include "Makefile.config"
729
730UNIT_TESTS:=	${.PARSEDIR}
731.PATH: ${UNIT_TESTS}
732
733.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
734OUTFILES=	${TESTS:@test@${.CURDIR:tA}/${test}.out@}
735.else
736OUTFILES=	${TESTS:=.out}
737.endif
738
739all: ${OUTFILES}
740
741CLEANFILES=		*.rawout *.out *.status *.tmp *.core *.tmp
742CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
743CLEANFILES+=		issue* .[ab]*		# suffixes.mk
744CLEANDIRS=		dir dummy		# posix1.mk
745
746clean:
747	rm -f ${CLEANFILES}
748	rm -rf ${CLEANDIRS}
749
750TEST_MAKE?=	${.MAKE}
751TOOL_SED?=	sed
752TOOL_TR?=	tr
753TOOL_DIFF?=	diff
754DIFF_FLAGS?=	-u
755
756.if defined(.PARSEDIR)
757# ensure consistent results from sort(1)
758LC_ALL=		C
759LANG=		C
760.export LANG LC_ALL
761.endif
762
763.if ${.MAKE.MODE:Unormal:Mmeta} != ""
764# we don't need the noise
765_MKMSG_TEST= :
766.endif
767
768# Some Linux systems such as Fedora have deprecated egrep in favor of grep -E.
769.if ${.MAKE.OS:NLinux} == ""
770EGREP= grep -E
771.endif
772# Keep the classical definition for all other systems.  Just as the bmake code
773# is kept compatible with C90, the tests are kept compatible with systems that
774# are several decades old and don't follow modern POSIX standards.
775EGREP?= egrep
776
777MAKE_TEST_ENV=  EGREP="${EGREP}"
778MAKE_TEST_ENV+=	MALLOC_OPTIONS="JA"	# for jemalloc 100
779MAKE_TEST_ENV+=	MALLOC_CONF="junk:true"	# for jemalloc 510
780MAKE_TEST_ENV+= TMPDIR=${TMPDIR}
781
782.if ${.MAKE.OS} == "NetBSD"
783LIMIT_RESOURCES?=	ulimit -v 300000
784.endif
785LIMIT_RESOURCES?=	:
786
787# Each test is run in a sub-make, to keep the tests from interfering with
788# each other, and because they use different environment variables and
789# command line options.
790.SUFFIXES: .mk .rawout .out
791.mk.rawout:
792	@${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
793	@set -eu; \
794	${LIMIT_RESOURCES}; \
795	cd ${.OBJDIR}; \
796	env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
797	  ${TEST_MAKE} \
798	    -r -C ${.CURDIR} -f ${.IMPSRC} \
799	    ${FLAGS.${.PREFIX:T}:U-k} \
800	    > ${.TARGET}.tmp 2>&1 \
801	&& status=$$? || status=$$?; \
802	echo $$status > ${.TARGET:R}.status
803	@mv ${.TARGET}.tmp ${.TARGET}
804
805# Postprocess the test output to make the output platform-independent.
806#
807# Replace anything after 'stopped in' with unit-tests
808_SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
809# Allow the test files to be placed anywhere.
810_SED_CMDS+=	-e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
811_SED_CMDS+=	-e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
812_SED_CMDS+=	-e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g'
813# canonicalize ${.OBJDIR} and ${.CURDIR}
814_SED_CMDS+=	-e 's,${.CURDIR},<curdir>,g'
815.if ${.OBJDIR} != ${.CURDIR}
816# yes this is inaccurate but none of the tests expect <objdir> anywhere
817# which we get depending on how MAKEOBJDIR is set.
818_SED_CMDS+=	-e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g'
819.endif
820# always pretend .MAKE was called 'make'
821_SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
822_SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
823_SED_CMDS+=	-e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
824_SED_CMDS+=	-e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\]:\),make\1,'
825_SED_CMDS+=	-e 's,<curdir>/,,g'
826_SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
827_SED_CMDS+=	-e '/MAKE_VERSION/d'
828_SED_CMDS+=	-e '/EGREP=/d'
829
830# on AT&T derived systems: false exits 255 not 1
831.if ${.MAKE.OS:N*BSD} != ""
832_SED_CMDS+=	-e 's,\(Error code\) 255,\1 1,'
833.endif
834.if ${.SHELL:T} == "ksh"
835_SED_CMDS+=	-e '/^set [+-]v/d'
836.endif
837
838.rawout.out:
839	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
840	  < ${.IMPSRC} > ${.TARGET}.tmp1
841	@${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
842	@rm ${.TARGET}.tmp1
843	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
844	@mv ${.TARGET}.tmp2 ${.TARGET}
845
846.if empty(DIFF_FLAGS)
847DIFF_ECHO= echo
848.else
849DIFF_ECHO= :
850.endif
851
852# Compare all output files
853test:	${OUTFILES} .PHONY
854	@failed= ; \
855	for test in ${TESTS}; do \
856	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out && continue || \
857	  ${DIFF_ECHO} diff ${UNIT_TESTS}/$${test}.exp $${test}.out; \
858	  ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
859	  || failed="$${failed}$${failed:+ }$${test}" ; \
860	done ; \
861	if [ -n "$${failed}" ]; then \
862	  echo "Failed tests: $${failed}" ; false ; \
863	else \
864	  echo "All tests passed" ; \
865	fi
866
867accept:
868	@for test in ${TESTS}; do \
869	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
870	  || { echo "Replacing $${test}.exp" ; \
871	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
872	done
873
874.if exists(${TEST_MAKE})
875${TESTS:=.rawout}: ${TEST_MAKE}
876# in meta mode, we *know* if a target script is impacted
877# by a makefile change.
878.if ${.MAKE.MODE:Unormal:Mmeta} == ""
879${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
880.endif
881.endif
882
883.-include <obj.mk>
884