Makefile revision 1.51
11.51Ssjg# $NetBSD: Makefile,v 1.51 2014/10/20 23:21:11 sjg 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.21Ssjg	export \
281.21Ssjg	export-all \
291.36Ssjg	export-env \
301.26Ssjg	doterror \
311.19Sapb	dotwait \
321.34Ssjg	forloop \
331.24Ssjg	forsubst \
341.32Sjoerg	hash \
351.31Ssjg	misc \
361.20Ssjg	moderrs \
371.11Ssjg	modmatch \
381.18Ssjg	modmisc \
391.15Ssjg	modorder \
401.11Ssjg	modts \
411.11Ssjg	modword \
421.35Ssjg	order \
431.13Ssjg	posix \
441.22Ssjg	qequals \
451.38Ssjg	sunshcmd \
461.31Ssjg	sysv \
471.11Ssjg	ternary \
481.25Ssjg	unexport \
491.25Ssjg	unexport-env \
501.39Sapb	varcmd \
511.43Sapb	varmisc \
521.39Sapb	varshell
531.11Ssjg
541.51Ssjg# these tests were broken by referting POSIX chanegs
551.51SsjgSTRICT_POSIX_TESTS = \
561.51Ssjg	escape \
571.51Ssjg	impsrc \
581.51Ssjg	phony-end \
591.51Ssjg	posix1 \
601.51Ssjg	suffixes
611.51Ssjg
621.42Sapb# Override make flags for certain tests
631.26Ssjgflags.doterror=
641.35Ssjgflags.order=-j1
651.26Ssjg
661.42SapbOUTFILES= ${TESTNAMES:S/$/.out/}
671.42Sapb
681.42Sapball: ${OUTFILES}
691.9Ssjg
701.48SapbCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
711.48SapbCLEANFILES += obj*.[och] lib*.a		# posix1.mk
721.49SsjgCLEANFILES += issue* .[ab]*		# suffixes.mk
731.48SapbCLEANRECURSIVE += dir dummy		# posix1.mk
741.48Sapb
751.1Ssjgclean:
761.48Sapb	rm -f ${CLEANFILES}
771.48Sapb.if !empty(CLEANRECURSIVE)
781.48Sapb	rm -rf ${CLEANRECURSIVE}
791.48Sapb.endif
801.1Ssjg
811.15SsjgTEST_MAKE?= ${.MAKE}
821.27SsjgTOOL_SED?= sed
831.1Ssjg
841.28Ssjg# ensure consistent results from sort(1)
851.30SsjgLC_ALL= C
861.28SsjgLANG= C
871.29Ssjg.export LANG LC_ALL
881.28Ssjg
891.42Sapb# the tests are actually done with sub-makes.
901.42Sapb.SUFFIXES: .mk .rawout .out
911.42Sapb.mk.rawout:
921.42Sapb	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
931.42Sapb	-@cd ${.OBJDIR} && \
941.42Sapb	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
951.42Sapb	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
961.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
971.42Sapb
981.12Ssjg# We always pretend .MAKE was called 'make' 
991.12Ssjg# and strip ${.CURDIR}/ from the output
1001.13Ssjg# and replace anything after 'stopped in' with unit-tests
1011.12Ssjg# so the results can be compared.
1021.42Sapb.rawout.out:
1031.42Sapb	@echo postprocess ${.TARGET}
1041.42Sapb	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
1051.42Sapb	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
1061.42Sapb	  -e '/stopped/s, /.*, unit-tests,' \
1071.42Sapb	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
1081.42Sapb	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
1091.42Sapb	  < ${.IMPSRC} > ${.TARGET}.tmp
1101.42Sapb	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
1111.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
1121.42Sapb
1131.42Sapb# Compare all output files
1141.42Sapbtest:	${OUTFILES} .PHONY
1151.42Sapb	@failed= ; \
1161.42Sapb	for test in ${TESTNAMES}; do \
1171.42Sapb	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
1181.42Sapb	  || failed="$${failed}$${failed:+ }$${test}" ; \
1191.42Sapb	done ; \
1201.42Sapb	if [ -n "$${failed}" ]; then \
1211.42Sapb	  echo "Failed tests: $${failed}" ; false ; \
1221.42Sapb	else \
1231.42Sapb	  echo "All tests passed" ; \
1241.42Sapb	fi
1251.1Ssjg
1261.1Ssjgaccept:
1271.42Sapb	@for test in ${TESTNAMES}; do \
1281.42Sapb	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
1291.42Sapb	  || { echo "Replacing $${test}.exp" ; \
1301.42Sapb	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
1311.42Sapb	done
1321.1Ssjg
1331.50Ssjg.if exists(${TEST_MAKE})
1341.50Ssjg${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
1351.50Ssjg.endif
1361.50Ssjg
1371.42Sapb.-include <bsd.obj.mk>
138