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