Makefile revision 1.70
1# $NetBSD: Makefile,v 1.70 2020/07/27 20:46:17 rillig Exp $ 2# 3# Unit tests for make(1) 4# 5# The main targets are: 6# 7# all: 8# run all the tests 9# test: 10# run 'all', and compare to expected results 11# accept: 12# move generated output to expected results 13# 14# Settable variables 15# 16# TEST_MAKE 17# The make program to be tested. 18# 19# 20# Adding a test case 21# 22# Each feature should get its own set of tests in its own suitably 23# named makefile (*.mk), with its own set of expected results (*.exp), 24# and it should be added to the TESTS list. 25# 26# Any added files must also be added to src/distrib/sets/lists/tests/mi. 27# Makefiles that are not added to TESTS must be ignored in 28# src/tests/usr.bin/make/t_make.sh (example: include-sub). 29# 30 31# Each test is in a sub-makefile. 32# Keep the list sorted. 33TESTS+= archive 34TESTS+= comment 35TESTS+= cond-late 36TESTS+= cond-short 37TESTS+= cond1 38TESTS+= cond2 39TESTS+= directives 40TESTS+= dollar 41TESTS+= doterror 42TESTS+= dotwait 43TESTS+= envfirst 44TESTS+= error 45TESTS+= # escape # broken by reverting POSIX changes 46TESTS+= export 47TESTS+= export-all 48TESTS+= export-env 49TESTS+= forloop 50TESTS+= forsubst 51TESTS+= hash 52TESTS+= # impsrc # broken by reverting POSIX changes 53TESTS+= include-main 54TESTS+= misc 55TESTS+= moderrs 56TESTS+= modmatch 57TESTS+= modmisc 58TESTS+= modorder 59TESTS+= modts 60TESTS+= modword 61TESTS+= order 62TESTS+= # phony-end # broken by reverting POSIX changes 63TESTS+= posix 64TESTS+= # posix1 # broken by reverting POSIX changes 65TESTS+= qequals 66TESTS+= # suffixes # broken by reverting POSIX changes 67TESTS+= sunshcmd 68TESTS+= sysv 69TESTS+= ternary 70TESTS+= unexport 71TESTS+= unexport-env 72TESTS+= varcmd 73TESTS+= vardebug 74TESTS+= varfind 75TESTS+= varmisc 76TESTS+= varmod-edge 77TESTS+= varparse-dynamic 78TESTS+= varquote 79TESTS+= varshell 80 81# Override environment variables for some of the tests. 82ENV.envfirst= FROM_ENV=value-from-env 83ENV.export= -i PATH=${PATH:Q} 84ENV.varmisc= FROM_ENV=env 85ENV.varmisc+= FROM_ENV_BEFORE=env 86ENV.varmisc+= FROM_ENV_AFTER=env 87 88# Override make flags for some of the tests; default is -k. 89FLAGS.doterror= # none 90FLAGS.envfirst= -e 91FLAGS.order= -j1 92FLAGS.vardebug= -k -dv FROM_CMDLINE= 93 94# Some tests need extra post-processing. 95SED_CMDS.modmisc+= -e 's,\(substitution error:\).*,\1 (details omitted),' 96SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 97SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 98 99# Some tests need an additional round of postprocessing. 100POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 101 102# End of the configuration section. 103 104.MAIN: all 105 106UNIT_TESTS:= ${.PARSEDIR} 107.PATH: ${UNIT_TESTS} 108 109OUTFILES= ${TESTS:=.out} 110 111all: ${OUTFILES} 112 113CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp 114CLEANFILES+= obj*.[och] lib*.a # posix1.mk 115CLEANFILES+= issue* .[ab]* # suffixes.mk 116CLEANRECURSIVE+= dir dummy # posix1.mk 117 118clean: 119 rm -f ${CLEANFILES} 120.if !empty(CLEANRECURSIVE) 121 rm -rf ${CLEANRECURSIVE} 122.endif 123 124TEST_MAKE?= ${.MAKE} 125TOOL_SED?= sed 126 127# ensure consistent results from sort(1) 128LC_ALL= C 129LANG= C 130.export LANG LC_ALL 131 132# the tests are actually done with sub-makes. 133.SUFFIXES: .mk .rawout .out 134.mk.rawout: 135 @echo testing ${.IMPSRC} 136 @set -eu; \ 137 cd ${.OBJDIR}; \ 138 env ${ENV.${.TARGET:R}} ${TEST_MAKE} \ 139 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 140 > ${.TARGET}.tmp 2>&1 \ 141 && status=$$? || status=$$?; \ 142 echo $$status > ${.TARGET:R}.status 143 @mv ${.TARGET}.tmp ${.TARGET} 144 145# Post-process the test output so that the results can be compared. 146# 147# always pretend .MAKE was called 'make' 148_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 149_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 150# replace anything after 'stopped in' with unit-tests 151_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 152# strip ${.CURDIR}/ from the output 153_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 154_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 155 156.rawout.out: 157 @echo postprocess ${.TARGET} 158 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 159 < ${.IMPSRC} > ${.TARGET}.tmp1 160 @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 161 @rm ${.TARGET}.tmp1 162 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 163 @mv ${.TARGET}.tmp2 ${.TARGET} 164 165# Compare all output files 166test: ${OUTFILES} .PHONY 167 @failed= ; \ 168 for test in ${TESTS}; do \ 169 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 170 || failed="$${failed}$${failed:+ }$${test}" ; \ 171 done ; \ 172 if [ -n "$${failed}" ]; then \ 173 echo "Failed tests: $${failed}" ; false ; \ 174 else \ 175 echo "All tests passed" ; \ 176 fi 177 178accept: 179 @for test in ${TESTS}; do \ 180 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 181 || { echo "Replacing $${test}.exp" ; \ 182 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 183 done 184 185.if exists(${TEST_MAKE}) 186${TESTS:=.rawout}: ${TEST_MAKE} 187.endif 188 189.-include <bsd.obj.mk> 190