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