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