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