Makefile revision 1.92
11.92Srillig# $NetBSD: Makefile,v 1.92 2020/08/15 01:49:07 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.78Srillig# To do that, just run "make sync-mi" in this directory. 281.78Srillig# 291.78Srillig# A few *.mk files are helper files for other tests (such as include-sub.mk) 301.78Srillig# and are thus not added to TESTS. Such files must be ignored in 311.78Srillig# src/tests/usr.bin/make/t_make.sh. 321.60Srillig# 331.1Ssjg 341.61Srillig# Each test is in a sub-makefile. 351.61Srillig# Keep the list sorted. 361.92Srillig# Any test that is commented out must be ignored in 371.92Srillig# src/tests/usr.bin/make/t_make.sh as well. 381.92SrilligTESTS+= # archive # broken on FreeBSD, enabled in t_make.sh 391.75SrilligTESTS+= cmdline 401.61SrilligTESTS+= comment 411.61SrilligTESTS+= cond-late 421.61SrilligTESTS+= cond-short 431.61SrilligTESTS+= cond1 441.61SrilligTESTS+= cond2 451.81SrilligTESTS+= counter 461.77SrilligTESTS+= dir 471.70SrilligTESTS+= directives 481.61SrilligTESTS+= dollar 491.61SrilligTESTS+= doterror 501.61SrilligTESTS+= dotwait 511.64SrilligTESTS+= envfirst 521.61SrilligTESTS+= error 531.63SsjgTESTS+= # escape # broken by reverting POSIX changes 541.61SrilligTESTS+= export 551.61SrilligTESTS+= export-all 561.61SrilligTESTS+= export-env 571.89SrilligTESTS+= export-variants 581.61SrilligTESTS+= forloop 591.61SrilligTESTS+= forsubst 601.61SrilligTESTS+= hash 611.86SrilligTESTS+= impsrc 621.61SrilligTESTS+= include-main 631.83SrilligTESTS+= lint 641.90SrilligTESTS+= make-exported 651.61SrilligTESTS+= misc 661.61SrilligTESTS+= moderrs 671.61SrilligTESTS+= modmatch 681.61SrilligTESTS+= modmisc 691.61SrilligTESTS+= modorder 701.61SrilligTESTS+= modts 711.61SrilligTESTS+= modword 721.61SrilligTESTS+= order 731.88SrilligTESTS+= phony-end 741.61SrilligTESTS+= posix 751.63SsjgTESTS+= # posix1 # broken by reverting POSIX changes 761.61SrilligTESTS+= qequals 771.84SrilligTESTS+= recursive 781.88SrilligTESTS+= # suffixes # runs into an endless loop (try -dA) 791.61SrilligTESTS+= sunshcmd 801.61SrilligTESTS+= sysv 811.61SrilligTESTS+= ternary 821.61SrilligTESTS+= unexport 831.61SrilligTESTS+= unexport-env 841.91SrilligTESTS+= use-inference 851.61SrilligTESTS+= varcmd 861.64SrilligTESTS+= vardebug 871.64SrilligTESTS+= varfind 881.61SrilligTESTS+= varmisc 891.61SrilligTESTS+= varmod-edge 901.66SrilligTESTS+= varparse-dynamic 911.61SrilligTESTS+= varquote 921.61SrilligTESTS+= varshell 931.61Srillig 941.64Srillig# Override environment variables for some of the tests. 951.82SrilligENV.counter= -i 961.64SrilligENV.envfirst= FROM_ENV=value-from-env 971.69SrilligENV.export= -i PATH=${PATH:Q} 981.89SrilligENV.export-variants= -i PATH=${PATH:Q} 991.83SrilligENV.lint= -i 1001.90SrilligENV.make-exported= -i PATH=${PATH:Q} 1011.84SrilligENV.recursive= -i 1021.65SrilligENV.varmisc= FROM_ENV=env 1031.65SrilligENV.varmisc+= FROM_ENV_BEFORE=env 1041.65SrilligENV.varmisc+= FROM_ENV_AFTER=env 1051.64Srillig 1061.64Srillig# Override make flags for some of the tests; default is -k. 1071.82SrilligFLAGS.counter= -r -dv 1081.61SrilligFLAGS.doterror= # none 1091.68SrilligFLAGS.envfirst= -e 1101.71SsjgFLAGS.export= -r 1111.83SrilligFLAGS.lint= -dL -k 1121.61SrilligFLAGS.order= -j1 1131.85SsjgFLAGS.recursive= -dL -r 1141.64SrilligFLAGS.vardebug= -k -dv FROM_CMDLINE= 1151.61Srillig 1161.61Srillig# Some tests need extra post-processing. 1171.80SrilligSED_CMDS.moderrs+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 1181.80SrilligSED_CMDS.modmisc+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 1191.79SrilligSED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 1201.61SrilligSED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 1211.61SrilligSED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 1221.61Srillig 1231.64Srillig# Some tests need an additional round of postprocessing. 1241.81SrilligPOSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 1251.64SrilligPOSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 1261.64Srillig 1271.89Srilligexport-all.rawout: export.mk 1281.89Srilligunexport.rawout: export.mk 1291.89Srilligunexport-env.rawout: export.mk 1301.89Srillig 1311.61Srillig# End of the configuration section. 1321.61Srillig 1331.1Ssjg.MAIN: all 1341.1Ssjg 1351.61SrilligUNIT_TESTS:= ${.PARSEDIR} 1361.44Sapb.PATH: ${UNIT_TESTS} 1371.7Ssjg 1381.61SrilligOUTFILES= ${TESTS:=.out} 1391.42Sapb 1401.42Sapball: ${OUTFILES} 1411.9Ssjg 1421.61SrilligCLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp 1431.61SrilligCLEANFILES+= obj*.[och] lib*.a # posix1.mk 1441.61SrilligCLEANFILES+= issue* .[ab]* # suffixes.mk 1451.61SrilligCLEANRECURSIVE+= dir dummy # posix1.mk 1461.48Sapb 1471.1Ssjgclean: 1481.48Sapb rm -f ${CLEANFILES} 1491.48Sapb.if !empty(CLEANRECURSIVE) 1501.48Sapb rm -rf ${CLEANRECURSIVE} 1511.48Sapb.endif 1521.1Ssjg 1531.61SrilligTEST_MAKE?= ${.MAKE} 1541.61SrilligTOOL_SED?= sed 1551.1Ssjg 1561.28Ssjg# ensure consistent results from sort(1) 1571.61SrilligLC_ALL= C 1581.61SrilligLANG= C 1591.29Ssjg.export LANG LC_ALL 1601.28Ssjg 1611.42Sapb# the tests are actually done with sub-makes. 1621.42Sapb.SUFFIXES: .mk .rawout .out 1631.42Sapb.mk.rawout: 1641.64Srillig @echo testing ${.IMPSRC} 1651.64Srillig @set -eu; \ 1661.64Srillig cd ${.OBJDIR}; \ 1671.73Ssjg env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \ 1681.64Srillig ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 1691.64Srillig > ${.TARGET}.tmp 2>&1 \ 1701.64Srillig && status=$$? || status=$$?; \ 1711.64Srillig echo $$status > ${.TARGET:R}.status 1721.42Sapb @mv ${.TARGET}.tmp ${.TARGET} 1731.42Sapb 1741.62Srillig# Post-process the test output so that the results can be compared. 1751.62Srillig# 1761.62Srillig# always pretend .MAKE was called 'make' 1771.61Srillig_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 1781.61Srillig_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 1791.62Srillig# replace anything after 'stopped in' with unit-tests 1801.61Srillig_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 1811.62Srillig# strip ${.CURDIR}/ from the output 1821.61Srillig_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 1831.61Srillig_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 1841.61Srillig 1851.42Sapb.rawout.out: 1861.42Sapb @echo postprocess ${.TARGET} 1871.61Srillig @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 1881.64Srillig < ${.IMPSRC} > ${.TARGET}.tmp1 1891.74Ssjg @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 1901.64Srillig @rm ${.TARGET}.tmp1 1911.64Srillig @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 1921.64Srillig @mv ${.TARGET}.tmp2 ${.TARGET} 1931.42Sapb 1941.42Sapb# Compare all output files 1951.42Sapbtest: ${OUTFILES} .PHONY 1961.42Sapb @failed= ; \ 1971.61Srillig for test in ${TESTS}; do \ 1981.42Sapb diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 1991.42Sapb || failed="$${failed}$${failed:+ }$${test}" ; \ 2001.42Sapb done ; \ 2011.42Sapb if [ -n "$${failed}" ]; then \ 2021.42Sapb echo "Failed tests: $${failed}" ; false ; \ 2031.42Sapb else \ 2041.42Sapb echo "All tests passed" ; \ 2051.42Sapb fi 2061.1Ssjg 2071.1Ssjgaccept: 2081.61Srillig @for test in ${TESTS}; do \ 2091.42Sapb cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 2101.42Sapb || { echo "Replacing $${test}.exp" ; \ 2111.42Sapb cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 2121.42Sapb done 2131.1Ssjg 2141.78SrilligSYNC_MI_AWK= \ 2151.78Srillig BEGIN { \ 2161.78Srillig testsdir = "usr.bin/make/unit-tests"; \ 2171.78Srillig linestart = "./usr/tests/" testsdir; \ 2181.78Srillig fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 2191.78Srillig cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \ 2201.78Srillig } \ 2211.78Srillig function startswith(s, prefix) { \ 2221.78Srillig return substr(s, 1, length(prefix)) == prefix; \ 2231.78Srillig } \ 2241.78Srillig startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \ 2251.78Srillig { print $$0 } \ 2261.78Srillig $$1 == linestart "/Makefile" { system(cmd) } 2271.78Srillig 2281.78Srilligsync-mi: 2291.78Srillig @set -eu; \ 2301.78Srillig cd "${MAKEFILE:tA:H}/../../.."; \ 2311.78Srillig mi="distrib/sets/lists/tests/mi"; \ 2321.78Srillig awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \ 2331.78Srillig mv -f "$$mi.$@" "$$mi"; \ 2341.78Srillig cvs diff "$$mi" || true 2351.78Srillig 2361.50Ssjg.if exists(${TEST_MAKE}) 2371.61Srillig${TESTS:=.rawout}: ${TEST_MAKE} 2381.50Ssjg.endif 2391.50Ssjg 2401.42Sapb.-include <bsd.obj.mk> 241