1# $Id: Makefile.in,v 1.48 2015/12/07 04:06:29 sjg Exp $ 2# 3# $NetBSD: Makefile,v 1.52 2015/05/05 21:51:09 sjg Exp $ 4# 5# Unit tests for make(1) 6# The main targets are: 7# 8# all: run all the tests 9# test: run 'all', and compare to expected results 10# accept: move generated output to expected results 11# 12# Adding a test case. 13# Each feature should get its own set of tests in its own suitably 14# named makefile (*.mk), with its own set of expected results (*.exp), 15# and it should be added to the TESTNAMES list. 16# 17 18srcdir= @srcdir@ 19 20.MAIN: all 21 22UNIT_TESTS:= ${srcdir} 23.PATH: ${UNIT_TESTS} 24 25# Each test is in a sub-makefile. 26# Keep the list sorted. 27TESTNAMES= \ 28 comment \ 29 cond1 \ 30 cond2 \ 31 error \ 32 export \ 33 export-all \ 34 export-env \ 35 doterror \ 36 dotwait \ 37 forloop \ 38 forsubst \ 39 hash \ 40 misc \ 41 moderrs \ 42 modmatch \ 43 modmisc \ 44 modorder \ 45 modts \ 46 modword \ 47 order \ 48 posix \ 49 qequals \ 50 sunshcmd \ 51 sysv \ 52 ternary \ 53 unexport \ 54 unexport-env \ 55 varcmd \ 56 varmisc \ 57 varshell 58 59# these tests were broken by referting POSIX chanegs 60STRICT_POSIX_TESTS = \ 61 escape \ 62 impsrc \ 63 phony-end \ 64 posix1 \ 65 suffixes 66 67# Override make flags for certain tests 68flags.doterror= 69flags.order=-j1 70 71OUTFILES= ${TESTNAMES:S/$/.out/} 72 73all: ${OUTFILES} 74 75CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp 76CLEANFILES += obj*.[och] lib*.a # posix1.mk 77CLEANFILES += issue* .[ab]* # suffixes.mk 78CLEANRECURSIVE += dir dummy # posix1.mk 79 80clean: 81 rm -f ${CLEANFILES} 82.if !empty(CLEANRECURSIVE) 83 rm -rf ${CLEANRECURSIVE} 84.endif 85 86TEST_MAKE?= ${.MAKE} 87TOOL_SED?= sed 88TOOL_TR?= tr 89TOOL_DIFF?= diff 90DIFF_FLAGS?= @diff_u@ 91 92.if defined(.PARSEDIR) 93# ensure consistent results from sort(1) 94LC_ALL= C 95LANG= C 96.export LANG LC_ALL 97.endif 98 99# some tests need extra post-processing 100SED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \ 101 -e '/command/s,No such.*,not found,' 102 103# the tests are actually done with sub-makes. 104.SUFFIXES: .mk .rawout .out 105.mk.rawout: 106 @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 107 -@cd ${.OBJDIR} && \ 108 { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 109 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 110 @mv ${.TARGET}.tmp ${.TARGET} 111 112# We always pretend .MAKE was called 'make' 113# and strip ${.CURDIR}/ from the output 114# and replace anything after 'stopped in' with unit-tests 115# so the results can be compared. 116.rawout.out: 117 @echo postprocess ${.TARGET} 118 @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 119 -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 120 -e '/stopped/s, /.*, unit-tests,' \ 121 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 122 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \ 123 < ${.IMPSRC} > ${.TARGET}.tmp 124 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 125 @mv ${.TARGET}.tmp ${.TARGET} 126 127# Compare all output files 128test: ${OUTFILES} .PHONY 129 @failed= ; \ 130 for test in ${TESTNAMES}; do \ 131 ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \ 132 || failed="$${failed}$${failed:+ }$${test}" ; \ 133 done ; \ 134 if [ -n "$${failed}" ]; then \ 135 echo "Failed tests: $${failed}" ; false ; \ 136 else \ 137 echo "All tests passed" ; \ 138 fi 139 140accept: 141 @for test in ${TESTNAMES}; do \ 142 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 143 || { echo "Replacing $${test}.exp" ; \ 144 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 145 done 146 147.if exists(${TEST_MAKE}) 148${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} 149.endif 150 151.-include <obj.mk> 152