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