Makefile revision 1.349 1 # $NetBSD: Makefile,v 1.349 2024/07/04 20:18:40 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
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-include-guard
200 TESTS+= directive-info
201 TESTS+= directive-misspellings
202 TESTS+= directive-sinclude
203 TESTS+= directive-undef
204 TESTS+= directive-unexport
205 TESTS+= directive-unexport-env
206 TESTS+= directive-warning
207 TESTS+= dollar
208 TESTS+= doterror
209 TESTS+= dotwait
210 TESTS+= error
211 TESTS+= # escape # broken by reverting POSIX changes
212 TESTS+= export
213 TESTS+= export-all
214 TESTS+= export-env
215 TESTS+= export-variants
216 TESTS+= gnode-submake
217 TESTS+= hanoi-include
218 TESTS+= impsrc
219 TESTS+= include-main
220 TESTS+= job-flags
221 TESTS+= job-output-long-lines
222 TESTS+= job-output-null
223 TESTS+= jobs-empty-commands
224 TESTS+= jobs-empty-commands-error
225 TESTS+= jobs-error-indirect
226 TESTS+= jobs-error-nested
227 TESTS+= jobs-error-nested-make
228 TESTS+= lint
229 TESTS+= make-exported
230 TESTS+= meta-cmd-cmp
231 TESTS+= moderrs
232 TESTS+= modmisc
233 .if ${.MAKE.UID} > 0
234 TESTS+= objdir-writable
235 .endif
236 TESTS+= opt
237 TESTS+= opt-backwards
238 TESTS+= opt-chdir
239 TESTS+= opt-debug
240 TESTS+= opt-debug-all
241 TESTS+= opt-debug-archive
242 TESTS+= opt-debug-curdir
243 TESTS+= opt-debug-cond
244 TESTS+= opt-debug-dir
245 TESTS+= opt-debug-errors
246 TESTS+= opt-debug-errors-jobs
247 TESTS+= opt-debug-file
248 TESTS+= opt-debug-for
249 TESTS+= opt-debug-graph1
250 TESTS+= opt-debug-graph2
251 TESTS+= opt-debug-graph3
252 TESTS+= opt-debug-hash
253 TESTS+= opt-debug-jobs
254 TESTS+= opt-debug-lint
255 TESTS+= opt-debug-loud
256 TESTS+= opt-debug-meta
257 TESTS+= opt-debug-making
258 TESTS+= opt-debug-no-rm
259 TESTS+= opt-debug-parse
260 TESTS+= opt-debug-suff
261 TESTS+= opt-debug-targets
262 TESTS+= opt-debug-varraw
263 TESTS+= opt-debug-var
264 TESTS+= opt-debug-x-trace
265 TESTS+= opt-define
266 TESTS+= opt-env
267 TESTS+= opt-file
268 TESTS+= opt-ignore
269 TESTS+= opt-include-dir
270 TESTS+= opt-jobs
271 TESTS+= opt-jobs-internal
272 TESTS+= opt-jobs-no-action
273 TESTS+= opt-keep-going
274 TESTS+= opt-keep-going-indirect
275 TESTS+= opt-keep-going-multiple
276 TESTS+= opt-m-include-dir
277 TESTS+= opt-no-action
278 TESTS+= opt-no-action-at-all
279 TESTS+= opt-no-action-runflags
280 TESTS+= opt-no-action-touch
281 TESTS+= opt-query
282 TESTS+= opt-raw
283 TESTS+= opt-silent
284 TESTS+= opt-touch
285 TESTS+= opt-touch-jobs
286 TESTS+= opt-tracefile
287 TESTS+= opt-var-expanded
288 TESTS+= opt-var-literal
289 TESTS+= opt-version
290 TESTS+= opt-warnings-as-errors
291 TESTS+= opt-where-am-i
292 TESTS+= opt-x-reduce-exported
293 TESTS+= order
294 TESTS+= parse
295 TESTS+= parse-var
296 TESTS+= phony-end
297 TESTS+= posix
298 TESTS+= # posix1 # broken by reverting POSIX changes
299 TESTS+= recursive
300 TESTS+= sh
301 TESTS+= sh-dots
302 TESTS+= sh-errctl
303 TESTS+= sh-flags
304 TESTS+= sh-jobs
305 TESTS+= sh-jobs-error
306 TESTS+= sh-leading-at
307 TESTS+= sh-leading-hyphen
308 TESTS+= sh-leading-plus
309 TESTS+= sh-meta-chars
310 TESTS+= sh-multi-line
311 TESTS+= sh-single-line
312 TESTS+= shell-csh
313 TESTS+= shell-custom
314 TESTS+= shell-ksh
315 TESTS+= shell-sh
316 TESTS+= suff-add-later
317 TESTS+= suff-clear-regular
318 TESTS+= suff-clear-single
319 TESTS+= suff-incomplete
320 TESTS+= suff-lookup
321 TESTS+= suff-main
322 TESTS+= suff-main-several
323 TESTS+= suff-phony
324 TESTS+= suff-rebuild
325 TESTS+= suff-self
326 TESTS+= suff-transform-debug
327 TESTS+= suff-transform-endless
328 TESTS+= suff-transform-expand
329 TESTS+= suff-transform-select
330 TESTS+= suff-use
331 TESTS+= sunshcmd
332 TESTS+= ternary
333 TESTS+= unexport
334 TESTS+= unexport-env
335 TESTS+= use-inference
336 TESTS+= var-readonly
337 TESTS+= var-scope
338 TESTS+= var-scope-cmdline
339 TESTS+= var-scope-env
340 TESTS+= var-scope-global
341 TESTS+= var-scope-local
342 TESTS+= var-scope-local-legacy
343 TESTS+= var-eval-short
344 TESTS+= var-op
345 TESTS+= var-op-append
346 TESTS+= var-op-assign
347 TESTS+= var-op-default
348 TESTS+= var-op-expand
349 TESTS+= var-op-shell
350 TESTS+= var-op-sunsh
351 TESTS+= var-recursive
352 TESTS+= varcmd
353 TESTS+= vardebug
354 TESTS+= varfind
355 TESTS+= varmisc
356 TESTS+= varmod
357 TESTS+= varmod-assign
358 TESTS+= varmod-assign-shell
359 TESTS+= varmod-defined
360 TESTS+= varmod-edge
361 TESTS+= varmod-exclam-shell
362 TESTS+= varmod-extension
363 TESTS+= varmod-gmtime
364 TESTS+= varmod-hash
365 TESTS+= varmod-head
366 TESTS+= varmod-ifelse
367 TESTS+= varmod-indirect
368 TESTS+= varmod-l-name-to-value
369 TESTS+= varmod-localtime
370 TESTS+= varmod-loop
371 TESTS+= varmod-loop-delete
372 TESTS+= varmod-loop-varname
373 TESTS+= varmod-match
374 TESTS+= varmod-match-escape
375 TESTS+= varmod-mtime
376 TESTS+= varmod-no-match
377 TESTS+= varmod-order
378 TESTS+= varmod-order-numeric
379 TESTS+= varmod-order-reverse
380 TESTS+= varmod-order-shuffle
381 TESTS+= varmod-order-string
382 TESTS+= varmod-path
383 TESTS+= varmod-quote
384 TESTS+= varmod-quote-dollar
385 TESTS+= varmod-range
386 TESTS+= varmod-remember
387 TESTS+= varmod-root
388 TESTS+= varmod-select-words
389 TESTS+= varmod-shell
390 TESTS+= varmod-subst
391 TESTS+= varmod-subst-regex
392 TESTS+= varmod-sun-shell
393 TESTS+= varmod-sysv
394 TESTS+= varmod-tail
395 TESTS+= varmod-to-abs
396 TESTS+= varmod-to-lower
397 TESTS+= varmod-to-many-words
398 TESTS+= varmod-to-one-word
399 TESTS+= varmod-to-separator
400 TESTS+= varmod-to-title
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.directive-include-guard= \
510 -e '/\.MAKEFLAGS/d' \
511 -e '/^Parsing line/d' \
512 -e '/^SetFilenameVars:/d' \
513 -e '/^ParseDependency/d' \
514 -e '/^ParseEOF:/d'
515 SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d'
516 SED_CMDS.export-all= ${SED_CMDS.export}
517 SED_CMDS.export-env= ${SED_CMDS.export}
518 SED_CMDS.job-output-long-lines= \
519 ${:D Job separators on their own line are ok. } \
520 -e '/^--- job-[ab] ---$$/d' \
521 ${:D Plain output lines are ok as well. } \
522 ${:D They may come in multiples of 1024 or as 10000. } \
523 -e '/^aa*$$/d' \
524 -e '/^bb*$$/d' \
525 ${:D The following lines should rather not occur since the job } \
526 ${:D marker should always be at the beginning of the line. } \
527 -e '/^aa*--- job-b ---$$/d' \
528 -e '/^bb*--- job-a ---$$/d'
529
530 # meta line numbers can vary based on filemon implementation
531 SED_CMDS.meta-ignore= -e 's,\(\.meta:\) [1-9][0-9]*:,\1 <line>:,'
532
533 SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,'
534 SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1}
535 SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2}
536 SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3}
537 SED_CMDS.opt-debug-hash= -e 's,\(numEntries\)=[1-9][0-9],\1=<entries>,'
538 SED_CMDS.opt-debug-jobs= -e 's,([0-9][0-9]*),(<pid>),'
539 SED_CMDS.opt-debug-jobs+= -e 's,pid [0-9][0-9]*,pid <pid>,'
540 SED_CMDS.opt-debug-jobs+= -e 's,Process [0-9][0-9]*,Process <pid>,'
541 SED_CMDS.opt-debug-jobs+= -e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
542 SED_CMDS.opt-debug-jobs+= -e 's,Command: ${.SHELL:T},Command: <shell>,'
543 # The "-q" may be there or not, see jobs.c, variable shells.
544 SED_CMDS.opt-debug-jobs+= -e 's,^\(.Command: <shell>\) -q,\1,'
545 SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex}
546 SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output}
547 SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
548 SED_CMDS.opt-where-am-i= -e '/usr.obj/d'
549 # For Compat_RunCommand, useShell == false.
550 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,'
551 # For Compat_RunCommand, useShell == true.
552 SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
553 SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
554 SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj}
555 SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output}
556 SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell}
557 SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1}
558 SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1}
559 SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1}
560 SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell}
561 SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,'
562 SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
563 SED_CMDS.varmod-mtime+= -e "s,\(.*\)': .*,\1': <ENOENT>,"
564 SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex}
565 SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp}
566 SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore}
567 SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore}
568 SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore}
569 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
570 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
571 SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g'
572 SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g'
573 SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g'
574 SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@}
575
576 # Some tests need an additional round of postprocessing.
577 POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,'
578 POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/'
579 POSTPROC.gnode-submake= awk '/Input graph/, /^$$/'
580 POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,'
581
582 # Some tests reuse other tests, which makes them unnecessarily fragile.
583 export-all.rawout: export.mk
584 unexport.rawout: export.mk
585 unexport-env.rawout: export.mk
586
587 # End of the configuration section.
588
589 # Some standard sed commands, to be used in the SED_CMDS above.
590
591 # In tests that use the debugging option -dd, ignore debugging output that is
592 # only logged in -DCLEANUP mode.
593 STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d'
594 STD_SED_CMDS.dd+= -e '/^CachedDir /d'
595 STD_SED_CMDS.dd+= -e 's, ${DEFSYSPATH:U/usr/share/mk} , <defsyspath> ,'
596
597 # Omit details such as process IDs from the output of the -dg1 option.
598 STD_SED_CMDS.dg1= -e 's,${.CURDIR}$$,<curdir>,'
599 STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,'
600 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
601 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
602 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,'
603 STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
604 STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
605 STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
606 STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d'
607
608 STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1}
609 STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'
610 STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2}
611
612 # Omit details such as process IDs from the output of the -dj option.
613 STD_SED_CMDS.dj= \
614 -e '/Process/d;/JobFinish:/d' \
615 -e 's,^\(Job_TokenWithdraw\)([0-9]*),\1(<pid>),' \
616 -e 's,^([0-9][0-9]*) \(withdrew token\),(<pid>) \1,' \
617 -e 's, \(pid\) [0-9][0-9]*, \1 <pid>,' \
618 -e 's,^\( Command:\) .*,\1 <shell>,'
619
620 # Reduce the noise for tests running with the -n option, since there is no
621 # other way to suppress the echoing of the commands.
622 STD_SED_CMDS.hide-from-output= \
623 -e '/^echo hide-from-output/d' \
624 -e 's,hide-from-output ,,' \
625 -e 's,hide-from-output,,'
626
627 # Normalize the output for error messages from the shell.
628 #
629 # $shell -c '...'
630 # NetBSD sh ...: not found
631 # NetBSD ksh ksh: ...: not found
632 # bash 5.0.18 bash: ...: command not found
633 # bash 5.1.0 bash: line 1: ...: command not found
634 # dash dash: 1: ...: not found
635 #
636 # $shell -c '< /nonexistent'
637 # NetBSD sh sh: cannot open /nonexistent: no such file
638 # NetBSD ksh ksh: cannot open /nonexistent: No such file or directory
639 # bash 5.0.18 bash: /nonexistent: No such file or directory
640 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
641 # dash dash: 1: cannot open /nonexistent: No such file
642 #
643 # echo '< /nonexistent' | $shell
644 # NetBSD sh sh: cannot open /nonexistent: no such file
645 # NetBSD ksh ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory
646 # bash 5.0.18 bash: line 1: /nonexistent: No such file or directory
647 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
648 # dash dash: 1: cannot open /nonexistent: No such file
649 #
650 STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},'
651 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
652 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
653 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,'
654 STD_SED_CMDS.shell+= -e 's,: command not found,: not found,'
655
656 # The actual error messages for a failed regcomp or regexec differ between the
657 # implementations.
658 STD_SED_CMDS.regex= \
659 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
660
661 # Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'.
662 # See STD_SED_CMDS.dg2 for timestamps from the debug log.
663 STD_SED_CMDS.timestamp= \
664 -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>,'
665
666 # End of the configuration helpers section.
667
668 UNIT_TESTS:= ${.PARSEDIR}
669 .PATH: ${UNIT_TESTS}
670
671 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
672 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@}
673 .else
674 OUTFILES= ${TESTS:=.out}
675 .endif
676
677 all: ${OUTFILES}
678
679 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
680 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
681 CLEANFILES+= issue* .[ab]* # suffixes.mk
682 CLEANDIRS= dir dummy *.tmp # posix1.mk
683
684 clean:
685 rm -rf ${CLEANDIRS}
686 rm -f ${CLEANFILES}
687
688 TEST_MAKE?= ${.MAKE}
689 TOOL_SED?= sed
690
691 # ensure consistent results from sort(1)
692 LC_ALL= C
693 LANG= C
694 .export LANG LC_ALL
695
696 # Some Linux systems such as Fedora have deprecated egrep in favor of grep -E.
697 .if ${.MAKE.OS:NLinux} == ""
698 EGREP= grep -E
699 .endif
700 # Keep the classical definition for all other systems. Just as the bmake code
701 # is kept compatible with C90, the tests are kept compatible with systems that
702 # are several decades old and don't follow modern POSIX standards.
703 EGREP?= egrep
704
705 MAKE_TEST_ENV= EGREP="${EGREP}"
706 MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100
707 MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510
708 MAKE_TEST_ENV+= TMPDIR=${TMPDIR}
709
710 .if ${.MAKE.OS} == "NetBSD"
711 LIMIT_RESOURCES?= ulimit -v 300000
712 .endif
713 LIMIT_RESOURCES?= :
714
715 # Each test is run in a sub-make, to keep the tests from interfering with
716 # each other, and because they use different environment variables and
717 # command line options.
718 .SUFFIXES: .mk .rawout .out
719 .mk.rawout:
720 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
721 @set -eu; \
722 ${LIMIT_RESOURCES}; \
723 cd ${.OBJDIR}; \
724 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
725 ${TEST_MAKE} \
726 -r -C ${.CURDIR} -f ${.IMPSRC} \
727 ${FLAGS.${.PREFIX:T}:U-k} \
728 > ${.TARGET}.tmp 2>&1 \
729 && status=$$? || status=$$?; \
730 echo $$status > ${.TARGET:R}.status
731 @mv ${.TARGET}.tmp ${.TARGET}
732
733 # Postprocess the test output to make the output platform-independent.
734 #
735 # Replace anything after 'stopped in' with unit-tests
736 _SED_CMDS+= -e '/stopped/s, in /.*, in unit-tests,'
737 # Allow the test files to be placed anywhere.
738 _SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
739 _SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
740 _SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g'
741 # canonicalize ${.OBJDIR} and ${.CURDIR}
742 _SED_CMDS+= -e 's,${.CURDIR},<curdir>,g'
743 .if ${.OBJDIR} != ${.CURDIR}
744 # yes this is inaccurate but none of the tests expect <objdir> anywhere
745 # which we get depending on how MAKEOBJDIR is set.
746 _SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g'
747 .endif
748 # always pretend .MAKE was called 'make'
749 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
750 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
751 _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
752 _SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\]:\),make\1,'
753 _SED_CMDS+= -e 's,<curdir>/,,g'
754 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
755 _SED_CMDS+= -e '/MAKE_VERSION/d'
756 _SED_CMDS+= -e '/EGREP=/d'
757
758 .rawout.out:
759 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
760 < ${.IMPSRC} > ${.TARGET}.tmp1
761 @${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
762 @rm ${.TARGET}.tmp1
763 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
764 @mv ${.TARGET}.tmp2 ${.TARGET}
765
766 # Compare all output files
767 test: ${OUTFILES} .PHONY
768 @failed= ; \
769 for test in ${TESTS}; do \
770 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
771 || failed="$${failed}$${failed:+ }$${test}" ; \
772 done ; \
773 if [ -n "$${failed}" ]; then \
774 echo "Failed tests: $${failed}" ; false ; \
775 else \
776 echo "All tests passed" ; \
777 lua=${LUA:Ulua} ; \
778 have_lua=$$("$$lua" -e 'print "yes"' 2>&1) ; \
779 if [ "$$have_lua" = "yes" ]; then \
780 (cd ${.CURDIR} && "$$lua" ./check-expect.lua *.mk); \
781 fi; \
782 fi
783
784 accept:
785 @for test in ${TESTS}; do \
786 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
787 || { echo "Replacing $${test}.exp" ; \
788 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
789 done
790
791 # Note: only works for adding tests.
792 # To remove a test, the $$mi file must be edited manually.
793 sync-mi:
794 @set -eu; \
795 cd "${MAKEFILE:tA:H}/../../.."; \
796 mi="distrib/sets/lists/tests/mi"; \
797 cvs update "$$mi"; \
798 testsdir="usr.bin/make/unit-tests"; \
799 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
800 cat "$$mi" > "$$mi.tmp"; \
801 (cd "$$testsdir" && egrep '\.(exp|mk)/' CVS/Entries | cut -d/ -f2) | \
802 xargs printf "$$fmt" >> "$$mi.tmp"; \
803 distrib/sets/fmt-list "$$mi.tmp"; \
804 mv "$$mi.tmp" "$$mi"; \
805 cvs diff "$$mi" || true
806
807 .if exists(${TEST_MAKE})
808 ${TESTS:=.rawout}: ${TEST_MAKE}
809 # in meta mode, we *know* if a target script is impacted
810 # by a makefile change.
811 .if ${.MAKE.MODE:Unormal:Mmeta} == ""
812 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
813 .endif
814 .endif
815
816 .-include <bsd.obj.mk>
817