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