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