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