Makefile revision 1.66
11.1Sriastrad# $NetBSD: Makefile,v 1.66 2020/07/26 22:15:36 rillig Exp $ 21.1Sriastrad# 31.1Sriastrad# Unit tests for make(1) 41.1Sriastrad# 51.1Sriastrad# The main targets are: 61.1Sriastrad# 71.1Sriastrad# all: 81.1Sriastrad# run all the tests 91.1Sriastrad# test: 101.1Sriastrad# run 'all', and compare to expected results 111.1Sriastrad# accept: 121.1Sriastrad# move generated output to expected results 131.1Sriastrad# 141.1Sriastrad# Settable variables 151.1Sriastrad# 161.1Sriastrad# TEST_MAKE 171.1Sriastrad# The make program to be tested. 181.1Sriastrad# 191.1Sriastrad# 201.1Sriastrad# Adding a test case 211.1Sriastrad# 221.1Sriastrad# Each feature should get its own set of tests in its own suitably 231.1Sriastrad# named makefile (*.mk), with its own set of expected results (*.exp), 241.1Sriastrad# and it should be added to the TESTS list. 251.1Sriastrad# 261.1Sriastrad# Any added files must also be added to src/distrib/sets/lists/tests/mi. 271.1Sriastrad# Makefiles that are not added to TESTS must be ignored in 281.1Sriastrad# src/tests/usr.bin/make/t_make.sh (example: include-sub). 291.1Sriastrad# 301.1Sriastrad 311.1Sriastrad# Each test is in a sub-makefile. 321.1Sriastrad# Keep the list sorted. 331.1SriastradTESTS+= comment 341.1SriastradTESTS+= cond-late 351.1SriastradTESTS+= cond-short 361.1SriastradTESTS+= cond1 371.1SriastradTESTS+= cond2 381.1SriastradTESTS+= dollar 391.1SriastradTESTS+= doterror 401.1SriastradTESTS+= dotwait 411.1SriastradTESTS+= envfirst 421.1SriastradTESTS+= error 431.1SriastradTESTS+= # escape # broken by reverting POSIX changes 441.1SriastradTESTS+= export 451.1SriastradTESTS+= export-all 461.1SriastradTESTS+= export-env 471.1SriastradTESTS+= forloop 481.1SriastradTESTS+= forsubst 491.1SriastradTESTS+= hash 501.1SriastradTESTS+= # impsrc # broken by reverting POSIX changes 511.1SriastradTESTS+= include-main 521.1SriastradTESTS+= misc 531.1SriastradTESTS+= moderrs 541.1SriastradTESTS+= modmatch 551.1SriastradTESTS+= modmisc 561.1SriastradTESTS+= modorder 571.1SriastradTESTS+= modts 581.1SriastradTESTS+= modword 591.1SriastradTESTS+= order 601.1SriastradTESTS+= # phony-end # broken by reverting POSIX changes 611.1SriastradTESTS+= posix 621.1SriastradTESTS+= # posix1 # broken by reverting POSIX changes 631.1SriastradTESTS+= qequals 641.1SriastradTESTS+= # suffixes # broken by reverting POSIX changes 651.1SriastradTESTS+= sunshcmd 661.1SriastradTESTS+= sysv 671.1SriastradTESTS+= ternary 681.1SriastradTESTS+= unexport 691.1SriastradTESTS+= unexport-env 701.1SriastradTESTS+= varcmd 711.1SriastradTESTS+= vardebug 721.1SriastradTESTS+= varfind 731.1SriastradTESTS+= varmisc 741.1SriastradTESTS+= varmod-edge 751.1SriastradTESTS+= varparse-dynamic 761.1SriastradTESTS+= varquote 771.1SriastradTESTS+= varshell 781.1Sriastrad 791.1Sriastrad# Override environment variables for some of the tests. 801.1SriastradENV.envfirst= FROM_ENV=value-from-env 811.1SriastradENV.varmisc= FROM_ENV=env 821.1SriastradENV.varmisc+= FROM_ENV_BEFORE=env 831.1SriastradENV.varmisc+= FROM_ENV_AFTER=env 841.1Sriastrad 851.1Sriastrad# Override make flags for some of the tests; default is -k. 861.1SriastradFLAGS.doterror= # none 871.1SriastradFLAGS.order= -j1 881.1SriastradFLAGS.envfirst= -e 891.1SriastradFLAGS.vardebug= -k -dv FROM_CMDLINE= 901.1Sriastrad 911.1Sriastrad# Some tests need extra post-processing. 921.1SriastradSED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' 931.1SriastradSED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 941.1SriastradSED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 951.1Sriastrad 961.1Sriastrad# Some tests need an additional round of postprocessing. 971.1SriastradPOSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 981.1Sriastrad 991.1Sriastrad# End of the configuration section. 1001.1Sriastrad 1011.1Sriastrad.MAIN: all 1021.1Sriastrad 1031.1SriastradUNIT_TESTS:= ${.PARSEDIR} 1041.1Sriastrad.PATH: ${UNIT_TESTS} 1051.1Sriastrad 1061.1SriastradOUTFILES= ${TESTS:=.out} 1071.1Sriastrad 1081.1Sriastradall: ${OUTFILES} 1091.1Sriastrad 1101.1SriastradCLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp 1111.1SriastradCLEANFILES+= obj*.[och] lib*.a # posix1.mk 1121.1SriastradCLEANFILES+= issue* .[ab]* # suffixes.mk 1131.1SriastradCLEANRECURSIVE+= dir dummy # posix1.mk 1141.1Sriastrad 1151.1Sriastradclean: 1161.1Sriastrad rm -f ${CLEANFILES} 1171.1Sriastrad.if !empty(CLEANRECURSIVE) 1181.1Sriastrad rm -rf ${CLEANRECURSIVE} 1191.1Sriastrad.endif 1201.1Sriastrad 1211.1SriastradTEST_MAKE?= ${.MAKE} 1221.1SriastradTOOL_SED?= sed 1231.1Sriastrad 1241.1Sriastrad# ensure consistent results from sort(1) 1251.1SriastradLC_ALL= C 1261.1SriastradLANG= C 1271.1Sriastrad.export LANG LC_ALL 1281.1Sriastrad 1291.1Sriastrad# the tests are actually done with sub-makes. 1301.1Sriastrad.SUFFIXES: .mk .rawout .out 1311.1Sriastrad.mk.rawout: 1321.1Sriastrad @echo testing ${.IMPSRC} 1331.1Sriastrad @set -eu; \ 1341.1Sriastrad cd ${.OBJDIR}; \ 1351.1Sriastrad ${ENV.${.TARGET:R}} ${TEST_MAKE} \ 1361.1Sriastrad ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 1371.1Sriastrad > ${.TARGET}.tmp 2>&1 \ 1381.1Sriastrad && status=$$? || status=$$?; \ 1391.1Sriastrad echo $$status > ${.TARGET:R}.status 1401.1Sriastrad @mv ${.TARGET}.tmp ${.TARGET} 1411.1Sriastrad 1421.1Sriastrad# Post-process the test output so that the results can be compared. 1431.1Sriastrad# 1441.1Sriastrad# always pretend .MAKE was called 'make' 1451.1Sriastrad_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 1461.1Sriastrad_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 1471.1Sriastrad# replace anything after 'stopped in' with unit-tests 1481.1Sriastrad_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 149# strip ${.CURDIR}/ from the output 150_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 151_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 152 153.rawout.out: 154 @echo postprocess ${.TARGET} 155 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 156 < ${.IMPSRC} > ${.TARGET}.tmp1 157 @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 158 @rm ${.TARGET}.tmp1 159 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 160 @mv ${.TARGET}.tmp2 ${.TARGET} 161 162# Compare all output files 163test: ${OUTFILES} .PHONY 164 @failed= ; \ 165 for test in ${TESTS}; do \ 166 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 167 || failed="$${failed}$${failed:+ }$${test}" ; \ 168 done ; \ 169 if [ -n "$${failed}" ]; then \ 170 echo "Failed tests: $${failed}" ; false ; \ 171 else \ 172 echo "All tests passed" ; \ 173 fi 174 175accept: 176 @for test in ${TESTS}; do \ 177 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 178 || { echo "Replacing $${test}.exp" ; \ 179 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 180 done 181 182.if exists(${TEST_MAKE}) 183${TESTS:=.rawout}: ${TEST_MAKE} 184.endif 185 186.-include <bsd.obj.mk> 187