Makefile revision 1.21
11.21Ssjg# $NetBSD: Makefile,v 1.21 2007/10/05 15:27:46 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.21Ssjg	export \
251.21Ssjg	export-all \
261.19Sapb	dotwait \
271.20Ssjg	moderrs \
281.11Ssjg	modmatch \
291.18Ssjg	modmisc \
301.15Ssjg	modorder \
311.11Ssjg	modts \
321.11Ssjg	modword \
331.13Ssjg	posix \
341.11Ssjg	ternary \
351.11Ssjg	varcmd
361.11Ssjg
371.11Ssjgall: ${SUBFILES}
381.11Ssjg
391.11Ssjg# the tests are actually done with sub-makes.
401.11Ssjg.PHONY: ${SUBFILES}
411.19Sapb.PRECIOUS: ${SUBFILES}
421.11Ssjg${SUBFILES}:
431.13Ssjg	-@${.MAKE} -k -f ${UNIT_TESTS}/$@
441.9Ssjg
451.1Ssjgclean:
461.1Ssjg	rm -f *.out *.fail *.core
471.1Ssjg
481.1Ssjg.include <bsd.obj.mk>
491.1Ssjg
501.15SsjgTEST_MAKE?= ${.MAKE}
511.1Ssjg
521.11Ssjg# The driver.
531.12Ssjg# We always pretend .MAKE was called 'make' 
541.12Ssjg# and strip ${.CURDIR}/ from the output
551.13Ssjg# and replace anything after 'stopped in' with unit-tests
561.12Ssjg# so the results can be compared.
571.1Ssjgtest:
581.1Ssjg	@echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
591.6Ssjg	@cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
601.17Sapb	sed -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \
611.13Ssjg	-e '/stopped/s, /.*, unit-tests,' \
621.17Sapb	-e 's,${.CURDIR:C/\./\\\./g}/,,g' \
631.17Sapb	-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
641.1Ssjg	tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
651.7Ssjg	diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
661.1Ssjg
671.1Ssjgaccept:
681.1Ssjg	mv test.out ${.CURDIR}/test.exp
691.1Ssjg
70