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