Home | History | Annotate | Line # | Download | only in unit-tests
Makefile revision 1.92
      1 # $NetBSD: Makefile,v 1.92 2020/08/15 01:49:07 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-late
     42 TESTS+=		cond-short
     43 TESTS+=		cond1
     44 TESTS+=		cond2
     45 TESTS+=		counter
     46 TESTS+=		dir
     47 TESTS+=		directives
     48 TESTS+=		dollar
     49 TESTS+=		doterror
     50 TESTS+=		dotwait
     51 TESTS+=		envfirst
     52 TESTS+=		error
     53 TESTS+=		# escape	# broken by reverting POSIX changes
     54 TESTS+=		export
     55 TESTS+=		export-all
     56 TESTS+=		export-env
     57 TESTS+=		export-variants
     58 TESTS+=		forloop
     59 TESTS+=		forsubst
     60 TESTS+=		hash
     61 TESTS+=		impsrc
     62 TESTS+=		include-main
     63 TESTS+=		lint
     64 TESTS+=		make-exported
     65 TESTS+=		misc
     66 TESTS+=		moderrs
     67 TESTS+=		modmatch
     68 TESTS+=		modmisc
     69 TESTS+=		modorder
     70 TESTS+=		modts
     71 TESTS+=		modword
     72 TESTS+=		order
     73 TESTS+=		phony-end
     74 TESTS+=		posix
     75 TESTS+=		# posix1	# broken by reverting POSIX changes
     76 TESTS+=		qequals
     77 TESTS+=		recursive
     78 TESTS+=		# suffixes	# runs into an endless loop (try -dA)
     79 TESTS+=		sunshcmd
     80 TESTS+=		sysv
     81 TESTS+=		ternary
     82 TESTS+=		unexport
     83 TESTS+=		unexport-env
     84 TESTS+=		use-inference
     85 TESTS+=		varcmd
     86 TESTS+=		vardebug
     87 TESTS+=		varfind
     88 TESTS+=		varmisc
     89 TESTS+=		varmod-edge
     90 TESTS+=		varparse-dynamic
     91 TESTS+=		varquote
     92 TESTS+=		varshell
     93 
     94 # Override environment variables for some of the tests.
     95 ENV.counter=		-i
     96 ENV.envfirst=		FROM_ENV=value-from-env
     97 ENV.export=		-i PATH=${PATH:Q}
     98 ENV.export-variants=	-i PATH=${PATH:Q}
     99 ENV.lint=		-i
    100 ENV.make-exported=	-i PATH=${PATH:Q}
    101 ENV.recursive=		-i
    102 ENV.varmisc=		FROM_ENV=env
    103 ENV.varmisc+=		FROM_ENV_BEFORE=env
    104 ENV.varmisc+=		FROM_ENV_AFTER=env
    105 
    106 # Override make flags for some of the tests; default is -k.
    107 FLAGS.counter=		-r -dv
    108 FLAGS.doterror=		# none
    109 FLAGS.envfirst=		-e
    110 FLAGS.export=		-r
    111 FLAGS.lint=		-dL -k
    112 FLAGS.order=		-j1
    113 FLAGS.recursive=	-dL -r
    114 FLAGS.vardebug=		-k -dv FROM_CMDLINE=
    115 
    116 # Some tests need extra post-processing.
    117 SED_CMDS.moderrs+=	-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
    118 SED_CMDS.modmisc+=	-e 's,\(Regex compilation error:\).*,\1 (details omitted),'
    119 SED_CMDS.varmod-edge+=	-e 's, line [0-9]*:, line omitted:,'
    120 SED_CMDS.varshell+=	-e 's,^[a-z]*sh: ,,'
    121 SED_CMDS.varshell+=	-e '/command/s,No such.*,not found,'
    122 
    123 # Some tests need an additional round of postprocessing.
    124 POSTPROC.counter=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
    125 POSTPROC.vardebug=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
    126 
    127 export-all.rawout: export.mk
    128 unexport.rawout: export.mk
    129 unexport-env.rawout: export.mk
    130 
    131 # End of the configuration section.
    132 
    133 .MAIN: all
    134 
    135 UNIT_TESTS:=	${.PARSEDIR}
    136 .PATH: ${UNIT_TESTS}
    137 
    138 OUTFILES=	${TESTS:=.out}
    139 
    140 all: ${OUTFILES}
    141 
    142 CLEANFILES+=		*.rawout *.out *.status *.tmp *.core *.tmp
    143 CLEANFILES+=		obj*.[och] lib*.a	# posix1.mk
    144 CLEANFILES+=		issue* .[ab]*		# suffixes.mk
    145 CLEANRECURSIVE+=	dir dummy		# posix1.mk
    146 
    147 clean:
    148 	rm -f ${CLEANFILES}
    149 .if !empty(CLEANRECURSIVE)
    150 	rm -rf ${CLEANRECURSIVE}
    151 .endif
    152 
    153 TEST_MAKE?=	${.MAKE}
    154 TOOL_SED?=	sed
    155 
    156 # ensure consistent results from sort(1)
    157 LC_ALL=		C
    158 LANG=		C
    159 .export LANG LC_ALL
    160 
    161 # the tests are actually done with sub-makes.
    162 .SUFFIXES: .mk .rawout .out
    163 .mk.rawout:
    164 	@echo testing ${.IMPSRC}
    165 	@set -eu; \
    166 	cd ${.OBJDIR}; \
    167 	env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \
    168 	  ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
    169 	  > ${.TARGET}.tmp 2>&1 \
    170 	&& status=$$? || status=$$?; \
    171 	echo $$status > ${.TARGET:R}.status
    172 	@mv ${.TARGET}.tmp ${.TARGET}
    173 
    174 # Post-process the test output so that the results can be compared.
    175 #
    176 # always pretend .MAKE was called 'make'
    177 _SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
    178 _SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
    179 # replace anything after 'stopped in' with unit-tests
    180 _SED_CMDS+=	-e '/stopped/s, /.*, unit-tests,'
    181 # strip ${.CURDIR}/ from the output
    182 _SED_CMDS+=	-e 's,${.CURDIR:S,.,\\.,g}/,,g'
    183 _SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
    184 
    185 .rawout.out:
    186 	@echo postprocess ${.TARGET}
    187 	@${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
    188 	  < ${.IMPSRC} > ${.TARGET}.tmp1
    189 	@${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
    190 	@rm ${.TARGET}.tmp1
    191 	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
    192 	@mv ${.TARGET}.tmp2 ${.TARGET}
    193 
    194 # Compare all output files
    195 test:	${OUTFILES} .PHONY
    196 	@failed= ; \
    197 	for test in ${TESTS}; do \
    198 	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
    199 	  || failed="$${failed}$${failed:+ }$${test}" ; \
    200 	done ; \
    201 	if [ -n "$${failed}" ]; then \
    202 	  echo "Failed tests: $${failed}" ; false ; \
    203 	else \
    204 	  echo "All tests passed" ; \
    205 	fi
    206 
    207 accept:
    208 	@for test in ${TESTS}; do \
    209 	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
    210 	  || { echo "Replacing $${test}.exp" ; \
    211 	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
    212 	done
    213 
    214 SYNC_MI_AWK= \
    215 	BEGIN {								\
    216 	  testsdir = "usr.bin/make/unit-tests";				\
    217 	  linestart = "./usr/tests/" testsdir;				\
    218 	  fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
    219 	  cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
    220 	}								\
    221 	function startswith(s, prefix) {				\
    222 	  return substr(s, 1, length(prefix)) == prefix;		\
    223 	}								\
    224 	startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next }	\
    225 	{ print $$0 }							\
    226 	$$1 == linestart "/Makefile" { system(cmd) }
    227 
    228 sync-mi:
    229 	@set -eu;							\
    230 	cd "${MAKEFILE:tA:H}/../../..";					\
    231 	mi="distrib/sets/lists/tests/mi";				\
    232 	awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@";			\
    233 	mv -f "$$mi.$@" "$$mi";						\
    234 	cvs diff "$$mi" || true
    235 
    236 .if exists(${TEST_MAKE})
    237 ${TESTS:=.rawout}: ${TEST_MAKE}
    238 .endif
    239 
    240 .-include <bsd.obj.mk>
    241