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