1# $NetBSD: Makefile,v 1.32 2011/04/07 01:40:02 joerg Exp $ 2# 3# Unit tests for make(1) 4# The main targets are: 5# 6# all: run all the tests 7# test: run 'all', capture output and compare to expected results 8# accept: move generated output to expected results 9# 10# Adding a test case. 11# Each feature should get its own set of tests in its own suitably 12# named makefile which should be added to SUBFILES to hook it in. 13# 14 15.MAIN: all 16 17UNIT_TESTS:= ${.PARSEDIR} 18 19# Simple sub-makefiles - we run them as a black box 20# keep the list sorted. 21SUBFILES= \ 22 comment \ 23 cond1 \ 24 error \ 25 export \ 26 export-all \ 27 doterror \ 28 dotwait \ 29 forsubst \ 30 hash \ 31 misc \ 32 moderrs \ 33 modmatch \ 34 modmisc \ 35 modorder \ 36 modts \ 37 modword \ 38 posix \ 39 qequals \ 40 sysv \ 41 ternary \ 42 unexport \ 43 unexport-env \ 44 varcmd 45 46all: ${SUBFILES} 47 48flags.doterror= 49 50# the tests are actually done with sub-makes. 51.PHONY: ${SUBFILES} 52.PRECIOUS: ${SUBFILES} 53${SUBFILES}: 54 -@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@ 55 56clean: 57 rm -f *.out *.fail *.core 58 59.-include <bsd.obj.mk> 60 61TEST_MAKE?= ${.MAKE} 62TOOL_SED?= sed 63 64# ensure consistent results from sort(1) 65LC_ALL= C 66LANG= C 67.export LANG LC_ALL 68 69# The driver. 70# We always pretend .MAKE was called 'make' 71# and strip ${.CURDIR}/ from the output 72# and replace anything after 'stopped in' with unit-tests 73# so the results can be compared. 74test: 75 @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1" 76 @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \ 77 ${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \ 78 -e '/stopped/s, /.*, unit-tests,' \ 79 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 80 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \ 81 tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; } 82 diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out 83 84accept: 85 mv test.out ${.CURDIR}/test.exp 86 87