Makefile revision 1.38
11.38Ssjg# $NetBSD: Makefile,v 1.38 2013/08/28 21:56:50 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.1Ssjg# test:	run 'all', capture output 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.11Ssjg# named makefile which should be added to SUBFILES to hook it in.
131.1Ssjg# 
141.1Ssjg
151.1Ssjg.MAIN: all
161.1Ssjg
171.7SsjgUNIT_TESTS:= ${.PARSEDIR}
181.7Ssjg
191.11Ssjg# Simple sub-makefiles - we run them as a black box
201.11Ssjg# keep the list sorted.
211.11SsjgSUBFILES= \
221.16Srpaulo	comment \
231.12Ssjg	cond1 \
241.26Ssjg	error \
251.21Ssjg	export \
261.21Ssjg	export-all \
271.36Ssjg	export-env \
281.26Ssjg	doterror \
291.19Sapb	dotwait \
301.34Ssjg	forloop \
311.24Ssjg	forsubst \
321.32Sjoerg	hash \
331.31Ssjg	misc \
341.20Ssjg	moderrs \
351.11Ssjg	modmatch \
361.18Ssjg	modmisc \
371.15Ssjg	modorder \
381.11Ssjg	modts \
391.11Ssjg	modword \
401.35Ssjg	order \
411.33Ssjg	phony-end \
421.13Ssjg	posix \
431.22Ssjg	qequals \
441.38Ssjg	sunshcmd \
451.31Ssjg	sysv \
461.11Ssjg	ternary \
471.25Ssjg	unexport \
481.25Ssjg	unexport-env \
491.11Ssjg	varcmd
501.11Ssjg
511.11Ssjgall: ${SUBFILES}
521.11Ssjg
531.26Ssjgflags.doterror=
541.35Ssjgflags.order=-j1
551.26Ssjg
561.11Ssjg# the tests are actually done with sub-makes.
571.11Ssjg.PHONY: ${SUBFILES}
581.19Sapb.PRECIOUS: ${SUBFILES}
591.11Ssjg${SUBFILES}:
601.26Ssjg	-@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
611.9Ssjg
621.1Ssjgclean:
631.1Ssjg	rm -f *.out *.fail *.core
641.1Ssjg
651.27Ssjg.-include <bsd.obj.mk>
661.1Ssjg
671.15SsjgTEST_MAKE?= ${.MAKE}
681.27SsjgTOOL_SED?= sed
691.1Ssjg
701.28Ssjg# ensure consistent results from sort(1)
711.30SsjgLC_ALL= C
721.28SsjgLANG= C
731.29Ssjg.export LANG LC_ALL
741.28Ssjg
751.11Ssjg# The driver.
761.12Ssjg# We always pretend .MAKE was called 'make' 
771.12Ssjg# and strip ${.CURDIR}/ from the output
781.13Ssjg# and replace anything after 'stopped in' with unit-tests
791.12Ssjg# so the results can be compared.
801.1Ssjgtest:
811.1Ssjg	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
821.6Ssjg	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
831.37Ssjg	${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[^:]*:,make:,' \
841.13Ssjg	-e '/stopped/s, /.*, unit-tests,' \
851.17Sapb	-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
861.17Sapb	-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
871.1Ssjg	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
881.7Ssjg	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
891.1Ssjg
901.1Ssjgaccept:
911.1Ssjg	mv test.out ${.CURDIR}/test.exp
921.1Ssjg
93