Makefile revision 1.64
11.64Srillig# $NetBSD: Makefile,v 1.64 2020/07/25 21:19:29 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.61Srillig# Settable variables 151.61Srillig# 161.61Srillig# TEST_MAKE 171.61Srillig# The make program to be tested. 181.61Srillig# 191.60Srillig# 201.60Srillig# Adding a test case 211.60Srillig# 221.11Ssjg# Each feature should get its own set of tests in its own suitably 231.42Sapb# named makefile (*.mk), with its own set of expected results (*.exp), 241.61Srillig# and it should be added to the TESTS list. 251.60Srillig# 261.60Srillig# Any added files must also be added to src/distrib/sets/lists/tests/mi. 271.61Srillig# Makefiles that are not added to TESTS must be ignored in 281.60Srillig# src/tests/usr.bin/make/t_make.sh (example: include-sub). 291.60Srillig# 301.1Ssjg 311.61Srillig# Each test is in a sub-makefile. 321.61Srillig# Keep the list sorted. 331.61SrilligTESTS+= comment 341.61SrilligTESTS+= cond-late 351.61SrilligTESTS+= cond-short 361.61SrilligTESTS+= cond1 371.61SrilligTESTS+= cond2 381.61SrilligTESTS+= dollar 391.61SrilligTESTS+= doterror 401.61SrilligTESTS+= dotwait 411.64SrilligTESTS+= envfirst 421.61SrilligTESTS+= error 431.63SsjgTESTS+= # escape # broken by reverting POSIX changes 441.61SrilligTESTS+= export 451.61SrilligTESTS+= export-all 461.61SrilligTESTS+= export-env 471.61SrilligTESTS+= forloop 481.61SrilligTESTS+= forsubst 491.61SrilligTESTS+= hash 501.63SsjgTESTS+= # impsrc # broken by reverting POSIX changes 511.61SrilligTESTS+= include-main 521.61SrilligTESTS+= misc 531.61SrilligTESTS+= moderrs 541.61SrilligTESTS+= modmatch 551.61SrilligTESTS+= modmisc 561.61SrilligTESTS+= modorder 571.61SrilligTESTS+= modts 581.61SrilligTESTS+= modword 591.61SrilligTESTS+= order 601.63SsjgTESTS+= # phony-end # broken by reverting POSIX changes 611.61SrilligTESTS+= posix 621.63SsjgTESTS+= # posix1 # broken by reverting POSIX changes 631.61SrilligTESTS+= qequals 641.63SsjgTESTS+= # suffixes # broken by reverting POSIX changes 651.61SrilligTESTS+= sunshcmd 661.61SrilligTESTS+= sysv 671.61SrilligTESTS+= ternary 681.61SrilligTESTS+= unexport 691.61SrilligTESTS+= unexport-env 701.61SrilligTESTS+= varcmd 711.64SrilligTESTS+= vardebug 721.64SrilligTESTS+= varfind 731.61SrilligTESTS+= varmisc 741.61SrilligTESTS+= varmod-edge 751.61SrilligTESTS+= varquote 761.61SrilligTESTS+= varshell 771.61Srillig 781.64Srillig# Override environment variables for some of the tests. 791.64SrilligENV.envfirst= FROM_ENV=value-from-env 801.64Srillig 811.64Srillig# Override make flags for some of the tests; default is -k. 821.61SrilligFLAGS.doterror= # none 831.61SrilligFLAGS.order= -j1 841.64SrilligFLAGS.envfirst= -e 851.64SrilligFLAGS.vardebug= -k -dv FROM_CMDLINE= 861.61Srillig 871.61Srillig# Some tests need extra post-processing. 881.62SrilligSED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' 891.61SrilligSED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 901.61SrilligSED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 911.61Srillig 921.64Srillig# Some tests need an additional round of postprocessing. 931.64SrilligPOSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 941.64Srillig 951.61Srillig# End of the configuration section. 961.61Srillig 971.1Ssjg.MAIN: all 981.1Ssjg 991.61SrilligUNIT_TESTS:= ${.PARSEDIR} 1001.44Sapb.PATH: ${UNIT_TESTS} 1011.7Ssjg 1021.61SrilligOUTFILES= ${TESTS:=.out} 1031.42Sapb 1041.42Sapball: ${OUTFILES} 1051.9Ssjg 1061.61SrilligCLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp 1071.61SrilligCLEANFILES+= obj*.[och] lib*.a # posix1.mk 1081.61SrilligCLEANFILES+= issue* .[ab]* # suffixes.mk 1091.61SrilligCLEANRECURSIVE+= dir dummy # posix1.mk 1101.48Sapb 1111.1Ssjgclean: 1121.48Sapb rm -f ${CLEANFILES} 1131.48Sapb.if !empty(CLEANRECURSIVE) 1141.48Sapb rm -rf ${CLEANRECURSIVE} 1151.48Sapb.endif 1161.1Ssjg 1171.61SrilligTEST_MAKE?= ${.MAKE} 1181.61SrilligTOOL_SED?= sed 1191.1Ssjg 1201.28Ssjg# ensure consistent results from sort(1) 1211.61SrilligLC_ALL= C 1221.61SrilligLANG= C 1231.29Ssjg.export LANG LC_ALL 1241.28Ssjg 1251.42Sapb# the tests are actually done with sub-makes. 1261.42Sapb.SUFFIXES: .mk .rawout .out 1271.42Sapb.mk.rawout: 1281.64Srillig @echo testing ${.IMPSRC} 1291.64Srillig @set -eu; \ 1301.64Srillig cd ${.OBJDIR}; \ 1311.64Srillig ${ENV.${.TARGET:R}} ${TEST_MAKE} \ 1321.64Srillig ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 1331.64Srillig > ${.TARGET}.tmp 2>&1 \ 1341.64Srillig && status=$$? || status=$$?; \ 1351.64Srillig echo $$status > ${.TARGET:R}.status 1361.42Sapb @mv ${.TARGET}.tmp ${.TARGET} 1371.42Sapb 1381.62Srillig# Post-process the test output so that the results can be compared. 1391.62Srillig# 1401.62Srillig# always pretend .MAKE was called 'make' 1411.61Srillig_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 1421.61Srillig_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 1431.62Srillig# replace anything after 'stopped in' with unit-tests 1441.61Srillig_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 1451.62Srillig# strip ${.CURDIR}/ from the output 1461.61Srillig_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 1471.61Srillig_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 1481.61Srillig 1491.42Sapb.rawout.out: 1501.42Sapb @echo postprocess ${.TARGET} 1511.61Srillig @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 1521.64Srillig < ${.IMPSRC} > ${.TARGET}.tmp1 1531.64Srillig @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 1541.64Srillig @rm ${.TARGET}.tmp1 1551.64Srillig @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 1561.64Srillig @mv ${.TARGET}.tmp2 ${.TARGET} 1571.42Sapb 1581.42Sapb# Compare all output files 1591.42Sapbtest: ${OUTFILES} .PHONY 1601.42Sapb @failed= ; \ 1611.61Srillig for test in ${TESTS}; do \ 1621.42Sapb diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 1631.42Sapb || failed="$${failed}$${failed:+ }$${test}" ; \ 1641.42Sapb done ; \ 1651.42Sapb if [ -n "$${failed}" ]; then \ 1661.42Sapb echo "Failed tests: $${failed}" ; false ; \ 1671.42Sapb else \ 1681.42Sapb echo "All tests passed" ; \ 1691.42Sapb fi 1701.1Ssjg 1711.1Ssjgaccept: 1721.61Srillig @for test in ${TESTS}; do \ 1731.42Sapb cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 1741.42Sapb || { echo "Replacing $${test}.exp" ; \ 1751.42Sapb cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 1761.42Sapb done 1771.1Ssjg 1781.50Ssjg.if exists(${TEST_MAKE}) 1791.61Srillig${TESTS:=.rawout}: ${TEST_MAKE} 1801.50Ssjg.endif 1811.50Ssjg 1821.42Sapb.-include <bsd.obj.mk> 183