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