Makefile revision 1.60
11.60Srillig# $NetBSD: Makefile,v 1.60 2020/07/04 21:04:25 rillig Exp $ 21.1Ssjg# 31.1Ssjg# Unit tests for make(1) 41.60Srillig# 51.1Ssjg# The main targets are: 61.1Ssjg# 71.60Srillig# all: 81.60Srillig# run all the tests 91.60Srillig# test: 101.60Srillig# run 'all', and compare to expected results 111.60Srillig# accept: 121.60Srillig# move generated output to expected results 131.60Srillig# 141.60Srillig# 151.60Srillig# Adding a test case 161.60Srillig# 171.11Ssjg# Each feature should get its own set of tests in its own suitably 181.42Sapb# named makefile (*.mk), with its own set of expected results (*.exp), 191.42Sapb# and it should be added to the TESTNAMES list. 201.60Srillig# 211.60Srillig# Any added files must also be added to src/distrib/sets/lists/tests/mi. 221.60Srillig# Makefiles that are not added to TESTNAMES must be ignored in 231.60Srillig# src/tests/usr.bin/make/t_make.sh (example: include-sub). 241.60Srillig# 251.1Ssjg 261.1Ssjg.MAIN: all 271.1Ssjg 281.7SsjgUNIT_TESTS:= ${.PARSEDIR} 291.44Sapb.PATH: ${UNIT_TESTS} 301.7Ssjg 311.42Sapb# Each test is in a sub-makefile. 321.42Sapb# Keep the list sorted. 331.42SapbTESTNAMES= \ 341.16Srpaulo comment \ 351.55Srillig cond-late \ 361.59Srillig cond-short \ 371.12Ssjg cond1 \ 381.52Ssjg cond2 \ 391.56Srillig dollar \ 401.57Srillig doterror \ 411.57Srillig dotwait \ 421.26Ssjg error \ 431.21Ssjg export \ 441.21Ssjg export-all \ 451.36Ssjg export-env \ 461.34Ssjg forloop \ 471.24Ssjg forsubst \ 481.32Sjoerg hash \ 491.58Srillig include-main \ 501.31Ssjg misc \ 511.20Ssjg moderrs \ 521.11Ssjg modmatch \ 531.18Ssjg modmisc \ 541.15Ssjg modorder \ 551.11Ssjg modts \ 561.11Ssjg modword \ 571.35Ssjg order \ 581.13Ssjg posix \ 591.22Ssjg qequals \ 601.38Ssjg sunshcmd \ 611.31Ssjg sysv \ 621.11Ssjg ternary \ 631.25Ssjg unexport \ 641.25Ssjg unexport-env \ 651.39Sapb varcmd \ 661.43Sapb varmisc \ 671.54Srillig varmod-edge \ 681.53Schristos varquote \ 691.39Sapb varshell 701.11Ssjg 711.51Ssjg# these tests were broken by referting POSIX chanegs 721.51SsjgSTRICT_POSIX_TESTS = \ 731.51Ssjg escape \ 741.51Ssjg impsrc \ 751.51Ssjg phony-end \ 761.51Ssjg posix1 \ 771.51Ssjg suffixes 781.51Ssjg 791.42Sapb# Override make flags for certain tests 801.26Ssjgflags.doterror= 811.35Ssjgflags.order=-j1 821.26Ssjg 831.42SapbOUTFILES= ${TESTNAMES:S/$/.out/} 841.42Sapb 851.42Sapball: ${OUTFILES} 861.9Ssjg 871.48SapbCLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp 881.48SapbCLEANFILES += obj*.[och] lib*.a # posix1.mk 891.49SsjgCLEANFILES += issue* .[ab]* # suffixes.mk 901.48SapbCLEANRECURSIVE += dir dummy # posix1.mk 911.48Sapb 921.1Ssjgclean: 931.48Sapb rm -f ${CLEANFILES} 941.48Sapb.if !empty(CLEANRECURSIVE) 951.48Sapb rm -rf ${CLEANRECURSIVE} 961.48Sapb.endif 971.1Ssjg 981.15SsjgTEST_MAKE?= ${.MAKE} 991.27SsjgTOOL_SED?= sed 1001.1Ssjg 1011.28Ssjg# ensure consistent results from sort(1) 1021.30SsjgLC_ALL= C 1031.28SsjgLANG= C 1041.29Ssjg.export LANG LC_ALL 1051.28Ssjg 1061.42Sapb# the tests are actually done with sub-makes. 1071.42Sapb.SUFFIXES: .mk .rawout .out 1081.42Sapb.mk.rawout: 1091.42Sapb @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 1101.42Sapb -@cd ${.OBJDIR} && \ 1111.42Sapb { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 1121.42Sapb 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 1131.42Sapb @mv ${.TARGET}.tmp ${.TARGET} 1141.42Sapb 1151.12Ssjg# We always pretend .MAKE was called 'make' 1161.12Ssjg# and strip ${.CURDIR}/ from the output 1171.13Ssjg# and replace anything after 'stopped in' with unit-tests 1181.12Ssjg# so the results can be compared. 1191.42Sapb.rawout.out: 1201.42Sapb @echo postprocess ${.TARGET} 1211.42Sapb @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 1221.42Sapb -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 1231.42Sapb -e '/stopped/s, /.*, unit-tests,' \ 1241.42Sapb -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 1251.42Sapb -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \ 1261.42Sapb < ${.IMPSRC} > ${.TARGET}.tmp 1271.42Sapb @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 1281.42Sapb @mv ${.TARGET}.tmp ${.TARGET} 1291.42Sapb 1301.42Sapb# Compare all output files 1311.42Sapbtest: ${OUTFILES} .PHONY 1321.42Sapb @failed= ; \ 1331.42Sapb for test in ${TESTNAMES}; do \ 1341.42Sapb diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 1351.42Sapb || failed="$${failed}$${failed:+ }$${test}" ; \ 1361.42Sapb done ; \ 1371.42Sapb if [ -n "$${failed}" ]; then \ 1381.42Sapb echo "Failed tests: $${failed}" ; false ; \ 1391.42Sapb else \ 1401.42Sapb echo "All tests passed" ; \ 1411.42Sapb fi 1421.1Ssjg 1431.1Ssjgaccept: 1441.42Sapb @for test in ${TESTNAMES}; do \ 1451.42Sapb cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 1461.42Sapb || { echo "Replacing $${test}.exp" ; \ 1471.42Sapb cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 1481.42Sapb done 1491.1Ssjg 1501.50Ssjg.if exists(${TEST_MAKE}) 1511.50Ssjg${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} 1521.50Ssjg.endif 1531.50Ssjg 1541.42Sapb.-include <bsd.obj.mk> 155