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