Makefile revision 1.59
11.59Srillig# $NetBSD: Makefile,v 1.59 2020/06/28 09:42:40 rillig 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.55Srillig	cond-late \
261.59Srillig	cond-short \
271.12Ssjg	cond1 \
281.52Ssjg	cond2 \
291.56Srillig	dollar \
301.57Srillig	doterror \
311.57Srillig	dotwait \
321.26Ssjg	error \
331.21Ssjg	export \
341.21Ssjg	export-all \
351.36Ssjg	export-env \
361.34Ssjg	forloop \
371.24Ssjg	forsubst \
381.32Sjoerg	hash \
391.58Srillig	include-main \
401.31Ssjg	misc \
411.20Ssjg	moderrs \
421.11Ssjg	modmatch \
431.18Ssjg	modmisc \
441.15Ssjg	modorder \
451.11Ssjg	modts \
461.11Ssjg	modword \
471.35Ssjg	order \
481.13Ssjg	posix \
491.22Ssjg	qequals \
501.38Ssjg	sunshcmd \
511.31Ssjg	sysv \
521.11Ssjg	ternary \
531.25Ssjg	unexport \
541.25Ssjg	unexport-env \
551.39Sapb	varcmd \
561.43Sapb	varmisc \
571.54Srillig	varmod-edge \
581.53Schristos	varquote \
591.39Sapb	varshell
601.11Ssjg
611.51Ssjg# these tests were broken by referting POSIX chanegs
621.51SsjgSTRICT_POSIX_TESTS = \
631.51Ssjg	escape \
641.51Ssjg	impsrc \
651.51Ssjg	phony-end \
661.51Ssjg	posix1 \
671.51Ssjg	suffixes
681.51Ssjg
691.42Sapb# Override make flags for certain tests
701.26Ssjgflags.doterror=
711.35Ssjgflags.order=-j1
721.26Ssjg
731.42SapbOUTFILES= ${TESTNAMES:S/$/.out/}
741.42Sapb
751.42Sapball: ${OUTFILES}
761.9Ssjg
771.48SapbCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
781.48SapbCLEANFILES += obj*.[och] lib*.a		# posix1.mk
791.49SsjgCLEANFILES += issue* .[ab]*		# suffixes.mk
801.48SapbCLEANRECURSIVE += dir dummy		# posix1.mk
811.48Sapb
821.1Ssjgclean:
831.48Sapb	rm -f ${CLEANFILES}
841.48Sapb.if !empty(CLEANRECURSIVE)
851.48Sapb	rm -rf ${CLEANRECURSIVE}
861.48Sapb.endif
871.1Ssjg
881.15SsjgTEST_MAKE?= ${.MAKE}
891.27SsjgTOOL_SED?= sed
901.1Ssjg
911.28Ssjg# ensure consistent results from sort(1)
921.30SsjgLC_ALL= C
931.28SsjgLANG= C
941.29Ssjg.export LANG LC_ALL
951.28Ssjg
961.42Sapb# the tests are actually done with sub-makes.
971.42Sapb.SUFFIXES: .mk .rawout .out
981.42Sapb.mk.rawout:
991.42Sapb	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
1001.42Sapb	-@cd ${.OBJDIR} && \
1011.42Sapb	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
1021.42Sapb	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
1031.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
1041.42Sapb
1051.12Ssjg# We always pretend .MAKE was called 'make' 
1061.12Ssjg# and strip ${.CURDIR}/ from the output
1071.13Ssjg# and replace anything after 'stopped in' with unit-tests
1081.12Ssjg# so the results can be compared.
1091.42Sapb.rawout.out:
1101.42Sapb	@echo postprocess ${.TARGET}
1111.42Sapb	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
1121.42Sapb	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
1131.42Sapb	  -e '/stopped/s, /.*, unit-tests,' \
1141.42Sapb	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
1151.42Sapb	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
1161.42Sapb	  < ${.IMPSRC} > ${.TARGET}.tmp
1171.42Sapb	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
1181.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
1191.42Sapb
1201.42Sapb# Compare all output files
1211.42Sapbtest:	${OUTFILES} .PHONY
1221.42Sapb	@failed= ; \
1231.42Sapb	for test in ${TESTNAMES}; do \
1241.42Sapb	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
1251.42Sapb	  || failed="$${failed}$${failed:+ }$${test}" ; \
1261.42Sapb	done ; \
1271.42Sapb	if [ -n "$${failed}" ]; then \
1281.42Sapb	  echo "Failed tests: $${failed}" ; false ; \
1291.42Sapb	else \
1301.42Sapb	  echo "All tests passed" ; \
1311.42Sapb	fi
1321.1Ssjg
1331.1Ssjgaccept:
1341.42Sapb	@for test in ${TESTNAMES}; do \
1351.42Sapb	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
1361.42Sapb	  || { echo "Replacing $${test}.exp" ; \
1371.42Sapb	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
1381.42Sapb	done
1391.1Ssjg
1401.50Ssjg.if exists(${TEST_MAKE})
1411.50Ssjg${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
1421.50Ssjg.endif
1431.50Ssjg
1441.42Sapb.-include <bsd.obj.mk>
145