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