aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/Makefile
blob: cca63155e8687da885b58cfd883bf3b809129dd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# $Id: Makefile,v 1.115 2020/11/18 04:01:07 sjg Exp $
#
# $NetBSD: Makefile,v 1.206 2020/11/18 01:12:00 sjg Exp $
#
# Unit tests for make(1)
#
# The main targets are:
#
# all:
#	run all the tests
# test:
#	run 'all', and compare to expected results
# accept:
#	move generated output to expected results
#
# Settable variables
#
# TEST_MAKE
#	The make program to be tested.
#
#
# Adding a test case
#
# Each feature should get its own set of tests in its own suitably
# named makefile (*.mk), with its own set of expected results (*.exp),
# and it should be added to the TESTS list.
#
# A few *.mk files are helper files for other tests (such as include-sub.mk)
# and are thus not added to TESTS.  Such files must be ignored in
# src/tests/usr.bin/make/t_make.sh.
#

# Each test is in a sub-makefile.
# Keep the list sorted.
# Any test that is commented out must be ignored in
# src/tests/usr.bin/make/t_make.sh as well.
#TESTS+=		archive
TESTS+=		archive-suffix
TESTS+=		cmd-errors
TESTS+=		cmd-errors-lint
TESTS+=		cmd-interrupt
TESTS+=		cmdline
TESTS+=		cmdline-undefined
TESTS+=		comment
TESTS+=		cond-cmp-numeric
TESTS+=		cond-cmp-numeric-eq
TESTS+=		cond-cmp-numeric-ge
TESTS+=		cond-cmp-numeric-gt
TESTS+=		cond-cmp-numeric-le
TESTS+=		cond-cmp-numeric-lt
TESTS+=		cond-cmp-numeric-ne
TESTS+=		cond-cmp-string
TESTS+=		cond-cmp-unary
TESTS+=		cond-func
TESTS+=		cond-func-commands
TESTS+=		cond-func-defined
TESTS+=		cond-func-empty
TESTS+=		cond-func-exists
TESTS+=		cond-func-make
TESTS+=		cond-func-target
TESTS+=		cond-late
TESTS+=		cond-op
TESTS+=		cond-op-and
TESTS+=		cond-op-and-lint
TESTS+=		cond-op-not
TESTS+=		cond-op-or
TESTS+=		cond-op-or-lint
TESTS+=		cond-op-parentheses
TESTS+=		cond-short
TESTS+=		cond-token-number
TESTS+=		cond-token-plain
TESTS+=		cond-token-string
TESTS+=		cond-token-var
TESTS+=		cond-undef-lint
TESTS+=		cond1
TESTS+=		counter
TESTS+=		counter-append
TESTS+=		dep
TESTS+=		dep-colon
TESTS+=		dep-colon-bug-cross-file
TESTS+=		dep-double-colon
TESTS+=		dep-double-colon-indep
TESTS+=		dep-exclam
TESTS+=		dep-none
TESTS+=		dep-percent
TESTS+=		dep-var
TESTS+=		dep-wildcards
TESTS+=		depsrc
TESTS+=		depsrc-end
TESTS+=		depsrc-exec
TESTS+=		depsrc-ignore
TESTS+=		depsrc-made
TESTS+=		depsrc-make
TESTS+=		depsrc-meta
TESTS+=		depsrc-nometa
TESTS+=		depsrc-nometa_cmp
TESTS+=		depsrc-nopath
TESTS+=		depsrc-notmain
TESTS+=		depsrc-optional
TESTS+=		depsrc-phony
TESTS+=		depsrc-precious
TESTS+=		depsrc-recursive
TESTS+=		depsrc-silent
TESTS+=		depsrc-use
TESTS+=		depsrc-usebefore
TESTS+=		depsrc-usebefore-double-colon
TESTS+=		depsrc-wait
TESTS+=		deptgt
TESTS+=		deptgt-begin
TESTS+=		deptgt-default
TESTS+=		deptgt-delete_on_error
TESTS+=		deptgt-end
TESTS+=		deptgt-end-jobs
TESTS+=		deptgt-error
TESTS+=		deptgt-ignore
TESTS+=		deptgt-interrupt
TESTS+=		deptgt-main
TESTS+=		deptgt-makeflags
TESTS+=		deptgt-no_parallel
TESTS+=		deptgt-nopath
TESTS+=		deptgt-notparallel
TESTS+=		deptgt-objdir
TESTS+=		deptgt-order
TESTS+=		deptgt-path
TESTS+=		deptgt-path-suffix
TESTS+=		deptgt-phony
TESTS+=		deptgt-precious
TESTS+=		deptgt-shell
TESTS+=		deptgt-silent
TESTS+=		deptgt-stale
TESTS+=		deptgt-suffixes
TESTS+=		dir
TESTS+=		dir-expand-path
TESTS+=		directive
TESTS+=		directive-dinclude
TESTS+=		directive-elif
TESTS+=		directive-elifdef
TESTS+=		directive-elifmake
TESTS+=		directive-elifndef
TESTS+=		directive-elifnmake
TESTS+=		directive-else
TESTS+=		directive-endif
TESTS+=		directive-error
TESTS+=		directive-export
TESTS+=		directive-export-env
TESTS+=		directive-export-gmake
TESTS+=		directive-export-literal
TESTS+=		directive-for
TESTS+=		directive-for-generating-endif
TESTS+=		directive-hyphen-include
TESTS+=		directive-if
TESTS+=		directive-if-nested
TESTS+=		directive-ifdef
TESTS+=		directive-ifmake
TESTS+=		directive-ifndef
TESTS+=		directive-ifnmake
TESTS+=		directive-include
TESTS+=		directive-include-fatal
TESTS+=		directive-info
TESTS+=		directive-sinclude
TESTS+=		directive-undef
TESTS+=		directive-unexport
TESTS+=		directive-unexport-env
TESTS+=		directive-warning
TESTS+=		dollar
TESTS+=		doterror
TESTS+=		dotwait
TESTS+=		envfirst
TESTS+=		error
TESTS+=		# escape	# broken by reverting POSIX changes
TESTS+=		export
TESTS+=		export-all
TESTS+=		export-env
TESTS+=		export-variants
TESTS+=		forloop
TESTS+=		forsubst
TESTS+=		gnode-submake
TESTS+=		hanoi-include
TESTS+=		impsrc
TESTS+=		include-main
TESTS+=		job-flags
#TESTS+=		job-output-long-lines
TESTS+=		lint
TESTS+=		make-exported
TESTS+=		moderrs
TESTS+=		modmatch
TESTS+=		modmisc
TESTS+=		modts
TESTS+=		modword
TESTS+=		objdir-writable
TESTS+=		opt
TESTS+=		opt-backwards
TESTS+=		opt-chdir
TESTS+=		opt-debug
TESTS+=		opt-debug-all
TESTS+=		opt-debug-archive
TESTS+=		opt-debug-curdir
TESTS+=		opt-debug-cond
TESTS+=		opt-debug-dir
TESTS+=		opt-debug-errors
TESTS+=		opt-debug-file
TESTS+=		opt-debug-for
TESTS+=		opt-debug-graph1
TESTS+=		opt-debug-graph2
TESTS+=		opt-debug-graph3
TESTS+=		opt-debug-hash
#TESTS+=		opt-debug-jobs
TESTS+=		opt-debug-lint
TESTS+=		opt-debug-loud
TESTS+=		opt-debug-meta
TESTS+=		opt-debug-making
TESTS+=		opt-debug-no-rm
TESTS+=		opt-debug-parse
TESTS+=		opt-debug-suff
TESTS+=		opt-debug-targets
TESTS+=		opt-debug-varraw
TESTS+=		opt-debug-var
TESTS+=		opt-debug-x-trace
TESTS+=		opt-define
TESTS+=		opt-env
TESTS+=		opt-file
TESTS+=		opt-ignore
TESTS+=		opt-include-dir
TESTS+=		opt-jobs
TESTS+=		opt-jobs-internal
TESTS+=		opt-keep-going
TESTS+=		opt-m-include-dir
TESTS+=		opt-no-action
TESTS+=		opt-no-action-at-all
TESTS+=		opt-query
TESTS+=		opt-raw
TESTS+=		opt-silent
TESTS+=		opt-touch
TESTS+=		opt-touch-jobs
TESTS+=		opt-tracefile
TESTS+=		opt-var-expanded
TESTS+=		opt-var-literal
TESTS+=		opt-warnings-as-errors
TESTS+=		opt-where-am-i
TESTS+=		opt-x-reduce-exported
TESTS+=		order
TESTS+=		parse-var
TESTS+=		phony-end
TESTS+=		posix
TESTS+=		# posix1	# broken by reverting POSIX changes
TESTS+=		qequals
TESTS+=		recursive
TESTS+=		sh
TESTS+=		sh-dots
TESTS+=		sh-jobs
TESTS+=		sh-jobs-error
TESTS+=		sh-leading-at
TESTS+=		sh-leading-hyphen
TESTS+=		sh-leading-plus
TESTS+=		sh-meta-chars
TESTS+=		sh-multi-line
TESTS+=		sh-single-line
TESTS+=		shell-csh
TESTS+=		shell-custom
.if exists(/bin/ksh)
TESTS+=		shell-ksh
.endif
TESTS+=		shell-sh
TESTS+=		suff-add-later
TESTS+=		suff-clear-regular
TESTS+=		suff-clear-single
TESTS+=		suff-lookup
TESTS+=		suff-main
TESTS+=		suff-rebuild
TESTS+=		suff-self
TESTS+=		suff-transform-endless
TESTS+=		suff-transform-expand
TESTS+=		suff-transform-select
TESTS+=		sunshcmd
TESTS+=		ternary
TESTS+=		unexport
TESTS+=		unexport-env
TESTS+=		use-inference
TESTS+=		var-class
TESTS+=		var-class-cmdline
TESTS+=		var-class-env
TESTS+=		var-class-global
TESTS+=		var-class-local
TESTS+=		var-class-local-legacy
TESTS+=		var-op
TESTS+=		var-op-append
TESTS+=		var-op-assign
TESTS+=		var-op-default
TESTS+=		var-op-expand
TESTS+=		var-op-shell
TESTS+=		var-op-sunsh
TESTS+=		var-recursive
TESTS+=		varcmd
TESTS+=		vardebug
TESTS+=		varfind
TESTS+=		varmisc
TESTS+=		varmod
TESTS+=		varmod-assign
TESTS+=		varmod-defined
TESTS+=		varmod-edge
TESTS+=		varmod-exclam-shell
TESTS+=		varmod-extension
TESTS+=		varmod-gmtime
TESTS+=		varmod-hash
TESTS+=		varmod-head
TESTS+=		varmod-ifelse
TESTS+=		varmod-l-name-to-value
TESTS+=		varmod-localtime
TESTS+=		varmod-loop
TESTS+=		varmod-match
TESTS+=		varmod-match-escape
TESTS+=		varmod-no-match
TESTS+=		varmod-order
TESTS+=		varmod-order-reverse
TESTS+=		varmod-order-shuffle
TESTS+=		varmod-path
TESTS+=		varmod-quote
TESTS+=		varmod-quote-dollar
TESTS+=		varmod-range
TESTS+=		varmod-remember
TESTS+=		varmod-root
TESTS+=		varmod-select-words
TESTS+=		varmod-shell
TESTS+=		varmod-subst
TESTS+=		varmod-subst-regex
TESTS+=		varmod-sysv
TESTS+=		varmod-tail
TESTS+=		varmod-to-abs
TESTS+=		varmod-to-lower
TESTS+=		varmod-to-many-words
TESTS+=		varmod-to-one-word
TESTS+=		varmod-to-separator
TESTS+=		varmod-to-upper
TESTS+=		varmod-undefined
TESTS+=		varmod-unique
TESTS+=		varname
TESTS+=		varname-dollar
TESTS+=		varname-dot-alltargets
TESTS+=		varname-dot-curdir
TESTS+=		varname-dot-includes
TESTS+=		varname-dot-includedfromdir
TESTS+=		varname-dot-includedfromfile
TESTS+=		varname-dot-libs
TESTS+=		varname-dot-make-dependfile
TESTS+=		varname-dot-make-expand_variables
TESTS+=		varname-dot-make-exported
TESTS+=		varname-dot-make-jobs
TESTS+=		varname-dot-make-jobs-prefix
TESTS+=		varname-dot-make-level
TESTS+=		varname-dot-make-makefile_preference
TESTS+=		varname-dot-make-makefiles
TESTS+=		varname-dot-make-meta-bailiwick
TESTS+=		varname-dot-make-meta-created
TESTS+=		varname-dot-make-meta-files
TESTS+=		varname-dot-make-meta-ignore_filter
TESTS+=		varname-dot-make-meta-ignore_paths
TESTS+=		varname-dot-make-meta-ignore_patterns
TESTS+=		varname-dot-make-meta-prefix
TESTS+=		varname-dot-make-mode
TESTS+=		varname-dot-make-path_filemon
TESTS+=		varname-dot-make-pid
TESTS+=		varname-dot-make-ppid
TESTS+=		varname-dot-make-save_dollars
TESTS+=		varname-dot-makeoverrides
TESTS+=		varname-dot-newline
TESTS+=		varname-dot-objdir
TESTS+=		varname-dot-parsedir
TESTS+=		varname-dot-parsefile
TESTS+=		varname-dot-path
TESTS+=		varname-dot-shell
TESTS+=		varname-dot-targets
TESTS+=		varname-empty
TESTS+=		varname-make
TESTS+=		varname-make_print_var_on_error
TESTS+=		varname-make_print_var_on_error-jobs
TESTS+=		varname-makefile
TESTS+=		varname-makeflags
TESTS+=		varname-pwd
TESTS+=		varname-vpath
TESTS+=		varparse-dynamic
TESTS+=		varparse-errors
TESTS+=		varparse-mod
TESTS+=		varparse-undef-partial
TESTS+=		varquote

# Ideas for more tests:
#	char-0020-space.mk
#	char-005C-backslash.mk
#	escape-cond-str.mk
#	escape-cond-func-arg.mk
#	escape-cond-func-arg.mk
#	escape-varmod.mk
#	escape-varmod-define.mk
#	escape-varmod-match.mk
#	escape-varname.mk
#	escape-varassign-varname.mk
#	escape-varassign-varname-cmdline.mk
#	escape-varassign-value.mk
#	escape-varassign-value-cmdline.mk
#	escape-dependency-source.mk
#	escape-dependency-target.mk
#	escape-for-varname.mk
#	escape-for-item.mk
#	posix-*.mk (see posix.mk and posix1.mk)

.if ${.OBJDIR} != ${.CURDIR}
RO_OBJDIR:=	${.OBJDIR}/roobj
.else
RO_OBJDIR:=	${TMPDIR:U/tmp}/roobj
.endif
# Additional environment variables for some of the tests.
# The base environment is -i PATH="$PATH".
ENV.depsrc-optional+=   TZ=UTC
ENV.envfirst=		FROM_ENV=value-from-env
ENV.objdir-writable+=	RO_OBJDIR=${RO_OBJDIR}
ENV.varmisc=		FROM_ENV=env
ENV.varmisc+=		FROM_ENV_BEFORE=env
ENV.varmisc+=		FROM_ENV_AFTER=env
ENV.varmod-localtime+=	TZ=Europe/Berlin
ENV.varname-vpath+=	VPATH=varname-vpath.dir:varname-vpath.dir2

# Override make flags for some of the tests; default is -k.
# If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
# settings FLAGS.test=-dv here, since that is closer to the test code.
FLAGS.cond-func-make=	via-cmdline
FLAGS.directive-ifmake=	first second
FLAGS.doterror=		# none, especially not -k
FLAGS.varname-empty=	-dv '$${:U}=cmdline-u' '=cmdline-plain'

# Some tests need extra postprocessing.
SED_CMDS.export= \
	-e '/^[^=_A-Za-z0-9]*=/d'
# these all share the same requirement
.for t in export-all export-env
SED_CMDS.$t= ${SED_CMDS.export}
.endfor
SED_CMDS.directive-export-gmake= \
	${:D dash is a pain } \
	-e /non-zero/d
SED_CMDS.job-output-long-lines= \
	${:D Job separators on their own line are ok. } \
	-e '/^--- job-[ab] ---$$/d' \
	${:D Plain output lines are ok as well. } \
	${:D They may come in multiples of 1024 or as 10000. } \
	-e '/^aa*$$/d' \
	-e '/^bb*$$/d' \
	${:D The following lines should rather not occur since the job } \
	${:D marker should always be at the beginning of the line. } \
	-e '/^aa*--- job-b ---$$/d' \
	-e '/^bb*--- job-a ---$$/d'
SED_CMDS.objdir-writable= -e 's,${RO_OBJDIR},OBJDIR/roobj,g'
SED_CMDS.opt-debug-graph1= \
			-e 's,${.CURDIR},CURDIR,'
SED_CMDS.opt-debug-graph1+= \
			-e '/Global Variables:/,/Suffixes:/d'
SED_CMDS.sh-dots=	-e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
SED_CMDS.opt-debug-jobs=	-e 's,([0-9][0-9]*),(<pid>),'
SED_CMDS.opt-debug-jobs+=	-e 's,pid [0-9][0-9]*,pid <pid>,'
SED_CMDS.opt-debug-jobs+=	-e 's,Process [0-9][0-9]*,Process <pid>,'
SED_CMDS.opt-debug-jobs+=	-e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
# The "-q" may be there or not, see jobs.c, variable shells.
SED_CMDS.opt-debug-jobs+=	-e 's,^\(.Command: sh\) -q,\1,'
SED_CMDS.var-op-shell+=	-e 's,^${.SHELL:T}: ,,'
SED_CMDS.var-op-shell+=	-e '/command/{ s,^[1-9]: ,,;s,No such.*,not found,; }'
SED_CMDS.vardebug= \
	${:D canonicalize .SHELL } \
	-e 's,${.SHELL},</path/to/shell>,'
SED_CMDS.varmod-subst-regex+= \
			-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
SED_CMDS.varmod-edge+=	-e 's, line [0-9]*:, line omitted:,'
SED_CMDS.varname-dot-parsedir=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
SED_CMDS.varname-dot-parsefile=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'

# Some tests need an additional round of postprocessing.
POSTPROC.deptgt-suffixes= \
			${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
POSTPROC.gnode-submake=	awk '/Input graph/, /^$$/'
POSTPROC.varname-empty=	${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'

# Some tests reuse other tests, which makes them unnecessarily fragile.
export-all.rawout: export.mk
unexport.rawout: export.mk
unexport-env.rawout: export.mk

# End of the configuration section.

.MAIN: all

.-include "Makefile.inc"
.-include "Makefile.config"

UNIT_TESTS:=	${.PARSEDIR}
.PATH: ${UNIT_TESTS}

.if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
OUTFILES=	${TESTS:@test@${.CURDIR:tA}/${test}.out@}
.else
OUTFILES=	${TESTS:=.out}
.endif

all: ${OUTFILES}

CLEANFILES=		*.rawout *.out *.status *.tmp *.core *.tmp
CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
CLEANFILES+=		issue* .[ab]*		# suffixes.mk
CLEANDIRS=		dir dummy		# posix1.mk

clean:
	rm -f ${CLEANFILES}
	rm -rf ${CLEANDIRS}

TEST_MAKE?=	${.MAKE}
TOOL_SED?=	sed
TOOL_TR?=	tr
TOOL_DIFF?=	diff
DIFF_FLAGS?=	-u

.if defined(.PARSEDIR)
# ensure consistent results from sort(1)
LC_ALL=		C
LANG=		C
.export LANG LC_ALL
.endif

.if ${.MAKE.MODE:Unormal:Mmeta} != ""
# we don't need the noise
_MKMSG_TEST= :
.endif

MAKE_TEST_ENV?=	MALLOC_OPTIONS="JA"	# for jemalloc

# Each test is run in a sub-make, to keep the tests for interfering with
# each other, and because they use different environment variables and
# command line options.
.SUFFIXES: .mk .rawout .out
.mk.rawout:
	@${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
	@set -eu; \
	cd ${.OBJDIR}; \
	env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
	  ${TEST_MAKE} \
	    -r -C ${.CURDIR} -f ${.IMPSRC} \
	    ${FLAGS.${.PREFIX:T}:U-k} \
	    > ${.TARGET}.tmp 2>&1 \
	&& status=$$? || status=$$?; \
	echo $$status > ${.TARGET:R}.status
	@mv ${.TARGET}.tmp ${.TARGET}

# Postprocess the test output so that the results can be compared.
#
# always pretend .MAKE was called 'make'
_SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
_SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
_SED_CMDS+=	-e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
_SED_CMDS+=	-e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
# replace anything after 'stopped in' with unit-tests
_SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
# strip ${.CURDIR}/ from the output
_SED_CMDS+=	-e 's,${.CURDIR:S,.,\\.,g}/,,g'
_SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'

.rawout.out:
	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
	  < ${.IMPSRC} > ${.TARGET}.tmp1
	@${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
	@rm ${.TARGET}.tmp1
	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
	@mv ${.TARGET}.tmp2 ${.TARGET}

# Compare all output files
test:	${OUTFILES} .PHONY
	@failed= ; \
	for test in ${TESTS}; do \
	  ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
	  || failed="$${failed}$${failed:+ }$${test}" ; \
	done ; \
	if [ -n "$${failed}" ]; then \
	  echo "Failed tests: $${failed}" ; false ; \
	else \
	  echo "All tests passed" ; \
	fi

accept:
	@for test in ${TESTS}; do \
	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
	  || { echo "Replacing $${test}.exp" ; \
	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
	done

.if exists(${TEST_MAKE})
${TESTS:=.rawout}: ${TEST_MAKE}
# in meta mode, we *know* if a target script is impacted
# by a makefile change.
.if ${.MAKE.MODE:Unormal:Mmeta} == ""
${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
.endif
.endif

.-include <obj.mk>