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