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