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