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