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