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