Makefile revision 1.35
11.35Ssjg# $NetBSD: Makefile,v 1.35 2012/11/09 19:08:28 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.26Ssjg	doterror \
281.19Sapb	dotwait \
291.34Ssjg	forloop \
301.24Ssjg	forsubst \
311.32Sjoerg	hash \
321.31Ssjg	misc \
331.20Ssjg	moderrs \
341.11Ssjg	modmatch \
351.18Ssjg	modmisc \
361.15Ssjg	modorder \
371.11Ssjg	modts \
381.11Ssjg	modword \
391.35Ssjg	order \
401.33Ssjg	phony-end \
411.13Ssjg	posix \
421.22Ssjg	qequals \
431.31Ssjg	sysv \
441.11Ssjg	ternary \
451.25Ssjg	unexport \
461.25Ssjg	unexport-env \
471.11Ssjg	varcmd
481.11Ssjg
491.11Ssjgall: ${SUBFILES}
501.11Ssjg
511.26Ssjgflags.doterror=
521.35Ssjgflags.order=-j1
531.26Ssjg
541.11Ssjg# the tests are actually done with sub-makes.
551.11Ssjg.PHONY: ${SUBFILES}
561.19Sapb.PRECIOUS: ${SUBFILES}
571.11Ssjg${SUBFILES}:
581.26Ssjg	-@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
591.9Ssjg
601.1Ssjgclean:
611.1Ssjg	rm -f *.out *.fail *.core
621.1Ssjg
631.27Ssjg.-include <bsd.obj.mk>
641.1Ssjg
651.15SsjgTEST_MAKE?= ${.MAKE}
661.27SsjgTOOL_SED?= sed
671.1Ssjg
681.28Ssjg# ensure consistent results from sort(1)
691.30SsjgLC_ALL= C
701.28SsjgLANG= C
711.29Ssjg.export LANG LC_ALL
721.28Ssjg
731.11Ssjg# The driver.
741.12Ssjg# We always pretend .MAKE was called 'make' 
751.12Ssjg# and strip ${.CURDIR}/ from the output
761.13Ssjg# and replace anything after 'stopped in' with unit-tests
771.12Ssjg# so the results can be compared.
781.1Ssjgtest:
791.1Ssjg	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
801.6Ssjg	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
811.23Sapb	${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \
821.13Ssjg	-e '/stopped/s, /.*, unit-tests,' \
831.17Sapb	-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
841.17Sapb	-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
851.1Ssjg	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
861.7Ssjg	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
871.1Ssjg
881.1Ssjgaccept:
891.1Ssjg	mv test.out ${.CURDIR}/test.exp
901.1Ssjg
91