1291978Ssjg# $Id: Makefile.in,v 1.48 2015/12/07 04:06:29 sjg Exp $ 2236769Sobrien# 3282740Ssjg# $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 9281812Ssjg# 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 14281812Ssjg# named makefile (*.mk), with its own set of expected results (*.exp), 15281812Ssjg# and it should be added to the TESTNAMES list. 16236769Sobrien# 17236769Sobrien 18236769Sobriensrcdir= @srcdir@ 19236769Sobrien 20236769Sobrien.MAIN: all 21236769Sobrien 22236769SobrienUNIT_TESTS:= ${srcdir} 23281812Ssjg.PATH: ${UNIT_TESTS} 24236769Sobrien 25281812Ssjg# Each test is in a sub-makefile. 26281812Ssjg# Keep the list sorted. 27281812SsjgTESTNAMES= \ 28236769Sobrien comment \ 29236769Sobrien cond1 \ 30282740Ssjg 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 \ 55281812Ssjg varcmd \ 56281812Ssjg varmisc \ 57281812Ssjg varshell 58236769Sobrien 59281812Ssjg# these tests were broken by referting POSIX chanegs 60281812SsjgSTRICT_POSIX_TESTS = \ 61281812Ssjg escape \ 62281812Ssjg impsrc \ 63281812Ssjg phony-end \ 64281812Ssjg posix1 \ 65281812Ssjg suffixes 66236769Sobrien 67281812Ssjg# Override make flags for certain tests 68236769Sobrienflags.doterror= 69243115Ssjgflags.order=-j1 70236769Sobrien 71281812SsjgOUTFILES= ${TESTNAMES:S/$/.out/} 72236769Sobrien 73281812Ssjgall: ${OUTFILES} 74281812Ssjg 75281812SsjgCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp 76281812SsjgCLEANFILES += obj*.[och] lib*.a # posix1.mk 77281812SsjgCLEANFILES += issue* .[ab]* # suffixes.mk 78281812SsjgCLEANRECURSIVE += dir dummy # posix1.mk 79281812Ssjg 80236769Sobrienclean: 81281812Ssjg rm -f ${CLEANFILES} 82281812Ssjg.if !empty(CLEANRECURSIVE) 83281812Ssjg rm -rf ${CLEANRECURSIVE} 84281812Ssjg.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 99281812Ssjg# some tests need extra post-processing 100281812SsjgSED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \ 101281812Ssjg -e '/command/s,No such.*,not found,' 102281812Ssjg 103281812Ssjg# the tests are actually done with sub-makes. 104281812Ssjg.SUFFIXES: .mk .rawout .out 105281812Ssjg.mk.rawout: 106281812Ssjg @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 107281812Ssjg -@cd ${.OBJDIR} && \ 108281812Ssjg { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 109281812Ssjg 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 110281812Ssjg @mv ${.TARGET}.tmp ${.TARGET} 111281812Ssjg 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. 116281812Ssjg.rawout.out: 117281812Ssjg @echo postprocess ${.TARGET} 118281812Ssjg @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 119281812Ssjg -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 120281812Ssjg -e '/stopped/s, /.*, unit-tests,' \ 121281812Ssjg -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 122281812Ssjg -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \ 123281812Ssjg < ${.IMPSRC} > ${.TARGET}.tmp 124281812Ssjg @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 125281812Ssjg @mv ${.TARGET}.tmp ${.TARGET} 126236769Sobrien 127281812Ssjg# Compare all output files 128281812Ssjgtest: ${OUTFILES} .PHONY 129281812Ssjg @failed= ; \ 130281812Ssjg for test in ${TESTNAMES}; do \ 131291978Ssjg ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \ 132281812Ssjg || failed="$${failed}$${failed:+ }$${test}" ; \ 133281812Ssjg done ; \ 134281812Ssjg if [ -n "$${failed}" ]; then \ 135281812Ssjg echo "Failed tests: $${failed}" ; false ; \ 136281812Ssjg else \ 137281812Ssjg echo "All tests passed" ; \ 138281812Ssjg fi 139281812Ssjg 140236769Sobrienaccept: 141281812Ssjg @for test in ${TESTNAMES}; do \ 142281812Ssjg cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 143281812Ssjg || { echo "Replacing $${test}.exp" ; \ 144281812Ssjg cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 145281812Ssjg done 146236769Sobrien 147281812Ssjg.if exists(${TEST_MAKE}) 148281812Ssjg${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} 149281812Ssjg.endif 150281812Ssjg 151281812Ssjg.-include <obj.mk> 152