Makefile revision 1.48
11.48Sapb# $NetBSD: Makefile,v 1.48 2014/08/24 17:17:24 apb 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.26Ssjg	error \
271.47Sapb	escape \
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.45Schristos	impsrc \
371.31Ssjg	misc \
381.20Ssjg	moderrs \
391.11Ssjg	modmatch \
401.18Ssjg	modmisc \
411.15Ssjg	modorder \
421.11Ssjg	modts \
431.11Ssjg	modword \
441.35Ssjg	order \
451.33Ssjg	phony-end \
461.13Ssjg	posix \
471.46Schristos	posix1 \
481.22Ssjg	qequals \
491.45Schristos	suffixes \
501.38Ssjg	sunshcmd \
511.31Ssjg	sysv \
521.11Ssjg	ternary \
531.25Ssjg	unexport \
541.25Ssjg	unexport-env \
551.39Sapb	varcmd \
561.43Sapb	varmisc \
571.39Sapb	varshell
581.11Ssjg
591.42Sapb# Override make flags for certain tests
601.26Ssjgflags.doterror=
611.35Ssjgflags.order=-j1
621.26Ssjg
631.42SapbOUTFILES= ${TESTNAMES:S/$/.out/}
641.42Sapb
651.42Sapball: ${OUTFILES}
661.9Ssjg
671.48SapbCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
681.48SapbCLEANFILES += obj*.[och] lib*.a		# posix1.mk
691.48SapbCLEANFILES += issue*			# suffixes.mk
701.48SapbCLEANRECURSIVE += dir dummy		# posix1.mk
711.48Sapb
721.1Ssjgclean:
731.48Sapb	rm -f ${CLEANFILES}
741.48Sapb.if !empty(CLEANRECURSIVE)
751.48Sapb	rm -rf ${CLEANRECURSIVE}
761.48Sapb.endif
771.1Ssjg
781.15SsjgTEST_MAKE?= ${.MAKE}
791.27SsjgTOOL_SED?= sed
801.1Ssjg
811.28Ssjg# ensure consistent results from sort(1)
821.30SsjgLC_ALL= C
831.28SsjgLANG= C
841.29Ssjg.export LANG LC_ALL
851.28Ssjg
861.42Sapb# the tests are actually done with sub-makes.
871.42Sapb.SUFFIXES: .mk .rawout .out
881.42Sapb.mk.rawout:
891.42Sapb	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
901.42Sapb	-@cd ${.OBJDIR} && \
911.42Sapb	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
921.42Sapb	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
931.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
941.42Sapb
951.12Ssjg# We always pretend .MAKE was called 'make' 
961.12Ssjg# and strip ${.CURDIR}/ from the output
971.13Ssjg# and replace anything after 'stopped in' with unit-tests
981.12Ssjg# so the results can be compared.
991.42Sapb.rawout.out:
1001.42Sapb	@echo postprocess ${.TARGET}
1011.42Sapb	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
1021.42Sapb	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
1031.42Sapb	  -e '/stopped/s, /.*, unit-tests,' \
1041.42Sapb	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
1051.42Sapb	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
1061.42Sapb	  < ${.IMPSRC} > ${.TARGET}.tmp
1071.42Sapb	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
1081.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
1091.42Sapb
1101.42Sapb# Compare all output files
1111.42Sapbtest:	${OUTFILES} .PHONY
1121.42Sapb	@failed= ; \
1131.42Sapb	for test in ${TESTNAMES}; do \
1141.42Sapb	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
1151.42Sapb	  || failed="$${failed}$${failed:+ }$${test}" ; \
1161.42Sapb	done ; \
1171.42Sapb	if [ -n "$${failed}" ]; then \
1181.42Sapb	  echo "Failed tests: $${failed}" ; false ; \
1191.42Sapb	else \
1201.42Sapb	  echo "All tests passed" ; \
1211.42Sapb	fi
1221.1Ssjg
1231.1Ssjgaccept:
1241.42Sapb	@for test in ${TESTNAMES}; do \
1251.42Sapb	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
1261.42Sapb	  || { echo "Replacing $${test}.exp" ; \
1271.42Sapb	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
1281.42Sapb	done
1291.1Ssjg
1301.42Sapb.-include <bsd.obj.mk>
131