Makefile revision 1.42
11.42Sapb# $NetBSD: Makefile,v 1.42 2014/08/21 13:44:51 apb Exp $ 21.1Ssjg# 31.1Ssjg# Unit tests for make(1) 41.1Ssjg# The main targets are: 51.1Ssjg# 61.1Ssjg# all: run all the tests 71.42Sapb# test: run 'all', and compare to expected results 81.1Ssjg# accept: move generated output to expected results 91.1Ssjg# 101.1Ssjg# Adding a test case. 111.11Ssjg# Each feature should get its own set of tests in its own suitably 121.42Sapb# named makefile (*.mk), with its own set of expected results (*.exp), 131.42Sapb# and it should be added to the TESTNAMES list. 141.1Ssjg# 151.1Ssjg 161.1Ssjg.MAIN: all 171.1Ssjg 181.7SsjgUNIT_TESTS:= ${.PARSEDIR} 191.7Ssjg 201.42Sapb# Each test is in a sub-makefile. 211.42Sapb# Keep the list sorted. 221.42SapbTESTNAMES= \ 231.16Srpaulo comment \ 241.12Ssjg cond1 \ 251.26Ssjg error \ 261.21Ssjg export \ 271.21Ssjg export-all \ 281.36Ssjg export-env \ 291.26Ssjg doterror \ 301.19Sapb dotwait \ 311.34Ssjg forloop \ 321.24Ssjg forsubst \ 331.32Sjoerg hash \ 341.31Ssjg misc \ 351.20Ssjg moderrs \ 361.11Ssjg modmatch \ 371.18Ssjg modmisc \ 381.15Ssjg modorder \ 391.11Ssjg modts \ 401.11Ssjg modword \ 411.35Ssjg order \ 421.33Ssjg phony-end \ 431.13Ssjg posix \ 441.22Ssjg qequals \ 451.38Ssjg sunshcmd \ 461.31Ssjg sysv \ 471.11Ssjg ternary \ 481.25Ssjg unexport \ 491.25Ssjg unexport-env \ 501.39Sapb varcmd \ 511.39Sapb varshell 521.11Ssjg 531.42Sapb# Override make flags for certain tests 541.26Ssjgflags.doterror= 551.35Ssjgflags.order=-j1 561.26Ssjg 571.42SapbOUTFILES= ${TESTNAMES:S/$/.out/} 581.42Sapb 591.42Sapball: ${OUTFILES} 601.9Ssjg 611.1Ssjgclean: 621.42Sapb rm -f *.rawout *.out *.status *.tmp *.core *.tmp 631.1Ssjg 641.15SsjgTEST_MAKE?= ${.MAKE} 651.27SsjgTOOL_SED?= sed 661.1Ssjg 671.28Ssjg# ensure consistent results from sort(1) 681.30SsjgLC_ALL= C 691.28SsjgLANG= C 701.29Ssjg.export LANG LC_ALL 711.28Ssjg 721.42Sapb# the tests are actually done with sub-makes. 731.42Sapb.SUFFIXES: .mk .rawout .out 741.42Sapb.mk.rawout: 751.42Sapb @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 761.42Sapb -@cd ${.OBJDIR} && \ 771.42Sapb { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 781.42Sapb 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 791.42Sapb @mv ${.TARGET}.tmp ${.TARGET} 801.42Sapb 811.12Ssjg# We always pretend .MAKE was called 'make' 821.12Ssjg# and strip ${.CURDIR}/ from the output 831.13Ssjg# and replace anything after 'stopped in' with unit-tests 841.12Ssjg# so the results can be compared. 851.42Sapb.rawout.out: 861.42Sapb @echo postprocess ${.TARGET} 871.42Sapb @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 881.42Sapb -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 891.42Sapb -e '/stopped/s, /.*, unit-tests,' \ 901.42Sapb -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 911.42Sapb -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \ 921.42Sapb < ${.IMPSRC} > ${.TARGET}.tmp 931.42Sapb @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 941.42Sapb @mv ${.TARGET}.tmp ${.TARGET} 951.42Sapb 961.42Sapb# Compare all output files 971.42Sapbtest: ${OUTFILES} .PHONY 981.42Sapb @failed= ; \ 991.42Sapb for test in ${TESTNAMES}; do \ 1001.42Sapb diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 1011.42Sapb || failed="$${failed}$${failed:+ }$${test}" ; \ 1021.42Sapb done ; \ 1031.42Sapb if [ -n "$${failed}" ]; then \ 1041.42Sapb echo "Failed tests: $${failed}" ; false ; \ 1051.42Sapb else \ 1061.42Sapb echo "All tests passed" ; \ 1071.42Sapb fi 1081.1Ssjg 1091.1Ssjgaccept: 1101.42Sapb @for test in ${TESTNAMES}; do \ 1111.42Sapb cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 1121.42Sapb || { echo "Replacing $${test}.exp" ; \ 1131.42Sapb cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 1141.42Sapb done 1151.1Ssjg 1161.42Sapb.-include <bsd.obj.mk> 117