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