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