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