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