Makefile revision 1.42
1# $NetBSD: Makefile,v 1.42 2014/08/21 13:44:51 apb Exp $ 2# 3# Unit tests for make(1) 4# The main targets are: 5# 6# all: run all the tests 7# test: run 'all', 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 (*.mk), with its own set of expected results (*.exp), 13# and it should be added to the TESTNAMES list. 14# 15 16.MAIN: all 17 18UNIT_TESTS:= ${.PARSEDIR} 19 20# Each test is in a sub-makefile. 21# Keep the list sorted. 22TESTNAMES= \ 23 comment \ 24 cond1 \ 25 error \ 26 export \ 27 export-all \ 28 export-env \ 29 doterror \ 30 dotwait \ 31 forloop \ 32 forsubst \ 33 hash \ 34 misc \ 35 moderrs \ 36 modmatch \ 37 modmisc \ 38 modorder \ 39 modts \ 40 modword \ 41 order \ 42 phony-end \ 43 posix \ 44 qequals \ 45 sunshcmd \ 46 sysv \ 47 ternary \ 48 unexport \ 49 unexport-env \ 50 varcmd \ 51 varshell 52 53# Override make flags for certain tests 54flags.doterror= 55flags.order=-j1 56 57OUTFILES= ${TESTNAMES:S/$/.out/} 58 59all: ${OUTFILES} 60 61clean: 62 rm -f *.rawout *.out *.status *.tmp *.core *.tmp 63 64TEST_MAKE?= ${.MAKE} 65TOOL_SED?= sed 66 67# ensure consistent results from sort(1) 68LC_ALL= C 69LANG= C 70.export LANG LC_ALL 71 72# the tests are actually done with sub-makes. 73.SUFFIXES: .mk .rawout .out 74.mk.rawout: 75 @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 76 -@cd ${.OBJDIR} && \ 77 { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 78 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 79 @mv ${.TARGET}.tmp ${.TARGET} 80 81# We always pretend .MAKE was called 'make' 82# and strip ${.CURDIR}/ from the output 83# and replace anything after 'stopped in' with unit-tests 84# so the results can be compared. 85.rawout.out: 86 @echo postprocess ${.TARGET} 87 @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 88 -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 89 -e '/stopped/s, /.*, unit-tests,' \ 90 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 91 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \ 92 < ${.IMPSRC} > ${.TARGET}.tmp 93 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 94 @mv ${.TARGET}.tmp ${.TARGET} 95 96# Compare all output files 97test: ${OUTFILES} .PHONY 98 @failed= ; \ 99 for test in ${TESTNAMES}; do \ 100 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 101 || failed="$${failed}$${failed:+ }$${test}" ; \ 102 done ; \ 103 if [ -n "$${failed}" ]; then \ 104 echo "Failed tests: $${failed}" ; false ; \ 105 else \ 106 echo "All tests passed" ; \ 107 fi 108 109accept: 110 @for test in ${TESTNAMES}; do \ 111 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 112 || { echo "Replacing $${test}.exp" ; \ 113 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 114 done 115 116.-include <bsd.obj.mk> 117