Home | History | Annotate | Line # | Download | only in unit-tests
Makefile revision 1.128
      1 # $NetBSD: Makefile,v 1.128 2020/08/29 19:07:32 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	# broken on FreeBSD, enabled in t_make.sh
     39 TESTS+=		archive-suffix
     40 TESTS+=		cmd-interrupt
     41 TESTS+=		cmdline
     42 TESTS+=		comment
     43 TESTS+=		cond-cmp-numeric
     44 TESTS+=		cond-cmp-numeric-eq
     45 TESTS+=		cond-cmp-numeric-ge
     46 TESTS+=		cond-cmp-numeric-gt
     47 TESTS+=		cond-cmp-numeric-le
     48 TESTS+=		cond-cmp-numeric-lt
     49 TESTS+=		cond-cmp-numeric-ne
     50 TESTS+=		cond-cmp-string
     51 TESTS+=		cond-func
     52 TESTS+=		cond-func-commands
     53 TESTS+=		cond-func-defined
     54 TESTS+=		cond-func-empty
     55 TESTS+=		cond-func-exists
     56 TESTS+=		cond-func-make
     57 TESTS+=		cond-func-target
     58 TESTS+=		cond-late
     59 TESTS+=		cond-op
     60 TESTS+=		cond-op-and
     61 TESTS+=		cond-op-not
     62 TESTS+=		cond-op-or
     63 TESTS+=		cond-op-parentheses
     64 TESTS+=		cond-short
     65 TESTS+=		cond-token-number
     66 TESTS+=		cond-token-plain
     67 TESTS+=		cond-token-string
     68 TESTS+=		cond-token-var
     69 TESTS+=		cond1
     70 TESTS+=		cond2
     71 TESTS+=		counter
     72 TESTS+=		dep
     73 TESTS+=		dep-colon
     74 TESTS+=		dep-double-colon
     75 TESTS+=		dep-exclam
     76 TESTS+=		dep-none
     77 TESTS+=		dep-var
     78 TESTS+=		dep-wildcards
     79 TESTS+=		depsrc
     80 TESTS+=		depsrc-exec
     81 TESTS+=		depsrc-ignore
     82 TESTS+=		depsrc-made
     83 TESTS+=		depsrc-make
     84 TESTS+=		depsrc-meta
     85 TESTS+=		depsrc-nometa
     86 TESTS+=		depsrc-nometa_cmp
     87 TESTS+=		depsrc-nopath
     88 TESTS+=		depsrc-notmain
     89 TESTS+=		depsrc-optional
     90 TESTS+=		depsrc-phony
     91 TESTS+=		depsrc-precious
     92 TESTS+=		depsrc-recursive
     93 TESTS+=		depsrc-silent
     94 TESTS+=		depsrc-use
     95 TESTS+=		depsrc-usebefore
     96 TESTS+=		depsrc-usebefore-double-colon
     97 TESTS+=		depsrc-wait
     98 TESTS+=		deptgt
     99 TESTS+=		deptgt-begin
    100 TESTS+=		deptgt-default
    101 TESTS+=		deptgt-delete_on_error
    102 TESTS+=		deptgt-end
    103 TESTS+=		deptgt-error
    104 TESTS+=		deptgt-ignore
    105 TESTS+=		deptgt-interrupt
    106 TESTS+=		deptgt-main
    107 TESTS+=		deptgt-makeflags
    108 TESTS+=		deptgt-no_parallel
    109 TESTS+=		deptgt-nopath
    110 TESTS+=		deptgt-notparallel
    111 TESTS+=		deptgt-objdir
    112 TESTS+=		deptgt-order
    113 TESTS+=		deptgt-path
    114 TESTS+=		deptgt-path-suffix
    115 TESTS+=		deptgt-phony
    116 TESTS+=		deptgt-precious
    117 TESTS+=		deptgt-shell
    118 TESTS+=		deptgt-silent
    119 TESTS+=		deptgt-stale
    120 TESTS+=		deptgt-suffixes
    121 TESTS+=		dir
    122 TESTS+=		dir-expand-path
    123 TESTS+=		directive
    124 TESTS+=		directive-elif
    125 TESTS+=		directive-elifdef
    126 TESTS+=		directive-elifmake
    127 TESTS+=		directive-elifndef
    128 TESTS+=		directive-elifnmake
    129 TESTS+=		directive-else
    130 TESTS+=		directive-endif
    131 TESTS+=		directive-error
    132 TESTS+=		directive-export
    133 TESTS+=		directive-export-env
    134 TESTS+=		directive-export-literal
    135 TESTS+=		directive-for-generating-endif
    136 TESTS+=		directive-if
    137 TESTS+=		directive-ifdef
    138 TESTS+=		directive-ifmake
    139 TESTS+=		directive-ifndef
    140 TESTS+=		directive-ifnmake
    141 TESTS+=		directive-info
    142 TESTS+=		directive-undef
    143 TESTS+=		directive-unexport
    144 TESTS+=		directive-unexport-env
    145 TESTS+=		directive-warning
    146 TESTS+=		directives
    147 TESTS+=		dollar
    148 TESTS+=		doterror
    149 TESTS+=		dotwait
    150 TESTS+=		envfirst
    151 TESTS+=		error
    152 TESTS+=		# escape	# broken by reverting POSIX changes
    153 TESTS+=		export
    154 TESTS+=		export-all
    155 TESTS+=		export-env
    156 TESTS+=		export-variants
    157 TESTS+=		forloop
    158 TESTS+=		forsubst
    159 TESTS+=		hash
    160 TESTS+=		impsrc
    161 TESTS+=		include-main
    162 TESTS+=		lint
    163 TESTS+=		make-exported
    164 TESTS+=		misc
    165 TESTS+=		moderrs
    166 TESTS+=		modmatch
    167 TESTS+=		modmisc
    168 TESTS+=		modts
    169 TESTS+=		modword
    170 TESTS+=		opt
    171 TESTS+=		opt-backwards
    172 TESTS+=		opt-chdir
    173 TESTS+=		opt-debug
    174 TESTS+=		opt-debug-g1
    175 TESTS+=		opt-define
    176 TESTS+=		opt-env
    177 TESTS+=		opt-file
    178 TESTS+=		opt-ignore
    179 TESTS+=		opt-include-dir
    180 TESTS+=		opt-jobs
    181 TESTS+=		opt-jobs-internal
    182 TESTS+=		opt-keep-going
    183 TESTS+=		opt-m-include-dir
    184 TESTS+=		opt-no-action
    185 TESTS+=		opt-no-action-at-all
    186 TESTS+=		opt-query
    187 TESTS+=		opt-raw
    188 TESTS+=		opt-silent
    189 TESTS+=		opt-touch
    190 TESTS+=		opt-tracefile
    191 TESTS+=		opt-var-expanded
    192 TESTS+=		opt-var-literal
    193 TESTS+=		opt-warnings-as-errors
    194 TESTS+=		opt-where-am-i
    195 TESTS+=		opt-x-reduce-exported
    196 TESTS+=		order
    197 TESTS+=		phony-end
    198 TESTS+=		posix
    199 TESTS+=		# posix1	# broken by reverting POSIX changes
    200 TESTS+=		qequals
    201 TESTS+=		recursive
    202 TESTS+=		sh
    203 TESTS+=		sh-dots
    204 TESTS+=		sh-jobs
    205 TESTS+=		sh-jobs-error
    206 TESTS+=		sh-leading-at
    207 TESTS+=		sh-leading-hyphen
    208 TESTS+=		sh-leading-plus
    209 TESTS+=		sh-meta-chars
    210 TESTS+=		sh-multi-line
    211 TESTS+=		sh-single-line
    212 TESTS+=		# suffixes	# runs into an endless loop (try -dA)
    213 TESTS+=		sunshcmd
    214 TESTS+=		sysv
    215 TESTS+=		ternary
    216 TESTS+=		unexport
    217 TESTS+=		unexport-env
    218 TESTS+=		use-inference
    219 TESTS+=		var-class
    220 TESTS+=		var-class-cmdline
    221 TESTS+=		var-class-env
    222 TESTS+=		var-class-global
    223 TESTS+=		var-class-local
    224 TESTS+=		var-class-local-legacy
    225 TESTS+=		var-op
    226 TESTS+=		var-op-append
    227 TESTS+=		var-op-assign
    228 TESTS+=		var-op-default
    229 TESTS+=		var-op-expand
    230 TESTS+=		var-op-shell
    231 TESTS+=		varcmd
    232 TESTS+=		vardebug
    233 TESTS+=		varfind
    234 TESTS+=		varmisc
    235 TESTS+=		varmod
    236 TESTS+=		varmod-assign
    237 TESTS+=		varmod-defined
    238 TESTS+=		varmod-edge
    239 TESTS+=		varmod-exclam-shell
    240 TESTS+=		varmod-extension
    241 TESTS+=		varmod-gmtime
    242 TESTS+=		varmod-hash
    243 TESTS+=		varmod-head
    244 TESTS+=		varmod-ifelse
    245 TESTS+=		varmod-l-name-to-value
    246 TESTS+=		varmod-localtime
    247 TESTS+=		varmod-loop
    248 TESTS+=		varmod-match
    249 TESTS+=		varmod-match-escape
    250 TESTS+=		varmod-no-match
    251 TESTS+=		varmod-order
    252 TESTS+=		varmod-order-reverse
    253 TESTS+=		varmod-order-shuffle
    254 TESTS+=		varmod-path
    255 TESTS+=		varmod-quote
    256 TESTS+=		varmod-quote-dollar
    257 TESTS+=		varmod-range
    258 TESTS+=		varmod-remember
    259 TESTS+=		varmod-root
    260 TESTS+=		varmod-select-words
    261 TESTS+=		varmod-shell
    262 TESTS+=		varmod-subst
    263 TESTS+=		varmod-subst-regex
    264 TESTS+=		varmod-sysv
    265 TESTS+=		varmod-tail
    266 TESTS+=		varmod-to-abs
    267 TESTS+=		varmod-to-lower
    268 TESTS+=		varmod-to-many-words
    269 TESTS+=		varmod-to-one-word
    270 TESTS+=		varmod-to-separator
    271 TESTS+=		varmod-to-upper
    272 TESTS+=		varmod-undefined
    273 TESTS+=		varmod-unique
    274 TESTS+=		varname
    275 TESTS+=		varname-dollar
    276 TESTS+=		varname-dot-alltargets
    277 TESTS+=		varname-dot-curdir
    278 TESTS+=		varname-dot-includes
    279 TESTS+=		varname-dot-includedfromdir
    280 TESTS+=		varname-dot-includedfromfile
    281 TESTS+=		varname-dot-libs
    282 TESTS+=		varname-dot-make-dependfile
    283 TESTS+=		varname-dot-make-expand_variables
    284 TESTS+=		varname-dot-make-exported
    285 TESTS+=		varname-dot-make-jobs
    286 TESTS+=		varname-dot-make-jobs-prefix
    287 TESTS+=		varname-dot-make-level
    288 TESTS+=		varname-dot-make-makefile_preference
    289 TESTS+=		varname-dot-make-makefiles
    290 TESTS+=		varname-dot-make-meta-bailiwick
    291 TESTS+=		varname-dot-make-meta-created
    292 TESTS+=		varname-dot-make-meta-files
    293 TESTS+=		varname-dot-make-meta-ignore_filter
    294 TESTS+=		varname-dot-make-meta-ignore_paths
    295 TESTS+=		varname-dot-make-meta-ignore_patterns
    296 TESTS+=		varname-dot-make-meta-prefix
    297 TESTS+=		varname-dot-make-mode
    298 TESTS+=		varname-dot-make-path_filemon
    299 TESTS+=		varname-dot-make-pid
    300 TESTS+=		varname-dot-make-ppid
    301 TESTS+=		varname-dot-make-save_dollars
    302 TESTS+=		varname-dot-makeoverrides
    303 TESTS+=		varname-dot-newline
    304 TESTS+=		varname-dot-objdir
    305 TESTS+=		varname-dot-parsedir
    306 TESTS+=		varname-dot-parsefile
    307 TESTS+=		varname-dot-path
    308 TESTS+=		varname-dot-shell
    309 TESTS+=		varname-dot-targets
    310 TESTS+=		varname-empty
    311 TESTS+=		varname-make
    312 TESTS+=		varname-make_print_var_on_error
    313 TESTS+=		varname-makeflags
    314 TESTS+=		varname-pwd
    315 TESTS+=		varname-vpath
    316 TESTS+=		varparse-dynamic
    317 TESTS+=		varquote
    318 TESTS+=		varshell
    319 
    320 # Additional environment variables for some of the tests.
    321 # The base environment is -i PATH="$PATH".
    322 ENV.envfirst=		FROM_ENV=value-from-env
    323 ENV.varmisc=		FROM_ENV=env
    324 ENV.varmisc+=		FROM_ENV_BEFORE=env
    325 ENV.varmisc+=		FROM_ENV_AFTER=env
    326 
    327 # Override make flags for some of the tests; default is -k.
    328 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
    329 # settings FLAGS.test=-dv here, since that is closer to the test code.
    330 FLAGS.archive=		-dA
    331 FLAGS.counter=		-dv
    332 FLAGS.directive-ifmake=	first second
    333 FLAGS.doterror=		# none
    334 FLAGS.envfirst=		-e
    335 FLAGS.export=		# none
    336 FLAGS.lint=		-dL -k
    337 FLAGS.opt-debug-g1=	-dg1
    338 FLAGS.opt-ignore=	-i
    339 FLAGS.opt-keep-going=	-k
    340 FLAGS.opt-no-action=	-n
    341 FLAGS.opt-query=	-q
    342 FLAGS.opt-var-expanded=	-v VAR -v VALUE
    343 FLAGS.opt-var-literal=	-V VAR -V VALUE
    344 FLAGS.opt-warnings-as-errors= -W
    345 FLAGS.order=		-j1
    346 FLAGS.recursive=	-dL
    347 FLAGS.sh-leading-plus=	-n
    348 FLAGS.vardebug=		-k -dv FROM_CMDLINE=
    349 FLAGS.varmod-match-escape= -dv
    350 FLAGS.varname-dot-shell= -dpv
    351 FLAGS.varname-empty=	-dv '$${:U}=cmdline-u' '=cmline-plain'
    352 
    353 # Some tests need extra post-processing.
    354 SED_CMDS.opt-debug-g1=	-e 's,${.CURDIR},CURDIR,'
    355 SED_CMDS.opt-debug-g1+=	-e 's,[/[a-z]*/share/mk,/.../share/mk,'
    356 SED_CMDS.opt-debug-g1+=	-e '/Global Variables:/,/Suffixes:/d'
    357 SED_CMDS.sh-dots+=	-e 's,^${.SHELL}: ,,' -e '/not found/s,command ,,'
    358 SED_CMDS.varmod-subst-regex+= \
    359 			-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
    360 SED_CMDS.varmod-edge+=	-e 's, line [0-9]*:, line omitted:,'
    361 SED_CMDS.varshell+=	-e 's,^${.SHELL:T}: ,,'
    362 SED_CMDS.varshell+=	-e '/command/s,No such.*,not found,'
    363 SED_CMDS.varname-dot-shell=	-e 's, = /.*, = (details omitted),'
    364 SED_CMDS.varname-dot-shell+=	-e 's,"/[^"]*","(details omitted)",'
    365 SED_CMDS.varname-dot-shell+=	-e 's,\[/[^]]*\],[(details omitted)],'
    366 
    367 # Some tests need an additional round of postprocessing.
    368 POSTPROC.counter=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
    369 POSTPROC.deptgt-suffixes= \
    370 			${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
    371 POSTPROC.vardebug=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
    372 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
    373 POSTPROC.varname-dot-shell= \
    374 			awk '/\.SHELL/ || /^ParseReadLine/'
    375 POSTPROC.varname-empty=	${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
    376 
    377 # Some tests reuse other tests, which makes them unnecessarily fragile.
    378 export-all.rawout: export.mk
    379 unexport.rawout: export.mk
    380 unexport-env.rawout: export.mk
    381 
    382 # End of the configuration section.
    383 
    384 .MAIN: all
    385 
    386 UNIT_TESTS:=	${.PARSEDIR}
    387 .PATH: ${UNIT_TESTS}
    388 
    389 OUTFILES=	${TESTS:=.out}
    390 
    391 all: ${OUTFILES}
    392 
    393 CLEANFILES=		*.rawout *.out *.status *.tmp *.core *.tmp
    394 CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
    395 CLEANFILES+=		issue* .[ab]*		# suffixes.mk
    396 CLEANDIRS=		dir dummy		# posix1.mk
    397 
    398 clean:
    399 	rm -f ${CLEANFILES}
    400 	rm -rf ${CLEANDIRS}
    401 
    402 TEST_MAKE?=	${.MAKE}
    403 TOOL_SED?=	sed
    404 
    405 # ensure consistent results from sort(1)
    406 LC_ALL=		C
    407 LANG=		C
    408 .export LANG LC_ALL
    409 
    410 # the tests are actually done with sub-makes.
    411 .SUFFIXES: .mk .rawout .out
    412 .mk.rawout:
    413 	@${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
    414 	@set -eu; \
    415 	cd ${.OBJDIR}; \
    416 	env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \
    417 	  ${TEST_MAKE} \
    418 	    -r -C ${.CURDIR} -f ${.IMPSRC} \
    419 	    ${FLAGS.${.TARGET:R}:U-k} \
    420 	    > ${.TARGET}.tmp 2>&1 \
    421 	&& status=$$? || status=$$?; \
    422 	echo $$status > ${.TARGET:R}.status
    423 	@mv ${.TARGET}.tmp ${.TARGET}
    424 
    425 # Post-process the test output so that the results can be compared.
    426 #
    427 # always pretend .MAKE was called 'make'
    428 _SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
    429 _SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
    430 # replace anything after 'stopped in' with unit-tests
    431 _SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
    432 # strip ${.CURDIR}/ from the output
    433 _SED_CMDS+=	-e 's,${.CURDIR:S,.,\\.,g}/,,g'
    434 _SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
    435 
    436 .rawout.out:
    437 	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
    438 	  < ${.IMPSRC} > ${.TARGET}.tmp1
    439 	@${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
    440 	@rm ${.TARGET}.tmp1
    441 	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
    442 	@mv ${.TARGET}.tmp2 ${.TARGET}
    443 
    444 # Compare all output files
    445 test:	${OUTFILES} .PHONY
    446 	@failed= ; \
    447 	for test in ${TESTS}; do \
    448 	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
    449 	  || failed="$${failed}$${failed:+ }$${test}" ; \
    450 	done ; \
    451 	if [ -n "$${failed}" ]; then \
    452 	  echo "Failed tests: $${failed}" ; false ; \
    453 	else \
    454 	  echo "All tests passed" ; \
    455 	fi
    456 
    457 accept:
    458 	@for test in ${TESTS}; do \
    459 	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
    460 	  || { echo "Replacing $${test}.exp" ; \
    461 	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
    462 	done
    463 
    464 SYNC_MI_AWK= \
    465 	BEGIN {								\
    466 	  testsdir = "usr.bin/make/unit-tests";				\
    467 	  linestart = "./usr/tests/" testsdir;				\
    468 	  fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
    469 	  cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
    470 	}								\
    471 	function startswith(s, prefix) {				\
    472 	  return substr(s, 1, length(prefix)) == prefix;		\
    473 	}								\
    474 	startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next }	\
    475 	{ print $$0 }							\
    476 	$$1 == linestart "/Makefile" { system(cmd) }
    477 
    478 sync-mi:
    479 	# Obsolete entries in the mi file must be marked as obsolete,
    480 	# the lines must be preserved instead of just being deleted.
    481 	@echo "$@: Doesn't work right now." 1>&2; exit 1
    482 	@set -eu;							\
    483 	cd "${MAKEFILE:tA:H}/../../..";					\
    484 	mi="distrib/sets/lists/tests/mi";				\
    485 	cvs update "$$mi";						\
    486 	awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@";			\
    487 	mv -f "$$mi.$@" "$$mi";						\
    488 	cvs diff "$$mi" || true
    489 
    490 .if exists(${TEST_MAKE})
    491 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
    492 .endif
    493 
    494 .-include <bsd.obj.mk>
    495