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