1292068Ssjg# $Id: Makefile.in,v 1.48 2015/12/07 04:06:29 sjg Exp $ 2236769Sobrien# 3292068Ssjg# $NetBSD: Makefile,v 1.52 2015/05/05 21:51:09 sjg Exp $ 4236769Sobrien# 5236769Sobrien# Unit tests for make(1) 6236769Sobrien# The main targets are: 7236769Sobrien# 8236769Sobrien# all: run all the tests 9292068Ssjg# test: run 'all', and compare to expected results 10236769Sobrien# accept: move generated output to expected results 11236769Sobrien# 12236769Sobrien# Adding a test case. 13236769Sobrien# Each feature should get its own set of tests in its own suitably 14292068Ssjg# named makefile (*.mk), with its own set of expected results (*.exp), 15292068Ssjg# and it should be added to the TESTNAMES list. 16236769Sobrien# 17236769Sobrien 18236769Sobriensrcdir= @srcdir@ 19236769Sobrien 20236769Sobrien.MAIN: all 21236769Sobrien 22236769SobrienUNIT_TESTS:= ${srcdir} 23292068Ssjg.PATH: ${UNIT_TESTS} 24236769Sobrien 25292068Ssjg# Each test is in a sub-makefile. 26292068Ssjg# Keep the list sorted. 27292068SsjgTESTNAMES= \ 28236769Sobrien comment \ 29236769Sobrien cond1 \ 30292068Ssjg cond2 \ 31236769Sobrien error \ 32236769Sobrien export \ 33236769Sobrien export-all \ 34249033Ssjg export-env \ 35236769Sobrien doterror \ 36236769Sobrien dotwait \ 37237578Sobrien forloop \ 38236769Sobrien forsubst \ 39236769Sobrien hash \ 40236769Sobrien misc \ 41236769Sobrien moderrs \ 42236769Sobrien modmatch \ 43236769Sobrien modmisc \ 44236769Sobrien modorder \ 45236769Sobrien modts \ 46236769Sobrien modword \ 47243115Ssjg order \ 48236769Sobrien posix \ 49236769Sobrien qequals \ 50255253Ssjg sunshcmd \ 51236769Sobrien sysv \ 52236769Sobrien ternary \ 53236769Sobrien unexport \ 54236769Sobrien unexport-env \ 55292068Ssjg varcmd \ 56292068Ssjg varmisc \ 57292068Ssjg varshell 58236769Sobrien 59292068Ssjg# these tests were broken by referting POSIX chanegs 60292068SsjgSTRICT_POSIX_TESTS = \ 61292068Ssjg escape \ 62292068Ssjg impsrc \ 63292068Ssjg phony-end \ 64292068Ssjg posix1 \ 65292068Ssjg suffixes 66236769Sobrien 67292068Ssjg# Override make flags for certain tests 68236769Sobrienflags.doterror= 69243115Ssjgflags.order=-j1 70236769Sobrien 71292068SsjgOUTFILES= ${TESTNAMES:S/$/.out/} 72236769Sobrien 73292068Ssjgall: ${OUTFILES} 74292068Ssjg 75292068SsjgCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp 76292068SsjgCLEANFILES += obj*.[och] lib*.a # posix1.mk 77292068SsjgCLEANFILES += issue* .[ab]* # suffixes.mk 78292068SsjgCLEANRECURSIVE += dir dummy # posix1.mk 79292068Ssjg 80236769Sobrienclean: 81292068Ssjg rm -f ${CLEANFILES} 82292068Ssjg.if !empty(CLEANRECURSIVE) 83292068Ssjg rm -rf ${CLEANRECURSIVE} 84292068Ssjg.endif 85236769Sobrien 86236769SobrienTEST_MAKE?= ${.MAKE} 87236769SobrienTOOL_SED?= sed 88236769SobrienTOOL_TR?= tr 89236769SobrienTOOL_DIFF?= diff 90236769SobrienDIFF_FLAGS?= @diff_u@ 91236769Sobrien 92249033Ssjg.if defined(.PARSEDIR) 93236769Sobrien# ensure consistent results from sort(1) 94236769SobrienLC_ALL= C 95236769SobrienLANG= C 96236769Sobrien.export LANG LC_ALL 97249033Ssjg.endif 98236769Sobrien 99292068Ssjg# some tests need extra post-processing 100292068SsjgSED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \ 101292068Ssjg -e '/command/s,No such.*,not found,' 102292068Ssjg 103292068Ssjg# the tests are actually done with sub-makes. 104292068Ssjg.SUFFIXES: .mk .rawout .out 105292068Ssjg.mk.rawout: 106292068Ssjg @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 107292068Ssjg -@cd ${.OBJDIR} && \ 108292068Ssjg { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 109292068Ssjg 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 110292068Ssjg @mv ${.TARGET}.tmp ${.TARGET} 111292068Ssjg 112236769Sobrien# We always pretend .MAKE was called 'make' 113236769Sobrien# and strip ${.CURDIR}/ from the output 114236769Sobrien# and replace anything after 'stopped in' with unit-tests 115236769Sobrien# so the results can be compared. 116292068Ssjg.rawout.out: 117292068Ssjg @echo postprocess ${.TARGET} 118292068Ssjg @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 119292068Ssjg -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 120292068Ssjg -e '/stopped/s, /.*, unit-tests,' \ 121292068Ssjg -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 122292068Ssjg -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \ 123292068Ssjg < ${.IMPSRC} > ${.TARGET}.tmp 124292068Ssjg @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 125292068Ssjg @mv ${.TARGET}.tmp ${.TARGET} 126236769Sobrien 127292068Ssjg# Compare all output files 128292068Ssjgtest: ${OUTFILES} .PHONY 129292068Ssjg @failed= ; \ 130292068Ssjg for test in ${TESTNAMES}; do \ 131292068Ssjg ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \ 132292068Ssjg || failed="$${failed}$${failed:+ }$${test}" ; \ 133292068Ssjg done ; \ 134292068Ssjg if [ -n "$${failed}" ]; then \ 135292068Ssjg echo "Failed tests: $${failed}" ; false ; \ 136292068Ssjg else \ 137292068Ssjg echo "All tests passed" ; \ 138292068Ssjg fi 139292068Ssjg 140236769Sobrienaccept: 141292068Ssjg @for test in ${TESTNAMES}; do \ 142292068Ssjg cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 143292068Ssjg || { echo "Replacing $${test}.exp" ; \ 144292068Ssjg cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 145292068Ssjg done 146236769Sobrien 147292068Ssjg.if exists(${TEST_MAKE}) 148292068Ssjg${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} 149292068Ssjg.endif 150292068Ssjg 151292068Ssjg.-include <obj.mk> 152