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