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