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