Makefile revision 1.264 1 # $NetBSD: Makefile,v 1.264 2021/01/30 12:46:38 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-empty-commands
205 TESTS+= jobs-error-indirect
206 TESTS+= jobs-error-nested
207 TESTS+= jobs-error-nested-make
208 TESTS+= lint
209 TESTS+= make-exported
210 TESTS+= meta-cmd-cmp
211 TESTS+= moderrs
212 TESTS+= modmatch
213 TESTS+= modmisc
214 TESTS+= modts
215 TESTS+= modword
216 .if ${.MAKE.UID} > 0
217 TESTS+= objdir-writable
218 .endif
219 TESTS+= opt
220 TESTS+= opt-backwards
221 TESTS+= opt-chdir
222 TESTS+= opt-debug
223 TESTS+= opt-debug-all
224 TESTS+= opt-debug-archive
225 TESTS+= opt-debug-curdir
226 TESTS+= opt-debug-cond
227 TESTS+= opt-debug-dir
228 TESTS+= opt-debug-errors
229 TESTS+= opt-debug-file
230 TESTS+= opt-debug-for
231 TESTS+= opt-debug-graph1
232 TESTS+= opt-debug-graph2
233 TESTS+= opt-debug-graph3
234 TESTS+= opt-debug-hash
235 TESTS+= opt-debug-jobs
236 TESTS+= opt-debug-lint
237 TESTS+= opt-debug-loud
238 TESTS+= opt-debug-meta
239 TESTS+= opt-debug-making
240 TESTS+= opt-debug-no-rm
241 TESTS+= opt-debug-parse
242 TESTS+= opt-debug-suff
243 TESTS+= opt-debug-targets
244 TESTS+= opt-debug-varraw
245 TESTS+= opt-debug-var
246 TESTS+= opt-debug-x-trace
247 TESTS+= opt-define
248 TESTS+= opt-env
249 TESTS+= opt-file
250 TESTS+= opt-ignore
251 TESTS+= opt-include-dir
252 TESTS+= opt-jobs
253 TESTS+= opt-jobs-internal
254 TESTS+= opt-jobs-no-action
255 TESTS+= opt-keep-going
256 TESTS+= opt-keep-going-multiple
257 TESTS+= opt-m-include-dir
258 TESTS+= opt-no-action
259 TESTS+= opt-no-action-at-all
260 TESTS+= opt-no-action-runflags
261 TESTS+= opt-no-action-touch
262 TESTS+= opt-query
263 TESTS+= opt-raw
264 TESTS+= opt-silent
265 TESTS+= opt-touch
266 TESTS+= opt-touch-jobs
267 TESTS+= opt-tracefile
268 TESTS+= opt-var-expanded
269 TESTS+= opt-var-literal
270 TESTS+= opt-warnings-as-errors
271 TESTS+= opt-where-am-i
272 TESTS+= opt-x-reduce-exported
273 TESTS+= order
274 TESTS+= parse-var
275 TESTS+= phony-end
276 TESTS+= posix
277 TESTS+= # posix1 # broken by reverting POSIX changes
278 TESTS+= recursive
279 TESTS+= sh
280 TESTS+= sh-dots
281 TESTS+= sh-errctl
282 TESTS+= sh-flags
283 TESTS+= sh-jobs
284 TESTS+= sh-jobs-error
285 TESTS+= sh-leading-at
286 TESTS+= sh-leading-hyphen
287 TESTS+= sh-leading-plus
288 TESTS+= sh-meta-chars
289 TESTS+= sh-multi-line
290 TESTS+= sh-single-line
291 TESTS+= shell-csh
292 TESTS+= shell-custom
293 TESTS+= shell-ksh
294 TESTS+= shell-sh
295 TESTS+= suff-add-later
296 TESTS+= suff-clear-regular
297 TESTS+= suff-clear-single
298 TESTS+= suff-incomplete
299 TESTS+= suff-lookup
300 TESTS+= suff-main
301 TESTS+= suff-main-several
302 TESTS+= suff-phony
303 TESTS+= suff-rebuild
304 TESTS+= suff-self
305 TESTS+= suff-transform-debug
306 TESTS+= suff-transform-endless
307 TESTS+= suff-transform-expand
308 TESTS+= suff-transform-select
309 TESTS+= sunshcmd
310 TESTS+= ternary
311 TESTS+= unexport
312 TESTS+= unexport-env
313 TESTS+= use-inference
314 TESTS+= var-class
315 TESTS+= var-class-cmdline
316 TESTS+= var-class-env
317 TESTS+= var-class-global
318 TESTS+= var-class-local
319 TESTS+= var-class-local-legacy
320 TESTS+= var-op
321 TESTS+= var-op-append
322 TESTS+= var-op-assign
323 TESTS+= var-op-default
324 TESTS+= var-op-expand
325 TESTS+= var-op-shell
326 TESTS+= var-op-sunsh
327 TESTS+= var-recursive
328 TESTS+= varcmd
329 TESTS+= vardebug
330 TESTS+= varfind
331 TESTS+= varmisc
332 TESTS+= varmod
333 TESTS+= varmod-assign
334 TESTS+= varmod-defined
335 TESTS+= varmod-edge
336 TESTS+= varmod-exclam-shell
337 TESTS+= varmod-extension
338 TESTS+= varmod-gmtime
339 TESTS+= varmod-hash
340 TESTS+= varmod-head
341 TESTS+= varmod-ifelse
342 TESTS+= varmod-indirect
343 TESTS+= varmod-l-name-to-value
344 TESTS+= varmod-localtime
345 TESTS+= varmod-loop
346 TESTS+= varmod-match
347 TESTS+= varmod-match-escape
348 TESTS+= varmod-no-match
349 TESTS+= varmod-order
350 TESTS+= varmod-order-reverse
351 TESTS+= varmod-order-shuffle
352 TESTS+= varmod-path
353 TESTS+= varmod-quote
354 TESTS+= varmod-quote-dollar
355 TESTS+= varmod-range
356 TESTS+= varmod-remember
357 TESTS+= varmod-root
358 TESTS+= varmod-select-words
359 TESTS+= varmod-shell
360 TESTS+= varmod-subst
361 TESTS+= varmod-subst-regex
362 TESTS+= varmod-sysv
363 TESTS+= varmod-tail
364 TESTS+= varmod-to-abs
365 TESTS+= varmod-to-lower
366 TESTS+= varmod-to-many-words
367 TESTS+= varmod-to-one-word
368 TESTS+= varmod-to-separator
369 TESTS+= varmod-to-upper
370 TESTS+= varmod-undefined
371 TESTS+= varmod-unique
372 TESTS+= varname
373 TESTS+= varname-dollar
374 TESTS+= varname-dot-alltargets
375 TESTS+= varname-dot-curdir
376 TESTS+= varname-dot-includes
377 TESTS+= varname-dot-includedfromdir
378 TESTS+= varname-dot-includedfromfile
379 TESTS+= varname-dot-libs
380 TESTS+= varname-dot-make-dependfile
381 TESTS+= varname-dot-make-expand_variables
382 TESTS+= varname-dot-make-exported
383 TESTS+= varname-dot-make-jobs
384 TESTS+= varname-dot-make-jobs-prefix
385 TESTS+= varname-dot-make-level
386 TESTS+= varname-dot-make-makefile_preference
387 TESTS+= varname-dot-make-makefiles
388 TESTS+= varname-dot-make-meta-bailiwick
389 TESTS+= varname-dot-make-meta-created
390 TESTS+= varname-dot-make-meta-files
391 TESTS+= varname-dot-make-meta-ignore_filter
392 TESTS+= varname-dot-make-meta-ignore_paths
393 TESTS+= varname-dot-make-meta-ignore_patterns
394 TESTS+= varname-dot-make-meta-prefix
395 TESTS+= varname-dot-make-mode
396 TESTS+= varname-dot-make-path_filemon
397 TESTS+= varname-dot-make-pid
398 TESTS+= varname-dot-make-ppid
399 TESTS+= varname-dot-make-save_dollars
400 TESTS+= varname-dot-makeflags
401 TESTS+= varname-dot-makeoverrides
402 TESTS+= varname-dot-newline
403 TESTS+= varname-dot-objdir
404 TESTS+= varname-dot-parsedir
405 TESTS+= varname-dot-parsefile
406 TESTS+= varname-dot-path
407 TESTS+= varname-dot-shell
408 TESTS+= varname-dot-targets
409 TESTS+= varname-empty
410 TESTS+= varname-make
411 TESTS+= varname-make_print_var_on_error
412 TESTS+= varname-make_print_var_on_error-jobs
413 TESTS+= varname-makefile
414 TESTS+= varname-makeflags
415 TESTS+= varname-pwd
416 TESTS+= varname-vpath
417 TESTS+= varparse-dynamic
418 TESTS+= varparse-errors
419 TESTS+= varparse-mod
420 TESTS+= varparse-undef-partial
421 TESTS+= varquote
422
423 # Ideas for more tests:
424 # char-0020-space.mk
425 # char-005C-backslash.mk
426 # escape-cond-str.mk
427 # escape-cond-func-arg.mk
428 # escape-cond-func-arg.mk
429 # escape-varmod.mk
430 # escape-varmod-define.mk
431 # escape-varmod-match.mk
432 # escape-varname.mk
433 # escape-varassign-varname.mk
434 # escape-varassign-varname-cmdline.mk
435 # escape-varassign-value.mk
436 # escape-varassign-value-cmdline.mk
437 # escape-dependency-source.mk
438 # escape-dependency-target.mk
439 # escape-for-varname.mk
440 # escape-for-item.mk
441 # posix-*.mk (see posix.mk and posix1.mk)
442
443 .if ${.OBJDIR} != ${.CURDIR}
444 RO_OBJDIR:= ${.OBJDIR}/roobj
445 .else
446 RO_OBJDIR:= ${TMPDIR:U/tmp}/roobj
447 .endif
448 # Additional environment variables for some of the tests.
449 # The base environment is -i PATH="$PATH".
450 ENV.depsrc-optional+= TZ=UTC
451 ENV.envfirst= FROM_ENV=value-from-env
452 ENV.objdir-writable+= RO_OBJDIR=${RO_OBJDIR}
453 ENV.varmisc= FROM_ENV=env
454 ENV.varmisc+= FROM_ENV_BEFORE=env
455 ENV.varmisc+= FROM_ENV_AFTER=env
456 ENV.varmod-localtime+= TZ=Europe/Berlin
457 ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2
458
459 # Override make flags for some of the tests; default is -k.
460 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
461 # settings FLAGS.test=-dv here, since that is closer to the test code.
462 FLAGS.cond-func-make= via-cmdline
463 FLAGS.directive-ifmake= first second
464 FLAGS.doterror= # none, especially not -k
465 FLAGS.jobs-error-indirect= # none, especially not -k
466 FLAGS.jobs-error-nested= # none, especially not -k
467 FLAGS.jobs-error-nested-make= # none, especially not -k
468 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain'
469
470 # Some tests need extra postprocessing.
471 SED_CMDS.dir= ${:D remove output from -DCLEANUP mode }
472 SED_CMDS.dir+= -e '/^OpenDirs_Done:/d'
473 SED_CMDS.dir+= -e '/^CachedDir /d'
474 SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d'
475 SED_CMDS.export-all= ${SED_CMDS.export}
476 SED_CMDS.export-env= ${SED_CMDS.export}
477 SED_CMDS.job-output-long-lines= \
478 ${:D Job separators on their own line are ok. } \
479 -e '/^--- job-[ab] ---$$/d' \
480 ${:D Plain output lines are ok as well. } \
481 ${:D They may come in multiples of 1024 or as 10000. } \
482 -e '/^aa*$$/d' \
483 -e '/^bb*$$/d' \
484 ${:D The following lines should rather not occur since the job } \
485 ${:D marker should always be at the beginning of the line. } \
486 -e '/^aa*--- job-b ---$$/d' \
487 -e '/^bb*--- job-a ---$$/d'
488 SED_CMDS.objdir-writable= -e 's,${RO_OBJDIR},OBJDIR/roobj,g'
489 SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1}
490 SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
491 SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
492 SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
493 SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
494 SED_CMDS.opt-debug-jobs+= -e 's,Command: ${.SHELL:T},Command: <shell>,'
495 # The "-q" may be there or not, see jobs.c, variable shells.
496 SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: <shell>\) -q,\1,'
497 SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output}
498 SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
499 # For Compat_RunCommand, useShell == FALSE.
500 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,'
501 # For Compat_RunCommand, useShell == TRUE.
502 SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
503 SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
504 SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj}
505 SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output}
506 SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1}
507 SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1}
508 SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1}
509 SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell}
510 SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,'
511 SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
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 # Normalize the output for error messages from the shell.
558 #
559 # $shell -c '...'
560 # NetBSD sh ...: not found
561 # NetBSD ksh ksh: ...: not found
562 # bash 5.0.18 bash: ...: command not found
563 # bash 5.1.0 bash: line 1: ...: command not found
564 # dash dash: 1: ...: not found
565 #
566 # $shell -c '< /nonexistent'
567 # NetBSD sh sh: cannot open /nonexistent: no such file
568 # NetBSD ksh ksh: cannot open /nonexistent: No such file or directory
569 # bash 5.0.18 bash: /nonexistent: No such file or directory
570 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
571 # dash dash: 1: cannot open /nonexistent: No such file
572 #
573 # echo '< /nonexistent' | $shell
574 # NetBSD sh sh: cannot open /nonexistent: no such file
575 # NetBSD ksh ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory
576 # bash 5.0.18 bash: line 1: /nonexistent: No such file or directory
577 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
578 # dash dash: 1: cannot open /nonexistent: No such file
579 #
580 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
581 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
582 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,'
583
584 # End of the configuration helpers section.
585
586 .MAIN: all
587
588 UNIT_TESTS:= ${.PARSEDIR}
589 .PATH: ${UNIT_TESTS}
590
591 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
592 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@}
593 .else
594 OUTFILES= ${TESTS:=.out}
595 .endif
596
597 all: ${OUTFILES}
598
599 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
600 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
601 CLEANFILES+= issue* .[ab]* # suffixes.mk
602 CLEANDIRS= dir dummy # posix1.mk
603
604 clean:
605 rm -f ${CLEANFILES}
606 rm -rf ${CLEANDIRS}
607
608 TEST_MAKE?= ${.MAKE}
609 TOOL_SED?= sed
610
611 # ensure consistent results from sort(1)
612 LC_ALL= C
613 LANG= C
614 .export LANG LC_ALL
615
616 MAKE_TEST_ENV?= MALLOC_OPTIONS="JA" # for jemalloc
617
618 .if ${.MAKE.OS} == "NetBSD"
619 LIMIT_RESOURCES?= ulimit -v 200000
620 .endif
621 LIMIT_RESOURCES?= :
622
623 # Each test is run in a sub-make, to keep the tests for interfering with
624 # each other, and because they use different environment variables and
625 # command line options.
626 .SUFFIXES: .mk .rawout .out
627 .mk.rawout:
628 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
629 @set -eu; \
630 ${LIMIT_RESOURCES}; \
631 cd ${.OBJDIR}; \
632 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
633 ${TEST_MAKE} \
634 -r -C ${.CURDIR} -f ${.IMPSRC} \
635 ${FLAGS.${.PREFIX:T}:U-k} \
636 > ${.TARGET}.tmp 2>&1 \
637 && status=$$? || status=$$?; \
638 echo $$status > ${.TARGET:R}.status
639 @mv ${.TARGET}.tmp ${.TARGET}
640
641 # Postprocess the test output so that the results can be compared.
642 #
643 # always pretend .MAKE was called 'make'
644 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
645 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
646 _SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
647 _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
648 # replace anything after 'stopped in' with unit-tests
649 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
650 # strip ${.CURDIR}/ from the output
651 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
652 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
653
654 .rawout.out:
655 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
656 < ${.IMPSRC} > ${.TARGET}.tmp1
657 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
658 @rm ${.TARGET}.tmp1
659 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
660 @mv ${.TARGET}.tmp2 ${.TARGET}
661
662 # Compare all output files
663 test: ${OUTFILES} .PHONY
664 @failed= ; \
665 for test in ${TESTS}; do \
666 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
667 || failed="$${failed}$${failed:+ }$${test}" ; \
668 done ; \
669 if [ -n "$${failed}" ]; then \
670 echo "Failed tests: $${failed}" ; false ; \
671 else \
672 echo "All tests passed" ; \
673 fi
674
675 accept:
676 @for test in ${TESTS}; do \
677 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
678 || { echo "Replacing $${test}.exp" ; \
679 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
680 done
681
682 # Note: only works for adding tests.
683 # To remove a test, the $$mi file must be edited manually.
684 sync-mi:
685 @set -eu; \
686 cd "${MAKEFILE:tA:H}/../../.."; \
687 mi="distrib/sets/lists/tests/mi"; \
688 cvs update "$$mi"; \
689 testsdir="usr.bin/make/unit-tests"; \
690 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
691 cat "$$mi" > "$$mi.tmp"; \
692 (cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \
693 distrib/sets/fmt-list "$$mi.tmp"; \
694 mv "$$mi.tmp" "$$mi"; \
695 cvs diff "$$mi" || true
696
697 .if exists(${TEST_MAKE})
698 ${TESTS:=.rawout}: ${TEST_MAKE}
699 # in meta mode, we *know* if a target script is impacted
700 # by a makefile change.
701 .if ${.MAKE.MODE:Unormal:Mmeta} == ""
702 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
703 .endif
704 .endif
705
706 .-include <bsd.obj.mk>
707