Makefile revision 1.362 1 # $NetBSD: Makefile,v 1.362 2025/05/09 21:38:34 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, 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+= posix-execution
304 TESTS+= posix-expansion
305 TESTS+= posix-varassign
306 TESTS+= # posix1 # broken by reverting POSIX changes
307 TESTS+= recursive
308 TESTS+= sh
309 TESTS+= sh-dots
310 TESTS+= sh-errctl
311 TESTS+= sh-flags
312 TESTS+= sh-jobs
313 TESTS+= sh-jobs-error
314 TESTS+= sh-leading-at
315 TESTS+= sh-leading-hyphen
316 TESTS+= sh-leading-plus
317 TESTS+= sh-meta-chars
318 TESTS+= sh-multi-line
319 TESTS+= sh-single-line
320 TESTS+= shell-csh
321 TESTS+= shell-custom
322 TESTS+= shell-ksh
323 TESTS+= shell-sh
324 TESTS+= suff
325 TESTS+= suff-add-later
326 TESTS+= suff-clear-regular
327 TESTS+= suff-clear-single
328 TESTS+= suff-incomplete
329 TESTS+= suff-lookup
330 TESTS+= suff-main
331 TESTS+= suff-main-several
332 TESTS+= suff-phony
333 TESTS+= suff-rebuild
334 TESTS+= suff-self
335 TESTS+= suff-transform-debug
336 TESTS+= suff-transform-endless
337 TESTS+= suff-transform-expand
338 TESTS+= suff-transform-select
339 TESTS+= suff-use
340 TESTS+= sunshcmd
341 TESTS+= ternary
342 TESTS+= unexport
343 TESTS+= unexport-env
344 TESTS+= use-inference
345 TESTS+= var-readonly
346 TESTS+= var-scope
347 TESTS+= var-scope-cmdline
348 TESTS+= var-scope-env
349 TESTS+= var-scope-global
350 TESTS+= var-scope-local
351 TESTS+= var-scope-local-legacy
352 TESTS+= var-eval-short
353 TESTS+= var-op
354 TESTS+= var-op-append
355 TESTS+= var-op-assign
356 TESTS+= var-op-default
357 TESTS+= var-op-expand
358 TESTS+= var-op-shell
359 TESTS+= var-op-sunsh
360 TESTS+= var-recursive
361 TESTS+= varcmd
362 TESTS+= vardebug
363 TESTS+= varfind
364 TESTS+= varmisc
365 TESTS+= varmod
366 TESTS+= varmod-assign
367 TESTS+= varmod-assign-shell
368 TESTS+= varmod-defined
369 TESTS+= varmod-edge
370 TESTS+= varmod-exclam-shell
371 TESTS+= varmod-extension
372 TESTS+= varmod-gmtime
373 TESTS+= varmod-hash
374 TESTS+= varmod-head
375 TESTS+= varmod-ifelse
376 TESTS+= varmod-indirect
377 TESTS+= varmod-l-name-to-value
378 TESTS+= varmod-localtime
379 TESTS+= varmod-loop
380 TESTS+= varmod-loop-delete
381 TESTS+= varmod-loop-varname
382 TESTS+= varmod-match
383 TESTS+= varmod-match-escape
384 TESTS+= varmod-mtime
385 TESTS+= varmod-no-match
386 TESTS+= varmod-order
387 TESTS+= varmod-order-numeric
388 TESTS+= varmod-order-reverse
389 TESTS+= varmod-order-shuffle
390 TESTS+= varmod-order-string
391 TESTS+= varmod-path
392 TESTS+= varmod-quote
393 TESTS+= varmod-quote-dollar
394 TESTS+= varmod-range
395 TESTS+= varmod-remember
396 TESTS+= varmod-root
397 TESTS+= varmod-select-words
398 TESTS+= varmod-shell
399 TESTS+= varmod-subst
400 TESTS+= varmod-subst-regex
401 TESTS+= varmod-sun-shell
402 TESTS+= varmod-sysv
403 TESTS+= varmod-tail
404 TESTS+= varmod-to-abs
405 TESTS+= varmod-to-lower
406 TESTS+= varmod-to-many-words
407 TESTS+= varmod-to-one-word
408 TESTS+= varmod-to-separator
409 TESTS+= varmod-to-title
410 TESTS+= varmod-to-upper
411 TESTS+= varmod-undefined
412 TESTS+= varmod-unique
413 TESTS+= varname
414 TESTS+= varname-dollar
415 TESTS+= varname-dot-alltargets
416 TESTS+= varname-dot-curdir
417 TESTS+= varname-dot-includes
418 TESTS+= varname-dot-includedfromdir
419 TESTS+= varname-dot-includedfromfile
420 TESTS+= varname-dot-libs
421 TESTS+= varname-dot-make-dependfile
422 TESTS+= varname-dot-make-expand_variables
423 TESTS+= varname-dot-make-exported
424 TESTS+= varname-dot-make-jobs
425 TESTS+= varname-dot-make-jobs-prefix
426 TESTS+= varname-dot-make-level
427 TESTS+= varname-dot-make-makefile_preference
428 TESTS+= varname-dot-make-makefiles
429 TESTS+= varname-dot-make-meta-bailiwick
430 TESTS+= varname-dot-make-meta-created
431 TESTS+= varname-dot-make-meta-files
432 .if ${.MAKE.PATH_FILEMON:Uno:Nktrace:N/dev*} == "" && ${TMPDIR:N/tmp*:N/var/tmp*} != ""
433 # these tests will not work if TMPDIR is or is a subdir of
434 # /tmp or /var/tmp
435 TESTS+= varname-dot-make-meta-ignore_filter
436 TESTS+= varname-dot-make-meta-ignore_paths
437 TESTS+= varname-dot-make-meta-ignore_patterns
438 TESTS+= varname-dot-make-path_filemon
439 .endif
440 TESTS+= varname-dot-make-meta-prefix
441 TESTS+= varname-dot-make-mode
442 TESTS+= varname-dot-make-pid
443 TESTS+= varname-dot-make-ppid
444 TESTS+= varname-dot-make-save_dollars
445 TESTS+= varname-dot-makeflags
446 TESTS+= varname-dot-makeoverrides
447 TESTS+= varname-dot-newline
448 TESTS+= varname-dot-objdir
449 TESTS+= varname-dot-parsedir
450 TESTS+= varname-dot-parsefile
451 TESTS+= varname-dot-path
452 TESTS+= varname-dot-shell
453 TESTS+= varname-dot-suffixes
454 TESTS+= varname-dot-targets
455 TESTS+= varname-empty
456 TESTS+= varname-make
457 TESTS+= varname-make_print_var_on_error
458 TESTS+= varname-make_print_var_on_error-jobs
459 TESTS+= varname-makefile
460 TESTS+= varname-makeflags
461 TESTS+= varname-pwd
462 TESTS+= varname-vpath
463 TESTS+= varparse-dynamic
464 TESTS+= varparse-errors
465 TESTS+= varparse-mod
466 TESTS+= varparse-undef-partial
467
468 # Some tests just do not work on some platforms or environments
469 # so allow for some filtering.
470 .if !empty(BROKEN_TESTS)
471 TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}}
472 .endif
473
474 # Ideas for more tests:
475 # char-0020-space.mk
476 # char-005C-backslash.mk
477 # escape-cond-str.mk
478 # escape-cond-func-arg.mk
479 # escape-varmod.mk
480 # escape-varmod-define.mk
481 # escape-varmod-match.mk
482 # escape-varname.mk
483 # escape-varassign-varname.mk
484 # escape-varassign-varname-cmdline.mk
485 # escape-varassign-value.mk
486 # escape-varassign-value-cmdline.mk
487 # escape-dependency-source.mk
488 # escape-dependency-target.mk
489 # escape-for-varname.mk
490 # escape-for-item.mk
491 # posix-*.mk (see posix.mk and posix1.mk)
492
493 # Additional environment variables for some of the tests.
494 # The base environment is -i PATH="$PATH".
495 ENV.depsrc-optional+= TZ=UTC
496 ENV.directive-undef= ENV_VAR=env-value
497 ENV.opt-env= FROM_ENV=value-from-env
498 ENV.opt-m-include-dir= ${MAKEOBJDIR:DMAKEOBJDIR=${MAKEOBJDIR}}
499 ENV.varmisc= FROM_ENV=env
500 ENV.varmisc+= FROM_ENV_BEFORE=env
501 ENV.varmisc+= FROM_ENV_AFTER=env
502 ENV.varmod-localtime+= TZ=Europe/Berlin
503 ENV.varname-vpath+= VPATH=varname-vpath.dir:varname-vpath.dir2
504
505 # Override make flags for some of the tests; default is -k.
506 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
507 # settings FLAGS.test=-dv here, since that is closer to the test code.
508 FLAGS.cond-func-make= via-cmdline
509 FLAGS.doterror= # none, especially not -k
510 FLAGS.jobs-error-indirect= # none, especially not -k
511 FLAGS.jobs-error-nested= # none, especially not -k
512 FLAGS.jobs-error-nested-make= # none, especially not -k
513 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmdline-plain'
514
515 # Some tests need extra postprocessing.
516 SED_CMDS.deptgt-phony= ${STD_SED_CMDS.dd}
517 SED_CMDS.dir= ${STD_SED_CMDS.dd}
518 SED_CMDS.directive-include-guard= \
519 -e '/\.MAKEFLAGS/d' \
520 -e '/^Parsing .*:[1-9][0-9]*:/d' \
521 -e '/^SetFilenameVars:/d' \
522 -e '/^ParseDependency/d' \
523 -e '/^ParseEOF:/d'
524 SED_CMDS.export= -e '/^[^=_A-Za-z0-9]*=/d'
525 SED_CMDS.export-all= ${SED_CMDS.export}
526 SED_CMDS.export-env= ${SED_CMDS.export}
527 SED_CMDS.job-output-long-lines= \
528 ${:D Job separators on their own line are ok. } \
529 -e '/^--- job-[ab] ---$$/d' \
530 ${:D Plain output lines are ok as well. } \
531 ${:D They may come in multiples of 1024 or as 10000. } \
532 -e '/^aa*$$/d' \
533 -e '/^bb*$$/d' \
534 ${:D The following lines should rather not occur since the job } \
535 ${:D marker should always be at the beginning of the line. } \
536 -e '/^aa*--- job-b ---$$/d' \
537 -e '/^bb*--- job-a ---$$/d'
538
539 # meta line numbers can vary based on filemon implementation
540 SED_CMDS.meta-ignore= -e 's,\(\.meta:\)[1-9][0-9]*:,\1<line>:,'
541
542 SED_CMDS.opt-chdir= -e 's,\(nonexistent\).[1-9][0-9]*,\1,'
543 SED_CMDS.opt-debug-graph1= ${STD_SED_CMDS.dg1}
544 SED_CMDS.opt-debug-graph2= ${STD_SED_CMDS.dg2}
545 SED_CMDS.opt-debug-graph3= ${STD_SED_CMDS.dg3}
546 SED_CMDS.opt-debug-hash= -e 's,\(entries\)=[1-9][0-9],\1=<entries>,'
547 SED_CMDS.opt-debug-jobs= ${STD_SED_CMDS.dj}
548 SED_CMDS.opt-debug-lint+= ${STD_SED_CMDS.regex}
549 SED_CMDS.opt-jobs-no-action= ${STD_SED_CMDS.hide-from-output}
550 SED_CMDS.opt-no-action-runflags= ${STD_SED_CMDS.hide-from-output}
551 SED_CMDS.opt-where-am-i= -e '/usr.obj/d'
552 # For Compat_RunCommand, useShell == false.
553 SED_CMDS.sh-dots= -e 's,^.*\.\.\.:.*,<not found: ...>,'
554 # For Compat_RunCommand, useShell == true.
555 SED_CMDS.sh-dots+= -e 's,^make: exec(\(.*\)) failed (.*)$$,<not found: \1>,'
556 SED_CMDS.sh-dots+= -e 's,^\(\*\*\* Error code \)[1-9][0-9]*,\1<nonzero>,'
557 SED_CMDS.sh-errctl= ${STD_SED_CMDS.dj}
558 SED_CMDS.sh-flags= ${STD_SED_CMDS.hide-from-output}
559 SED_CMDS.sh-leading-hyphen= ${STD_SED_CMDS.shell}
560 SED_CMDS.suff-main+= ${STD_SED_CMDS.dg1}
561 SED_CMDS.suff-main-several+= ${STD_SED_CMDS.dg1}
562 SED_CMDS.suff-transform-debug+= ${STD_SED_CMDS.dg1}
563 SED_CMDS.var-op-shell+= ${STD_SED_CMDS.shell}
564 SED_CMDS.var-op-shell+= -e '/command/s,No such.*,not found,'
565 SED_CMDS.vardebug+= -e 's,${.SHELL},</path/to/shell>,'
566 SED_CMDS.varmod-mtime+= -e "s,\(.*\)': .*,\1': <ENOENT>,"
567 SED_CMDS.varmod-subst-regex+= ${STD_SED_CMDS.regex}
568 SED_CMDS.varparse-errors+= ${STD_SED_CMDS.timestamp}
569 SED_CMDS.varname-dot-make-meta-ignore_filter+= ${SED_CMDS.meta-ignore}
570 SED_CMDS.varname-dot-make-meta-ignore_paths+= ${SED_CMDS.meta-ignore}
571 SED_CMDS.varname-dot-make-meta-ignore_patterns+= ${SED_CMDS.meta-ignore}
572 SED_CMDS.varname-dot-parsedir= -e '/in some cases/ s,^make: [^:]*:,make: <normalized>:,'
573 SED_CMDS.varname-dot-parsefile= -e '/in some cases/ s,^make: [^:]*:,make: <normalized>:,'
574 SED_CMDS.varname-dot-shell= -e 's, = /[^ ]*, = (details omitted),g'
575 SED_CMDS.varname-dot-shell+= -e 's,"/[^" ]*","(details omitted)",g'
576 SED_CMDS.varname-dot-shell+= -e 's,\[/[^] ]*\],[(details omitted)],g'
577 SED_CMDS.varname-empty= ${.OBJDIR .PARSEDIR .PATH .SHELL .SYSPATH:L:@v@-e '/\\$v/d'@}
578
579 # Some tests need an additional round of postprocessing.
580 POSTPROC.depsrc-wait= sed -e '/^---/d' -e 's,^\(: Making 3[abc]\)[123]$$,\1,'
581 POSTPROC.deptgt-suffixes= awk '/^\#\*\*\* Suffixes/,/^never-stop/'
582 POSTPROC.gnode-submake= awk '/Begin input graph/, /^$$/'
583 POSTPROC.varname-dot-make-mode= sed 's,^\(: Making [abc]\)[123]$$,\1,'
584
585 # Some tests reuse other tests, which makes them unnecessarily fragile.
586 export-all.rawout: export.mk
587 unexport.rawout: export.mk
588 unexport-env.rawout: export.mk
589
590 # End of the configuration section.
591
592 # Some standard sed commands, to be used in the SED_CMDS above.
593
594 # In tests that use the debugging option -dd, ignore debugging output that is
595 # only logged in -DCLEANUP mode.
596 STD_SED_CMDS.dd= -e '/^OpenDirs_Done:/d'
597 STD_SED_CMDS.dd+= -e '/^CachedDir /d'
598 STD_SED_CMDS.dd+= -e 's, ${DEFSYSPATH:U/usr/share/mk} , <defsyspath> ,'
599
600 # Omit details such as process IDs from the output of the -dg1 option.
601 STD_SED_CMDS.dg1= -e 's,${.CURDIR}$$,<curdir>,'
602 STD_SED_CMDS.dg1+= -e 's, ${DEFSYSPATH:U/usr/share/mk}$$, <defsyspath>,'
603 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
604 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
605 STD_SED_CMDS.dg1+= -e 's,^\(\.MAKE\.JOBS\.C *=\) .*,\1 <details omitted>,'
606 STD_SED_CMDS.dg1+= -e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
607 STD_SED_CMDS.dg1+= -e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
608 STD_SED_CMDS.dg1+= -e 's,^\(\.SHELL *=\) .*,\1 <details omitted>,'
609 STD_SED_CMDS.dg1+= -e '/\.SYSPATH/d'
610
611 STD_SED_CMDS.dg2= ${STD_SED_CMDS.dg1}
612 STD_SED_CMDS.dg2+= -e 's,\(last modified\) ..:..:.. ... ..\, ....,\1 <timestamp>,'
613 STD_SED_CMDS.dg3= ${STD_SED_CMDS.dg2}
614
615 # Omit details such as process IDs from the output of the -dj option.
616 STD_SED_CMDS.dj= -e 's, pid [0-9][0-9]*, pid <pid>,'
617 STD_SED_CMDS.dj+= -e 's,^\(.Command\): ${.SHELL:T},\1: <shell>,'
618 # The "-q" may be there or not, see jobs.c, variable shells.
619 STD_SED_CMDS.dj+= -e 's,^\(.Command: <shell>\) -q,\1,'
620
621 # Reduce the noise for tests running with the -n option, since there is no
622 # other way to suppress the echoing of the commands.
623 STD_SED_CMDS.hide-from-output= \
624 -e '/^echo hide-from-output/d' \
625 -e 's,hide-from-output ,,' \
626 -e 's,hide-from-output,,'
627
628 # Normalize the output for error messages from the shell.
629 #
630 # $shell -c '...'
631 # NetBSD sh ...: not found
632 # NetBSD ksh ksh: ...: not found
633 # bash 5.0.18 bash: ...: command not found
634 # bash 5.1.0 bash: line 1: ...: command not found
635 # dash dash: 1: ...: not found
636 #
637 # $shell -c '< /nonexistent'
638 # NetBSD sh sh: cannot open /nonexistent: no such file
639 # NetBSD ksh ksh: cannot open /nonexistent: No such file or directory
640 # bash 5.0.18 bash: /nonexistent: No such file or directory
641 # bash 5.1.0 bash: line 1: /nonexistent: No such file or directory
642 # dash dash: 1: cannot open /nonexistent: No such file
643 #
644 # echo '< /nonexistent' | $shell
645 # NetBSD sh sh: cannot open /nonexistent: no such file
646 # NetBSD ksh ksh: <stdin>[1]: cannot open /nonexistent: No such file or directory
647 # bash 5.0.18 bash: line 1: /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 STD_SED_CMDS.shell+= -e 's,^${.SHELL},${.SHELL:T},'
652 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: line [0-9][0-9]*: ,,'
653 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: [0-9][0-9]*: ,,'
654 STD_SED_CMDS.shell+= -e 's,^${.SHELL:T}: ,,'
655 STD_SED_CMDS.shell+= -e 's,: command not found,: not found,'
656
657 # The actual error messages for a failed regcomp or regexec differ between the
658 # implementations.
659 STD_SED_CMDS.regex= \
660 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
661
662 # Normalize timestamps from ':gmtime' or ':localtime' to '<timestamp>'.
663 # See STD_SED_CMDS.dg2 for timestamps from the debug log.
664 STD_SED_CMDS.timestamp= \
665 -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>,'
666
667 # End of the configuration helpers section.
668
669 UNIT_TESTS:= ${.PARSEDIR}
670 .PATH: ${UNIT_TESTS}
671
672 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
673 OUTFILES= ${TESTS:@test@${.CURDIR:tA}/${test}.out@}
674 .else
675 OUTFILES= ${TESTS:=.out}
676 .endif
677
678 all: ${OUTFILES}
679
680 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
681 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
682 CLEANFILES+= issue* .[ab]* # suffixes.mk
683 CLEANDIRS= dir dummy *.tmp # posix1.mk
684
685 clean:
686 rm -rf ${CLEANDIRS}
687 rm -f ${CLEANFILES}
688
689 TEST_MAKE?= ${.MAKE}
690 TOOL_SED?= sed
691
692 # ensure consistent results from sort(1)
693 LC_ALL= C
694 LANG= C
695 .export LANG LC_ALL
696
697 # Some Linux systems such as Fedora have deprecated egrep in favor of grep -E.
698 .if ${.MAKE.OS:NLinux} == ""
699 EGREP= grep -E
700 .endif
701 # Keep the classical definition for all other systems. Just as the bmake code
702 # is kept compatible with C90, the tests are kept compatible with systems that
703 # are several decades old and don't follow modern POSIX standards.
704 EGREP?= egrep
705
706 MAKE_TEST_ENV= EGREP="${EGREP}"
707 MAKE_TEST_ENV+= MALLOC_OPTIONS="JA" # for jemalloc 100
708 MAKE_TEST_ENV+= MALLOC_CONF="junk:true" # for jemalloc 510
709 MAKE_TEST_ENV+= TMPDIR=${TMPDIR}
710
711 .if ${.MAKE.OS} == "NetBSD"
712 LIMIT_RESOURCES?= ulimit -v 300000
713 .endif
714 LIMIT_RESOURCES?= :
715
716 # Each test is run in a sub-make, to keep the tests from interfering with
717 # each other, and because they use different environment variables and
718 # command line options.
719 .SUFFIXES: .mk .rawout .out
720 .mk.rawout:
721 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
722 @set -eu; \
723 ${LIMIT_RESOURCES}; \
724 cd ${.OBJDIR}; \
725 env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
726 ${TEST_MAKE} \
727 -r -C ${.CURDIR} -f ${.IMPSRC} \
728 ${FLAGS.${.PREFIX:T}:U-k} \
729 > ${.TARGET}.tmp 2>&1 \
730 && status=$$? || status=$$?; \
731 echo $$status > ${.TARGET:R}.status
732 @mv ${.TARGET}.tmp ${.TARGET}
733
734 # Postprocess the test output to make the output platform-independent.
735 #
736 # Replace anything after 'stopped in' with unit-tests
737 _SED_CMDS+= -e '/stopped/s, in /.*, in unit-tests,'
738 # Allow the test files to be placed anywhere.
739 _SED_CMDS+= -e 's,\(\.PARSEDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
740 _SED_CMDS+= -e 's,\(\.INCLUDEDFROMDIR}\) = `'"/[^']*'"',\1 = <some-dir>,'
741 _SED_CMDS+= -e 's,${TMPDIR},<tmpdir>,g' -e 's,${TMPDIR:tA},<tmpdir>,g'
742 # canonicalize ${.OBJDIR} and ${.CURDIR}
743 _SED_CMDS+= -e 's,${.CURDIR},<curdir>,g'
744 .if ${.OBJDIR} != ${.CURDIR}
745 # yes this is inaccurate but none of the tests expect <objdir> anywhere
746 # which we get depending on how MAKEOBJDIR is set.
747 _SED_CMDS+= -e 's,${.OBJDIR},<curdir>,g' -e 's,${.OBJDIR:tA},<curdir>,g'
748 .endif
749 # always pretend .MAKE was called 'make'
750 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
751 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
752 _SED_CMDS+= -e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
753 _SED_CMDS+= -e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\]:\),make\1,'
754 _SED_CMDS+= -e 's,<curdir>/,,g'
755 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
756 _SED_CMDS+= -e '/MAKE_VERSION/d'
757 _SED_CMDS+= -e '/EGREP=/d'
758
759 .rawout.out:
760 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
761 < ${.IMPSRC} > ${.TARGET}.tmp
762 @${POSTPROC.${.PREFIX:T}:D \
763 ${POSTPROC.${.PREFIX:T}} < ${.TARGET}.tmp > ${.TARGET}.post \
764 && mv ${.TARGET}.post ${.TARGET}.tmp}
765 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
766 @mv ${.TARGET}.tmp ${.TARGET}
767
768 # Compare all output files
769 test: ${OUTFILES} .PHONY
770 @failed= ; \
771 for test in ${TESTS}; do \
772 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
773 || failed="$${failed}$${failed:+ }$${test}" ; \
774 done ; \
775 if [ -n "$${failed}" ]; then \
776 echo "Failed tests: $${failed}" ; false ; \
777 else \
778 echo "All tests passed" ; \
779 lua=${LUA:Ulua} ; \
780 have_lua=$$("$$lua" -e 'print "yes"' 2>&1) ; \
781 if [ "$$have_lua" = "yes" ]; then \
782 (cd ${.CURDIR} && "$$lua" ./check-expect.lua *.mk); \
783 fi; \
784 fi
785
786 accept:
787 @for test in ${TESTS}; do \
788 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
789 || { echo "Replacing $${test}.exp" ; \
790 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
791 done
792
793 # Note: only works for adding tests.
794 # To remove a test, the $$mi file must be edited manually.
795 sync-mi:
796 @set -eu; \
797 cd "${MAKEFILE:tA:H}/../../.."; \
798 mi="distrib/sets/lists/tests/mi"; \
799 cvs update "$$mi"; \
800 testsdir="usr.bin/make/unit-tests"; \
801 fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
802 cat "$$mi" > "$$mi.tmp"; \
803 (cd "$$testsdir" && egrep '\.(exp|mk)/' CVS/Entries | cut -d/ -f2) | \
804 xargs printf "$$fmt" >> "$$mi.tmp"; \
805 distrib/sets/fmt-list "$$mi.tmp"; \
806 mv "$$mi.tmp" "$$mi"; \
807 cvs diff "$$mi" || true
808
809 .if exists(${TEST_MAKE})
810 ${TESTS:=.rawout}: ${TEST_MAKE}
811 # in meta mode, we *know* if a target script is impacted
812 # by a makefile change.
813 .if ${.MAKE.MODE:Unormal:Mmeta} == ""
814 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
815 .endif
816 .endif
817
818 .-include <bsd.obj.mk>
819