Home | History | Annotate | Line # | Download | only in unit-tests
Makefile revision 1.237
      1 # $NetBSD: Makefile,v 1.237 2020/12/06 21:22:04 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, just run "make sync-mi" in this directory.
     28 #
     29 # A few *.mk files are helper files for other tests (such as include-sub.mk)
     30 # and are thus not added to TESTS.  Such files must be ignored in
     31 # src/tests/usr.bin/make/t_make.sh.
     32 #
     33 
     34 # Each test is in a sub-makefile.
     35 # Keep the list sorted.
     36 # Any test that is commented out must be ignored in
     37 # src/tests/usr.bin/make/t_make.sh as well.
     38 TESTS+=		archive
     39 TESTS+=		archive-suffix
     40 TESTS+=		cmd-errors
     41 TESTS+=		cmd-errors-lint
     42 TESTS+=		cmd-interrupt
     43 TESTS+=		cmdline
     44 TESTS+=		cmdline-undefined
     45 TESTS+=		comment
     46 TESTS+=		cond-cmp-numeric
     47 TESTS+=		cond-cmp-numeric-eq
     48 TESTS+=		cond-cmp-numeric-ge
     49 TESTS+=		cond-cmp-numeric-gt
     50 TESTS+=		cond-cmp-numeric-le
     51 TESTS+=		cond-cmp-numeric-lt
     52 TESTS+=		cond-cmp-numeric-ne
     53 TESTS+=		cond-cmp-string
     54 TESTS+=		cond-cmp-unary
     55 TESTS+=		cond-func
     56 TESTS+=		cond-func-commands
     57 TESTS+=		cond-func-defined
     58 TESTS+=		cond-func-empty
     59 TESTS+=		cond-func-exists
     60 TESTS+=		cond-func-make
     61 TESTS+=		cond-func-make-main
     62 TESTS+=		cond-func-target
     63 TESTS+=		cond-late
     64 TESTS+=		cond-op
     65 TESTS+=		cond-op-and
     66 TESTS+=		cond-op-and-lint
     67 TESTS+=		cond-op-not
     68 TESTS+=		cond-op-or
     69 TESTS+=		cond-op-or-lint
     70 TESTS+=		cond-op-parentheses
     71 TESTS+=		cond-short
     72 TESTS+=		cond-token-number
     73 TESTS+=		cond-token-plain
     74 TESTS+=		cond-token-string
     75 TESTS+=		cond-token-var
     76 TESTS+=		cond-undef-lint
     77 TESTS+=		cond1
     78 TESTS+=		counter
     79 TESTS+=		counter-append
     80 TESTS+=		dep
     81 TESTS+=		dep-colon
     82 TESTS+=		dep-colon-bug-cross-file
     83 TESTS+=		dep-double-colon
     84 TESTS+=		dep-double-colon-indep
     85 TESTS+=		dep-exclam
     86 TESTS+=		dep-none
     87 TESTS+=		dep-percent
     88 TESTS+=		dep-var
     89 TESTS+=		dep-wildcards
     90 TESTS+=		depsrc
     91 TESTS+=		depsrc-end
     92 TESTS+=		depsrc-exec
     93 TESTS+=		depsrc-ignore
     94 TESTS+=		depsrc-made
     95 TESTS+=		depsrc-make
     96 TESTS+=		depsrc-meta
     97 TESTS+=		depsrc-nometa
     98 TESTS+=		depsrc-nometa_cmp
     99 TESTS+=		depsrc-nopath
    100 TESTS+=		depsrc-notmain
    101 TESTS+=		depsrc-optional
    102 TESTS+=		depsrc-phony
    103 TESTS+=		depsrc-precious
    104 TESTS+=		depsrc-recursive
    105 TESTS+=		depsrc-silent
    106 TESTS+=		depsrc-use
    107 TESTS+=		depsrc-usebefore
    108 TESTS+=		depsrc-usebefore-double-colon
    109 TESTS+=		depsrc-wait
    110 TESTS+=		deptgt
    111 TESTS+=		deptgt-begin
    112 TESTS+=		deptgt-begin-fail
    113 TESTS+=		deptgt-begin-fail-indirect
    114 TESTS+=		deptgt-default
    115 TESTS+=		deptgt-delete_on_error
    116 TESTS+=		deptgt-end
    117 TESTS+=		deptgt-end-fail
    118 TESTS+=		deptgt-end-fail-all
    119 TESTS+=		deptgt-end-fail-indirect
    120 TESTS+=		deptgt-end-jobs
    121 TESTS+=		deptgt-error
    122 TESTS+=		deptgt-ignore
    123 TESTS+=		deptgt-interrupt
    124 TESTS+=		deptgt-main
    125 TESTS+=		deptgt-makeflags
    126 TESTS+=		deptgt-no_parallel
    127 TESTS+=		deptgt-nopath
    128 TESTS+=		deptgt-notparallel
    129 TESTS+=		deptgt-objdir
    130 TESTS+=		deptgt-order
    131 TESTS+=		deptgt-path
    132 TESTS+=		deptgt-path-suffix
    133 TESTS+=		deptgt-phony
    134 TESTS+=		deptgt-precious
    135 TESTS+=		deptgt-shell
    136 TESTS+=		deptgt-silent
    137 TESTS+=		deptgt-stale
    138 TESTS+=		deptgt-suffixes
    139 TESTS+=		dir
    140 TESTS+=		dir-expand-path
    141 TESTS+=		directive
    142 TESTS+=		directive-dinclude
    143 TESTS+=		directive-elif
    144 TESTS+=		directive-elifdef
    145 TESTS+=		directive-elifmake
    146 TESTS+=		directive-elifndef
    147 TESTS+=		directive-elifnmake
    148 TESTS+=		directive-else
    149 TESTS+=		directive-endif
    150 TESTS+=		directive-error
    151 TESTS+=		directive-export
    152 TESTS+=		directive-export-env
    153 TESTS+=		directive-export-gmake
    154 TESTS+=		directive-export-literal
    155 TESTS+=		directive-for
    156 TESTS+=		directive-for-generating-endif
    157 TESTS+=		directive-hyphen-include
    158 TESTS+=		directive-if
    159 TESTS+=		directive-if-nested
    160 TESTS+=		directive-ifdef
    161 TESTS+=		directive-ifmake
    162 TESTS+=		directive-ifndef
    163 TESTS+=		directive-ifnmake
    164 TESTS+=		directive-include
    165 TESTS+=		directive-include-fatal
    166 TESTS+=		directive-info
    167 TESTS+=		directive-sinclude
    168 TESTS+=		directive-undef
    169 TESTS+=		directive-unexport
    170 TESTS+=		directive-unexport-env
    171 TESTS+=		directive-warning
    172 TESTS+=		dollar
    173 TESTS+=		doterror
    174 TESTS+=		dotwait
    175 TESTS+=		envfirst
    176 TESTS+=		error
    177 TESTS+=		# escape	# broken by reverting POSIX changes
    178 TESTS+=		export
    179 TESTS+=		export-all
    180 TESTS+=		export-env
    181 TESTS+=		export-variants
    182 TESTS+=		forloop
    183 TESTS+=		forsubst
    184 TESTS+=		gnode-submake
    185 TESTS+=		hanoi-include
    186 TESTS+=		impsrc
    187 TESTS+=		include-main
    188 TESTS+=		job-flags
    189 TESTS+=		job-output-long-lines
    190 TESTS+=		jobs-error-indirect
    191 TESTS+=		jobs-error-nested
    192 TESTS+=		jobs-error-nested-make
    193 TESTS+=		lint
    194 TESTS+=		make-exported
    195 TESTS+=		meta-cmd-cmp
    196 TESTS+=		moderrs
    197 TESTS+=		modmatch
    198 TESTS+=		modmisc
    199 TESTS+=		modts
    200 TESTS+=		modword
    201 .if ${.MAKE.UID:U0} > 0
    202 TESTS+=		objdir-writable
    203 .endif
    204 TESTS+=		opt
    205 TESTS+=		opt-backwards
    206 TESTS+=		opt-chdir
    207 TESTS+=		opt-debug
    208 TESTS+=		opt-debug-all
    209 TESTS+=		opt-debug-archive
    210 TESTS+=		opt-debug-curdir
    211 TESTS+=		opt-debug-cond
    212 TESTS+=		opt-debug-dir
    213 TESTS+=		opt-debug-errors
    214 TESTS+=		opt-debug-file
    215 TESTS+=		opt-debug-for
    216 TESTS+=		opt-debug-graph1
    217 TESTS+=		opt-debug-graph2
    218 TESTS+=		opt-debug-graph3
    219 TESTS+=		opt-debug-hash
    220 TESTS+=		opt-debug-jobs
    221 TESTS+=		opt-debug-lint
    222 TESTS+=		opt-debug-loud
    223 TESTS+=		opt-debug-meta
    224 TESTS+=		opt-debug-making
    225 TESTS+=		opt-debug-no-rm
    226 TESTS+=		opt-debug-parse
    227 TESTS+=		opt-debug-suff
    228 TESTS+=		opt-debug-targets
    229 TESTS+=		opt-debug-varraw
    230 TESTS+=		opt-debug-var
    231 TESTS+=		opt-debug-x-trace
    232 TESTS+=		opt-define
    233 TESTS+=		opt-env
    234 TESTS+=		opt-file
    235 TESTS+=		opt-ignore
    236 TESTS+=		opt-include-dir
    237 TESTS+=		opt-jobs
    238 TESTS+=		opt-jobs-internal
    239 TESTS+=		opt-keep-going
    240 TESTS+=		opt-m-include-dir
    241 TESTS+=		opt-no-action
    242 TESTS+=		opt-no-action-at-all
    243 TESTS+=		opt-query
    244 TESTS+=		opt-raw
    245 TESTS+=		opt-silent
    246 TESTS+=		opt-touch
    247 TESTS+=		opt-touch-jobs
    248 TESTS+=		opt-tracefile
    249 TESTS+=		opt-var-expanded
    250 TESTS+=		opt-var-literal
    251 TESTS+=		opt-warnings-as-errors
    252 TESTS+=		opt-where-am-i
    253 TESTS+=		opt-x-reduce-exported
    254 TESTS+=		order
    255 TESTS+=		parse-var
    256 TESTS+=		phony-end
    257 TESTS+=		posix
    258 TESTS+=		# posix1	# broken by reverting POSIX changes
    259 TESTS+=		qequals
    260 TESTS+=		recursive
    261 TESTS+=		sh
    262 TESTS+=		sh-dots
    263 TESTS+=		sh-jobs
    264 TESTS+=		sh-jobs-error
    265 TESTS+=		sh-leading-at
    266 TESTS+=		sh-leading-hyphen
    267 TESTS+=		sh-leading-plus
    268 TESTS+=		sh-meta-chars
    269 TESTS+=		sh-multi-line
    270 TESTS+=		sh-single-line
    271 TESTS+=		shell-csh
    272 TESTS+=		shell-custom
    273 TESTS+=		shell-ksh
    274 TESTS+=		shell-sh
    275 TESTS+=		suff-add-later
    276 TESTS+=		suff-clear-regular
    277 TESTS+=		suff-clear-single
    278 TESTS+=		suff-incomplete
    279 TESTS+=		suff-lookup
    280 TESTS+=		suff-main
    281 TESTS+=		suff-main-several
    282 TESTS+=		suff-phony
    283 TESTS+=		suff-rebuild
    284 TESTS+=		suff-self
    285 TESTS+=		suff-transform-debug
    286 TESTS+=		suff-transform-endless
    287 TESTS+=		suff-transform-expand
    288 TESTS+=		suff-transform-select
    289 TESTS+=		sunshcmd
    290 TESTS+=		ternary
    291 TESTS+=		unexport
    292 TESTS+=		unexport-env
    293 TESTS+=		use-inference
    294 TESTS+=		var-class
    295 TESTS+=		var-class-cmdline
    296 TESTS+=		var-class-env
    297 TESTS+=		var-class-global
    298 TESTS+=		var-class-local
    299 TESTS+=		var-class-local-legacy
    300 TESTS+=		var-op
    301 TESTS+=		var-op-append
    302 TESTS+=		var-op-assign
    303 TESTS+=		var-op-default
    304 TESTS+=		var-op-expand
    305 TESTS+=		var-op-shell
    306 TESTS+=		var-op-sunsh
    307 TESTS+=		var-recursive
    308 TESTS+=		varcmd
    309 TESTS+=		vardebug
    310 TESTS+=		varfind
    311 TESTS+=		varmisc
    312 TESTS+=		varmod
    313 TESTS+=		varmod-assign
    314 TESTS+=		varmod-defined
    315 TESTS+=		varmod-edge
    316 TESTS+=		varmod-exclam-shell
    317 TESTS+=		varmod-extension
    318 TESTS+=		varmod-gmtime
    319 TESTS+=		varmod-hash
    320 TESTS+=		varmod-head
    321 TESTS+=		varmod-ifelse
    322 TESTS+=		varmod-indirect
    323 TESTS+=		varmod-l-name-to-value
    324 TESTS+=		varmod-localtime
    325 TESTS+=		varmod-loop
    326 TESTS+=		varmod-match
    327 TESTS+=		varmod-match-escape
    328 TESTS+=		varmod-no-match
    329 TESTS+=		varmod-order
    330 TESTS+=		varmod-order-reverse
    331 TESTS+=		varmod-order-shuffle
    332 TESTS+=		varmod-path
    333 TESTS+=		varmod-quote
    334 TESTS+=		varmod-quote-dollar
    335 TESTS+=		varmod-range
    336 TESTS+=		varmod-remember
    337 TESTS+=		varmod-root
    338 TESTS+=		varmod-select-words
    339 TESTS+=		varmod-shell
    340 TESTS+=		varmod-subst
    341 TESTS+=		varmod-subst-regex
    342 TESTS+=		varmod-sysv
    343 TESTS+=		varmod-tail
    344 TESTS+=		varmod-to-abs
    345 TESTS+=		varmod-to-lower
    346 TESTS+=		varmod-to-many-words
    347 TESTS+=		varmod-to-one-word
    348 TESTS+=		varmod-to-separator
    349 TESTS+=		varmod-to-upper
    350 TESTS+=		varmod-undefined
    351 TESTS+=		varmod-unique
    352 TESTS+=		varname
    353 TESTS+=		varname-dollar
    354 TESTS+=		varname-dot-alltargets
    355 TESTS+=		varname-dot-curdir
    356 TESTS+=		varname-dot-includes
    357 TESTS+=		varname-dot-includedfromdir
    358 TESTS+=		varname-dot-includedfromfile
    359 TESTS+=		varname-dot-libs
    360 TESTS+=		varname-dot-make-dependfile
    361 TESTS+=		varname-dot-make-expand_variables
    362 TESTS+=		varname-dot-make-exported
    363 TESTS+=		varname-dot-make-jobs
    364 TESTS+=		varname-dot-make-jobs-prefix
    365 TESTS+=		varname-dot-make-level
    366 TESTS+=		varname-dot-make-makefile_preference
    367 TESTS+=		varname-dot-make-makefiles
    368 TESTS+=		varname-dot-make-meta-bailiwick
    369 TESTS+=		varname-dot-make-meta-created
    370 TESTS+=		varname-dot-make-meta-files
    371 TESTS+=		varname-dot-make-meta-ignore_filter
    372 TESTS+=		varname-dot-make-meta-ignore_paths
    373 TESTS+=		varname-dot-make-meta-ignore_patterns
    374 TESTS+=		varname-dot-make-meta-prefix
    375 TESTS+=		varname-dot-make-mode
    376 TESTS+=		varname-dot-make-path_filemon
    377 TESTS+=		varname-dot-make-pid
    378 TESTS+=		varname-dot-make-ppid
    379 TESTS+=		varname-dot-make-save_dollars
    380 TESTS+=		varname-dot-makeflags
    381 TESTS+=		varname-dot-makeoverrides
    382 TESTS+=		varname-dot-newline
    383 TESTS+=		varname-dot-objdir
    384 TESTS+=		varname-dot-parsedir
    385 TESTS+=		varname-dot-parsefile
    386 TESTS+=		varname-dot-path
    387 TESTS+=		varname-dot-shell
    388 TESTS+=		varname-dot-targets
    389 TESTS+=		varname-empty
    390 TESTS+=		varname-make
    391 TESTS+=		varname-make_print_var_on_error
    392 TESTS+=		varname-make_print_var_on_error-jobs
    393 TESTS+=		varname-makefile
    394 TESTS+=		varname-makeflags
    395 TESTS+=		varname-pwd
    396 TESTS+=		varname-vpath
    397 TESTS+=		varparse-dynamic
    398 TESTS+=		varparse-errors
    399 TESTS+=		varparse-mod
    400 TESTS+=		varparse-undef-partial
    401 TESTS+=		varquote
    402 
    403 # Ideas for more tests:
    404 #	char-0020-space.mk
    405 #	char-005C-backslash.mk
    406 #	escape-cond-str.mk
    407 #	escape-cond-func-arg.mk
    408 #	escape-cond-func-arg.mk
    409 #	escape-varmod.mk
    410 #	escape-varmod-define.mk
    411 #	escape-varmod-match.mk
    412 #	escape-varname.mk
    413 #	escape-varassign-varname.mk
    414 #	escape-varassign-varname-cmdline.mk
    415 #	escape-varassign-value.mk
    416 #	escape-varassign-value-cmdline.mk
    417 #	escape-dependency-source.mk
    418 #	escape-dependency-target.mk
    419 #	escape-for-varname.mk
    420 #	escape-for-item.mk
    421 #	posix-*.mk (see posix.mk and posix1.mk)
    422 
    423 .if ${.OBJDIR} != ${.CURDIR}
    424 RO_OBJDIR:=	${.OBJDIR}/roobj
    425 .else
    426 RO_OBJDIR:=	${TMPDIR:U/tmp}/roobj
    427 .endif
    428 # Additional environment variables for some of the tests.
    429 # The base environment is -i PATH="$PATH".
    430 ENV.depsrc-optional+=   TZ=UTC
    431 ENV.envfirst=		FROM_ENV=value-from-env
    432 ENV.objdir-writable+=	RO_OBJDIR=${RO_OBJDIR}
    433 ENV.varmisc=		FROM_ENV=env
    434 ENV.varmisc+=		FROM_ENV_BEFORE=env
    435 ENV.varmisc+=		FROM_ENV_AFTER=env
    436 ENV.varmod-localtime+=	TZ=Europe/Berlin
    437 ENV.varname-vpath+=	VPATH=varname-vpath.dir:varname-vpath.dir2
    438 
    439 # Override make flags for some of the tests; default is -k.
    440 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
    441 # settings FLAGS.test=-dv here, since that is closer to the test code.
    442 FLAGS.cond-func-make=		via-cmdline
    443 FLAGS.directive-ifmake=		first second
    444 FLAGS.doterror=			# none, especially not -k
    445 FLAGS.jobs-error-indirect=	# none, especially not -k
    446 FLAGS.jobs-error-nested=	# none, especially not -k
    447 FLAGS.jobs-error-nested-make=	# none, especially not -k
    448 FLAGS.varname-empty=		-dv '$${:U}=cmdline-u' '=cmdline-plain'
    449 
    450 # Some tests need extra postprocessing.
    451 SED_CMDS.dir=		${:D remove output from -DCLEANUP mode }
    452 SED_CMDS.dir+=		-e '/^OpenDirs_Done:/d'
    453 SED_CMDS.dir+=		-e '/^CachedDir /d'
    454 SED_CMDS.export=	-e '/^[^=_A-Za-z0-9]*=/d'
    455 SED_CMDS.export-all=	${SED_CMDS.export}
    456 SED_CMDS.export-env=	${SED_CMDS.export}
    457 SED_CMDS.job-output-long-lines= \
    458 	${:D Job separators on their own line are ok. } \
    459 	-e '/^--- job-[ab] ---$$/d' \
    460 	${:D Plain output lines are ok as well. } \
    461 	${:D They may come in multiples of 1024 or as 10000. } \
    462 	-e '/^aa*$$/d' \
    463 	-e '/^bb*$$/d' \
    464 	${:D The following lines should rather not occur since the job } \
    465 	${:D marker should always be at the beginning of the line. } \
    466 	-e '/^aa*--- job-b ---$$/d' \
    467 	-e '/^bb*--- job-a ---$$/d'
    468 SED_CMDS.objdir-writable=	-e 's,${RO_OBJDIR},OBJDIR/roobj,g'
    469 SED_CMDS.opt-debug-graph1=	${STD_SED_CMDS.dg1}
    470 SED_CMDS.opt-debug-jobs=	-e 's,([0-9][0-9]*),(<pid>),'
    471 SED_CMDS.opt-debug-jobs+=	-e 's,pid [0-9][0-9]*,pid <pid>,'
    472 SED_CMDS.opt-debug-jobs+=	-e 's,Process [0-9][0-9]*,Process <pid>,'
    473 SED_CMDS.opt-debug-jobs+=	-e 's,JobFinish: [0-9][0-9]*,JobFinish: <pid>,'
    474 SED_CMDS.opt-debug-jobs+=	-e 's,Command: ${.SHELL:T},Command: <shell>,'
    475 # The "-q" may be there or not, see jobs.c, variable shells.
    476 SED_CMDS.opt-debug-jobs+=	-e 's,^\(.Command: <shell>\) -q,\1,'
    477 SED_CMDS.sh-dots=		-e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
    478 SED_CMDS.suff-main+=		${STD_SED_CMDS.dg1}
    479 SED_CMDS.suff-main-several+=	${STD_SED_CMDS.dg1}
    480 SED_CMDS.suff-transform-debug+=	${STD_SED_CMDS.dg1}
    481 SED_CMDS.var-op-shell+=	\
    482 	-e 's,^${.SHELL:T}: [ 0-9:]*,,' \
    483 	-e '/command/s,No such.*,not found,'
    484 SED_CMDS.vardebug+=	-e 's,${.SHELL},</path/to/shell>,'
    485 SED_CMDS.varmod-edge+=	-e 's, line [0-9]*:, line omitted:,'
    486 SED_CMDS.varmod-gmtime+=	-e 's,Tue Jan 19 03:14:08 2038,<normalized>,'
    487 SED_CMDS.varmod-gmtime+=	${:D FreeBSD i386 still has 32-bit time_t. }
    488 SED_CMDS.varmod-gmtime+=	-e 's,Fri Dec 13 20:45:52 1901,<normalized>,'
    489 SED_CMDS.varmod-localtime+=	-e 's,Tue Jan 19 04:14:08 2038,<normalized>,'
    490 SED_CMDS.varmod-localtime+=	${:D FreeBSD i386 still has 32-bit time_t. }
    491 SED_CMDS.varmod-localtime+=	-e 's,Fri Dec 13 21:45:52 1901,<normalized>,'
    492 SED_CMDS.varmod-subst-regex+= \
    493 			-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
    494 SED_CMDS.varname-dot-parsedir=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
    495 SED_CMDS.varname-dot-parsefile=	-e '/in some cases/ s,^make: "[^"]*,make: "<normalized>,'
    496 SED_CMDS.varname-dot-shell=	-e 's, = /[^ ]*, = (details omitted),g'
    497 SED_CMDS.varname-dot-shell+=	-e 's,"/[^" ]*","(details omitted)",g'
    498 SED_CMDS.varname-dot-shell+=	-e 's,\[/[^] ]*\],[(details omitted)],g'
    499 
    500 # Some tests need an additional round of postprocessing.
    501 POSTPROC.deptgt-suffixes=	awk '/^\#\*\*\* Suffixes/,/^never-stop/'
    502 POSTPROC.gnode-submake=		awk '/Input graph/, /^$$/'
    503 POSTPROC.varname-empty=		${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
    504 
    505 # Some tests reuse other tests, which makes them unnecessarily fragile.
    506 export-all.rawout: export.mk
    507 unexport.rawout: export.mk
    508 unexport-env.rawout: export.mk
    509 
    510 # End of the configuration section.
    511 
    512 # Some standard sed commands, to be used in the SED_CMDS above.
    513 
    514 # Omit details from the output of the -dg1 option such as process IDs.
    515 STD_SED_CMDS.dg1=	-e 's,${.CURDIR}$$,<curdir>,'
    516 STD_SED_CMDS.dg1+=	-e 's,  ${DEFSYSPATH:U/usr/share/mk}$$,  <defsyspath>,'
    517 STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE *=\) .*,\1 <details omitted>,'
    518 STD_SED_CMDS.dg1+=	-e 's,^\(\.MAKE\.[A-Z_]* *=\) .*,\1 <details omitted>,'
    519 STD_SED_CMDS.dg1+=	-e 's,^\(MACHINE[_ARCH]* *=\) .*,\1 <details omitted>,'
    520 STD_SED_CMDS.dg1+=	-e 's,^\(MAKE *=\) .*,\1 <details omitted>,'
    521 
    522 # End of the configuration helpers section.
    523 
    524 .MAIN: all
    525 
    526 UNIT_TESTS:=	${.PARSEDIR}
    527 .PATH: ${UNIT_TESTS}
    528 
    529 .if ${USE_ABSOLUTE_TESTNAMES:Uno} == yes
    530 OUTFILES=	${TESTS:@test@${.CURDIR:tA}/${test}.out@}
    531 .else
    532 OUTFILES=	${TESTS:=.out}
    533 .endif
    534 
    535 all: ${OUTFILES}
    536 
    537 CLEANFILES=		*.rawout *.out *.status *.tmp *.core *.tmp
    538 CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
    539 CLEANFILES+=		issue* .[ab]*		# suffixes.mk
    540 CLEANDIRS=		dir dummy		# posix1.mk
    541 
    542 clean:
    543 	rm -f ${CLEANFILES}
    544 	rm -rf ${CLEANDIRS}
    545 
    546 TEST_MAKE?=	${.MAKE}
    547 TOOL_SED?=	sed
    548 
    549 # ensure consistent results from sort(1)
    550 LC_ALL=		C
    551 LANG=		C
    552 .export LANG LC_ALL
    553 
    554 MAKE_TEST_ENV?=	MALLOC_OPTIONS="JA"	# for jemalloc
    555 
    556 .if ${.MAKE.OS:U${uname -s:L:sh}} == "NetBSD"
    557 LIMIT_RESOURCES?=	ulimit -v 200000
    558 .endif
    559 LIMIT_RESOURCES?=	:
    560 
    561 # Each test is run in a sub-make, to keep the tests for interfering with
    562 # each other, and because they use different environment variables and
    563 # command line options.
    564 .SUFFIXES: .mk .rawout .out
    565 .mk.rawout:
    566 	@${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
    567 	@set -eu; \
    568 	${LIMIT_RESOURCES}; \
    569 	cd ${.OBJDIR}; \
    570 	env -i PATH="$$PATH" ${MAKE_TEST_ENV} ${ENV.${.PREFIX:T}} \
    571 	  ${TEST_MAKE} \
    572 	    -r -C ${.CURDIR} -f ${.IMPSRC} \
    573 	    ${FLAGS.${.PREFIX:T}:U-k} \
    574 	    > ${.TARGET}.tmp 2>&1 \
    575 	&& status=$$? || status=$$?; \
    576 	echo $$status > ${.TARGET:R}.status
    577 	@mv ${.TARGET}.tmp ${.TARGET}
    578 
    579 # Postprocess the test output so that the results can be compared.
    580 #
    581 # always pretend .MAKE was called 'make'
    582 _SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
    583 _SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
    584 _SED_CMDS+=	-e 's,${TEST_MAKE:T:S,.,\\.,g}[][0-9]* warning,make warning,'
    585 _SED_CMDS+=	-e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
    586 # replace anything after 'stopped in' with unit-tests
    587 _SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
    588 # strip ${.CURDIR}/ from the output
    589 _SED_CMDS+=	-e 's,${.CURDIR:S,.,\\.,g}/,,g'
    590 _SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
    591 
    592 .rawout.out:
    593 	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.PREFIX:T}} \
    594 	  < ${.IMPSRC} > ${.TARGET}.tmp1
    595 	@${POSTPROC.${.PREFIX:T}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
    596 	@rm ${.TARGET}.tmp1
    597 	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
    598 	@mv ${.TARGET}.tmp2 ${.TARGET}
    599 
    600 # Compare all output files
    601 test:	${OUTFILES} .PHONY
    602 	@failed= ; \
    603 	for test in ${TESTS}; do \
    604 	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
    605 	  || failed="$${failed}$${failed:+ }$${test}" ; \
    606 	done ; \
    607 	if [ -n "$${failed}" ]; then \
    608 	  echo "Failed tests: $${failed}" ; false ; \
    609 	else \
    610 	  echo "All tests passed" ; \
    611 	fi
    612 
    613 accept:
    614 	@for test in ${TESTS}; do \
    615 	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
    616 	  || { echo "Replacing $${test}.exp" ; \
    617 	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
    618 	done
    619 
    620 # Note: only works for adding tests.
    621 # To remove a test, the $$mi file must be edited manually.
    622 sync-mi:
    623 	@set -eu;							\
    624 	cd "${MAKEFILE:tA:H}/../../..";					\
    625 	mi="distrib/sets/lists/tests/mi";				\
    626 	cvs update "$$mi";						\
    627 	testsdir="usr.bin/make/unit-tests";				\
    628 	fmt="./usr/tests/$$testsdir/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
    629 	cat "$$mi" > "$$mi.tmp";					\
    630 	(cd "$$testsdir" && ls *.exp *.mk) | xargs printf "$$fmt" >> "$$mi.tmp"; \
    631 	distrib/sets/fmt-list "$$mi.tmp";				\
    632 	mv "$$mi.tmp" "$$mi";						\
    633 	cvs diff "$$mi" || true
    634 
    635 .if exists(${TEST_MAKE})
    636 ${TESTS:=.rawout}: ${TEST_MAKE}
    637 # in meta mode, we *know* if a target script is impacted
    638 # by a makefile change.
    639 .if ${.MAKE.MODE:Unormal:Mmeta} == ""
    640 ${TESTS:=.rawout}: ${.PARSEDIR}/Makefile
    641 .endif
    642 .endif
    643 
    644 .-include <bsd.obj.mk>
    645