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