Makefile revision 1.55
11.55Srillig# $NetBSD: Makefile,v 1.55 2020/04/29 23:15:21 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.12Ssjg	cond1 \
271.52Ssjg	cond2 \
281.26Ssjg	error \
291.21Ssjg	export \
301.21Ssjg	export-all \
311.36Ssjg	export-env \
321.26Ssjg	doterror \
331.19Sapb	dotwait \
341.34Ssjg	forloop \
351.24Ssjg	forsubst \
361.32Sjoerg	hash \
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.13Ssjg	posix \
461.22Ssjg	qequals \
471.38Ssjg	sunshcmd \
481.31Ssjg	sysv \
491.11Ssjg	ternary \
501.25Ssjg	unexport \
511.25Ssjg	unexport-env \
521.39Sapb	varcmd \
531.43Sapb	varmisc \
541.54Srillig	varmod-edge \
551.53Schristos	varquote \
561.39Sapb	varshell
571.11Ssjg
581.51Ssjg# these tests were broken by referting POSIX chanegs
591.51SsjgSTRICT_POSIX_TESTS = \
601.51Ssjg	escape \
611.51Ssjg	impsrc \
621.51Ssjg	phony-end \
631.51Ssjg	posix1 \
641.51Ssjg	suffixes
651.51Ssjg
661.42Sapb# Override make flags for certain tests
671.26Ssjgflags.doterror=
681.35Ssjgflags.order=-j1
691.26Ssjg
701.42SapbOUTFILES= ${TESTNAMES:S/$/.out/}
711.42Sapb
721.42Sapball: ${OUTFILES}
731.9Ssjg
741.48SapbCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
751.48SapbCLEANFILES += obj*.[och] lib*.a		# posix1.mk
761.49SsjgCLEANFILES += issue* .[ab]*		# suffixes.mk
771.48SapbCLEANRECURSIVE += dir dummy		# posix1.mk
781.48Sapb
791.1Ssjgclean:
801.48Sapb	rm -f ${CLEANFILES}
811.48Sapb.if !empty(CLEANRECURSIVE)
821.48Sapb	rm -rf ${CLEANRECURSIVE}
831.48Sapb.endif
841.1Ssjg
851.15SsjgTEST_MAKE?= ${.MAKE}
861.27SsjgTOOL_SED?= sed
871.1Ssjg
881.28Ssjg# ensure consistent results from sort(1)
891.30SsjgLC_ALL= C
901.28SsjgLANG= C
911.29Ssjg.export LANG LC_ALL
921.28Ssjg
931.42Sapb# the tests are actually done with sub-makes.
941.42Sapb.SUFFIXES: .mk .rawout .out
951.42Sapb.mk.rawout:
961.42Sapb	@echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
971.42Sapb	-@cd ${.OBJDIR} && \
981.42Sapb	{ ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
991.42Sapb	  2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
1001.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
1011.42Sapb
1021.12Ssjg# We always pretend .MAKE was called 'make' 
1031.12Ssjg# and strip ${.CURDIR}/ from the output
1041.13Ssjg# and replace anything after 'stopped in' with unit-tests
1051.12Ssjg# so the results can be compared.
1061.42Sapb.rawout.out:
1071.42Sapb	@echo postprocess ${.TARGET}
1081.42Sapb	@${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
1091.42Sapb	  -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
1101.42Sapb	  -e '/stopped/s, /.*, unit-tests,' \
1111.42Sapb	  -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
1121.42Sapb	  -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
1131.42Sapb	  < ${.IMPSRC} > ${.TARGET}.tmp
1141.42Sapb	@echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
1151.42Sapb	@mv ${.TARGET}.tmp ${.TARGET}
1161.42Sapb
1171.42Sapb# Compare all output files
1181.42Sapbtest:	${OUTFILES} .PHONY
1191.42Sapb	@failed= ; \
1201.42Sapb	for test in ${TESTNAMES}; do \
1211.42Sapb	  diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
1221.42Sapb	  || failed="$${failed}$${failed:+ }$${test}" ; \
1231.42Sapb	done ; \
1241.42Sapb	if [ -n "$${failed}" ]; then \
1251.42Sapb	  echo "Failed tests: $${failed}" ; false ; \
1261.42Sapb	else \
1271.42Sapb	  echo "All tests passed" ; \
1281.42Sapb	fi
1291.1Ssjg
1301.1Ssjgaccept:
1311.42Sapb	@for test in ${TESTNAMES}; do \
1321.42Sapb	  cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
1331.42Sapb	  || { echo "Replacing $${test}.exp" ; \
1341.42Sapb	       cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
1351.42Sapb	done
1361.1Ssjg
1371.50Ssjg.if exists(${TEST_MAKE})
1381.50Ssjg${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
1391.50Ssjg.endif
1401.50Ssjg
1411.42Sapb.-include <bsd.obj.mk>
142