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