1*0a6a1f1dSLionel Sambuc# $NetBSD: Makefile,v 1.52 2015/05/05 21:51:09 sjg Exp $ 22e2caf59SThomas Veerman# 32e2caf59SThomas Veerman# Unit tests for make(1) 42e2caf59SThomas Veerman# The main targets are: 52e2caf59SThomas Veerman# 62e2caf59SThomas Veerman# all: run all the tests 7*0a6a1f1dSLionel Sambuc# test: run 'all', and compare to expected results 82e2caf59SThomas Veerman# accept: move generated output to expected results 92e2caf59SThomas Veerman# 102e2caf59SThomas Veerman# Adding a test case. 112e2caf59SThomas Veerman# Each feature should get its own set of tests in its own suitably 12*0a6a1f1dSLionel Sambuc# named makefile (*.mk), with its own set of expected results (*.exp), 13*0a6a1f1dSLionel Sambuc# and it should be added to the TESTNAMES list. 142e2caf59SThomas Veerman# 152e2caf59SThomas Veerman 162e2caf59SThomas Veerman.MAIN: all 172e2caf59SThomas Veerman 182e2caf59SThomas VeermanUNIT_TESTS:= ${.PARSEDIR} 19*0a6a1f1dSLionel Sambuc.PATH: ${UNIT_TESTS} 202e2caf59SThomas Veerman 21*0a6a1f1dSLionel Sambuc# Each test is in a sub-makefile. 22*0a6a1f1dSLionel Sambuc# Keep the list sorted. 23*0a6a1f1dSLionel SambucTESTNAMES= \ 242e2caf59SThomas Veerman comment \ 252e2caf59SThomas Veerman cond1 \ 26*0a6a1f1dSLionel Sambuc cond2 \ 272e2caf59SThomas Veerman error \ 282e2caf59SThomas Veerman export \ 292e2caf59SThomas Veerman export-all \ 3084d9c625SLionel Sambuc export-env \ 312e2caf59SThomas Veerman doterror \ 322e2caf59SThomas Veerman dotwait \ 332bc7c627SLionel Sambuc forloop \ 342e2caf59SThomas Veerman forsubst \ 352e2caf59SThomas Veerman hash \ 362e2caf59SThomas Veerman misc \ 372e2caf59SThomas Veerman moderrs \ 382e2caf59SThomas Veerman modmatch \ 392e2caf59SThomas Veerman modmisc \ 402e2caf59SThomas Veerman modorder \ 412e2caf59SThomas Veerman modts \ 422e2caf59SThomas Veerman modword \ 4384d9c625SLionel Sambuc order \ 442e2caf59SThomas Veerman posix \ 452e2caf59SThomas Veerman qequals \ 4684d9c625SLionel Sambuc sunshcmd \ 472e2caf59SThomas Veerman sysv \ 482e2caf59SThomas Veerman ternary \ 492e2caf59SThomas Veerman unexport \ 502e2caf59SThomas Veerman unexport-env \ 51*0a6a1f1dSLionel Sambuc varcmd \ 52*0a6a1f1dSLionel Sambuc varmisc \ 53*0a6a1f1dSLionel Sambuc varshell 542e2caf59SThomas Veerman 55*0a6a1f1dSLionel Sambuc# these tests were broken by referting POSIX chanegs 56*0a6a1f1dSLionel SambucSTRICT_POSIX_TESTS = \ 57*0a6a1f1dSLionel Sambuc escape \ 58*0a6a1f1dSLionel Sambuc impsrc \ 59*0a6a1f1dSLionel Sambuc phony-end \ 60*0a6a1f1dSLionel Sambuc posix1 \ 61*0a6a1f1dSLionel Sambuc suffixes 622e2caf59SThomas Veerman 63*0a6a1f1dSLionel Sambuc# Override make flags for certain tests 642e2caf59SThomas Veermanflags.doterror= 6584d9c625SLionel Sambucflags.order=-j1 662e2caf59SThomas Veerman 67*0a6a1f1dSLionel SambucOUTFILES= ${TESTNAMES:S/$/.out/} 68*0a6a1f1dSLionel Sambuc 69*0a6a1f1dSLionel Sambucall: ${OUTFILES} 70*0a6a1f1dSLionel Sambuc 71*0a6a1f1dSLionel SambucCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp 72*0a6a1f1dSLionel SambucCLEANFILES += obj*.[och] lib*.a # posix1.mk 73*0a6a1f1dSLionel SambucCLEANFILES += issue* .[ab]* # suffixes.mk 74*0a6a1f1dSLionel SambucCLEANRECURSIVE += dir dummy # posix1.mk 752e2caf59SThomas Veerman 762e2caf59SThomas Veermanclean: 77*0a6a1f1dSLionel Sambuc rm -f ${CLEANFILES} 78*0a6a1f1dSLionel Sambuc.if !empty(CLEANRECURSIVE) 79*0a6a1f1dSLionel Sambuc rm -rf ${CLEANRECURSIVE} 80*0a6a1f1dSLionel Sambuc.endif 812e2caf59SThomas Veerman 822e2caf59SThomas VeermanTEST_MAKE?= ${.MAKE} 832e2caf59SThomas VeermanTOOL_SED?= sed 842e2caf59SThomas Veerman 852e2caf59SThomas Veerman# ensure consistent results from sort(1) 862e2caf59SThomas VeermanLC_ALL= C 872e2caf59SThomas VeermanLANG= C 882e2caf59SThomas Veerman.export LANG LC_ALL 892e2caf59SThomas Veerman 90*0a6a1f1dSLionel Sambuc# the tests are actually done with sub-makes. 91*0a6a1f1dSLionel Sambuc.SUFFIXES: .mk .rawout .out 92*0a6a1f1dSLionel Sambuc.mk.rawout: 93*0a6a1f1dSLionel Sambuc @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 94*0a6a1f1dSLionel Sambuc -@cd ${.OBJDIR} && \ 95*0a6a1f1dSLionel Sambuc { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 96*0a6a1f1dSLionel Sambuc 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 97*0a6a1f1dSLionel Sambuc @mv ${.TARGET}.tmp ${.TARGET} 98*0a6a1f1dSLionel Sambuc 992e2caf59SThomas Veerman# We always pretend .MAKE was called 'make' 1002e2caf59SThomas Veerman# and strip ${.CURDIR}/ from the output 1012e2caf59SThomas Veerman# and replace anything after 'stopped in' with unit-tests 1022e2caf59SThomas Veerman# so the results can be compared. 103*0a6a1f1dSLionel Sambuc.rawout.out: 104*0a6a1f1dSLionel Sambuc @echo postprocess ${.TARGET} 105*0a6a1f1dSLionel Sambuc @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 106*0a6a1f1dSLionel Sambuc -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 1072e2caf59SThomas Veerman -e '/stopped/s, /.*, unit-tests,' \ 1082e2caf59SThomas Veerman -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 109*0a6a1f1dSLionel Sambuc -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \ 110*0a6a1f1dSLionel Sambuc < ${.IMPSRC} > ${.TARGET}.tmp 111*0a6a1f1dSLionel Sambuc @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 112*0a6a1f1dSLionel Sambuc @mv ${.TARGET}.tmp ${.TARGET} 113*0a6a1f1dSLionel Sambuc 114*0a6a1f1dSLionel Sambuc# Compare all output files 115*0a6a1f1dSLionel Sambuctest: ${OUTFILES} .PHONY 116*0a6a1f1dSLionel Sambuc @failed= ; \ 117*0a6a1f1dSLionel Sambuc for test in ${TESTNAMES}; do \ 118*0a6a1f1dSLionel Sambuc diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 119*0a6a1f1dSLionel Sambuc || failed="$${failed}$${failed:+ }$${test}" ; \ 120*0a6a1f1dSLionel Sambuc done ; \ 121*0a6a1f1dSLionel Sambuc if [ -n "$${failed}" ]; then \ 122*0a6a1f1dSLionel Sambuc echo "Failed tests: $${failed}" ; false ; \ 123*0a6a1f1dSLionel Sambuc else \ 124*0a6a1f1dSLionel Sambuc echo "All tests passed" ; \ 125*0a6a1f1dSLionel Sambuc fi 1262e2caf59SThomas Veerman 1272e2caf59SThomas Veermanaccept: 128*0a6a1f1dSLionel Sambuc @for test in ${TESTNAMES}; do \ 129*0a6a1f1dSLionel Sambuc cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 130*0a6a1f1dSLionel Sambuc || { echo "Replacing $${test}.exp" ; \ 131*0a6a1f1dSLionel Sambuc cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 132*0a6a1f1dSLionel Sambuc done 1332e2caf59SThomas Veerman 134*0a6a1f1dSLionel Sambuc.if exists(${TEST_MAKE}) 135*0a6a1f1dSLionel Sambuc${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} 136*0a6a1f1dSLionel Sambuc.endif 137*0a6a1f1dSLionel Sambuc 138*0a6a1f1dSLionel Sambuc.-include <bsd.obj.mk> 139