Makefile revision 1.53
11.53Schristos# $NetBSD: Makefile,v 1.53 2018/05/24 00:25:44 christos Exp $
21.1Ssjg#
31.1Ssjg# Unit tests for make(1)
41.1Ssjg# The main targets are:
51.1Ssjg# 
61.1Ssjg# all:	run all the tests
71.42Sapb# test:	run 'all', and compare to expected results
81.1Ssjg# accept: move generated output to expected results
91.1Ssjg#
101.1Ssjg# Adding a test case.  
111.11Ssjg# Each feature should get its own set of tests in its own suitably
121.42Sapb# named makefile (*.mk), with its own set of expected results (*.exp),
131.42Sapb# and it should be added to the TESTNAMES list.
141.1Ssjg# 
151.1Ssjg
161.1Ssjg.MAIN: all
171.1Ssjg
181.7SsjgUNIT_TESTS:= ${.PARSEDIR}
191.44Sapb.PATH: ${UNIT_TESTS}
201.7Ssjg
211.42Sapb# Each test is in a sub-makefile.
221.42Sapb# Keep the list sorted.
231.42SapbTESTNAMES= \
241.16Srpaulo	comment \
251.12Ssjg	cond1 \
261.52Ssjg	cond2 \
271.26Ssjg	error \
281.21Ssjg	export \
291.21Ssjg	export-all \
301.36Ssjg	export-env \
311.26Ssjg	doterror \
321.19Sapb	dotwait \
331.34Ssjg	forloop \
341.24Ssjg	forsubst \
351.32Sjoerg	hash \
361.31Ssjg	misc \
371.20Ssjg	moderrs \
381.11Ssjg	modmatch \
391.18Ssjg	modmisc \
401.15Ssjg	modorder \
411.11Ssjg	modts \
421.11Ssjg	modword \
431.35Ssjg	order \
441.13Ssjg	posix \
451.22Ssjg	qequals \
461.38Ssjg	sunshcmd \
471.31Ssjg	sysv \
481.11Ssjg	ternary \
491.25Ssjg	unexport \
501.25Ssjg	unexport-env \
511.39Sapb	varcmd \
521.43Sapb	varmisc \
531.53Schristos	varquote \
541.39Sapb	varshell
551.11Ssjg
561.51Ssjg# these tests were broken by referting POSIX chanegs
571.51SsjgSTRICT_POSIX_TESTS = \
581.51Ssjg	escape \
591.51Ssjg	impsrc \
601.51Ssjg	phony-end \
611.51Ssjg	posix1 \
621.51Ssjg	suffixes
631.51Ssjg
641.42Sapb# Override make flags for certain tests
651.26Ssjgflags.doterror=
661.35Ssjgflags.order=-j1
671.26Ssjg
681.42SapbOUTFILES= ${TESTNAMES:S/$/.out/}
691.42Sapb
701.42Sapball: ${OUTFILES}
711.9Ssjg
721.48SapbCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
731.48SapbCLEANFILES += obj*.[och] lib*.a		# posix1.mk
741.49SsjgCLEANFILES += issue* .[ab]*		# suffixes.mk
751.48SapbCLEANRECURSIVE += dir dummy		# posix1.mk
761.48Sapb
771.1Ssjgclean:
781.48Sapb	rm -f ${CLEANFILES}
791.48Sapb.if !empty(CLEANRECURSIVE)
801.48Sapb	rm -rf ${CLEANRECURSIVE}
811.48Sapb.endif
821.1Ssjg
831.15SsjgTEST_MAKE?= ${.MAKE}
841.27SsjgTOOL_SED?= sed
851.1Ssjg
861.28Ssjg# ensure consistent results from sort(1)
871.30SsjgLC_ALL= C
881.28SsjgLANG= C
891.29Ssjg.export LANG LC_ALL
901.28Ssjg
911.42Sapb# the tests are actually done with sub-makes.
921.42Sapb.SUFFIXES: .mk .rawout .out
931.42Sapb.mk.rawout:
941.42Sapb	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
951.42Sapb	-@cd ${.OBJDIR} && \
961.42Sapb	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
971.42Sapb	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
981.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
991.42Sapb
1001.12Ssjg# We always pretend .MAKE was called 'make' 
1011.12Ssjg# and strip ${.CURDIR}/ from the output
1021.13Ssjg# and replace anything after 'stopped in' with unit-tests
1031.12Ssjg# so the results can be compared.
1041.42Sapb.rawout.out:
1051.42Sapb	@echo postprocess ${.TARGET}
1061.42Sapb	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
1071.42Sapb	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
1081.42Sapb	  -e '/stopped/s, /.*, unit-tests,' \
1091.42Sapb	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
1101.42Sapb	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
1111.42Sapb	  < ${.IMPSRC} > ${.TARGET}.tmp
1121.42Sapb	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
1131.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
1141.42Sapb
1151.42Sapb# Compare all output files
1161.42Sapbtest:	${OUTFILES} .PHONY
1171.42Sapb	@failed= ; \
1181.42Sapb	for test in ${TESTNAMES}; do \
1191.42Sapb	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
1201.42Sapb	  || failed="$${failed}$${failed:+ }$${test}" ; \
1211.42Sapb	done ; \
1221.42Sapb	if [ -n "$${failed}" ]; then \
1231.42Sapb	  echo "Failed tests: $${failed}" ; false ; \
1241.42Sapb	else \
1251.42Sapb	  echo "All tests passed" ; \
1261.42Sapb	fi
1271.1Ssjg
1281.1Ssjgaccept:
1291.42Sapb	@for test in ${TESTNAMES}; do \
1301.42Sapb	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
1311.42Sapb	  || { echo "Replacing $${test}.exp" ; \
1321.42Sapb	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
1331.42Sapb	done
1341.1Ssjg
1351.50Ssjg.if exists(${TEST_MAKE})
1361.50Ssjg${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
1371.50Ssjg.endif
1381.50Ssjg
1391.42Sapb.-include <bsd.obj.mk>
140