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