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