Makefile revision 1.90
1# $NetBSD: Makefile,v 1.90 2020/08/09 12:59:16 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# To do that, just run "make sync-mi" in this directory. 28# 29# A few *.mk files are helper files for other tests (such as include-sub.mk) 30# and are thus not added to TESTS. Such files must be ignored in 31# src/tests/usr.bin/make/t_make.sh. 32# 33 34# Each test is in a sub-makefile. 35# Keep the list sorted. 36TESTS+= # archive # broken on FreeBSD 37TESTS+= cmdline 38TESTS+= comment 39TESTS+= cond-late 40TESTS+= cond-short 41TESTS+= cond1 42TESTS+= cond2 43TESTS+= counter 44TESTS+= dir 45TESTS+= directives 46TESTS+= dollar 47TESTS+= doterror 48TESTS+= dotwait 49TESTS+= envfirst 50TESTS+= error 51TESTS+= # escape # broken by reverting POSIX changes 52TESTS+= export 53TESTS+= export-all 54TESTS+= export-env 55TESTS+= export-variants 56TESTS+= forloop 57TESTS+= forsubst 58TESTS+= hash 59TESTS+= impsrc 60TESTS+= include-main 61TESTS+= lint 62TESTS+= make-exported 63TESTS+= misc 64TESTS+= moderrs 65TESTS+= modmatch 66TESTS+= modmisc 67TESTS+= modorder 68TESTS+= modts 69TESTS+= modword 70TESTS+= order 71TESTS+= phony-end 72TESTS+= posix 73TESTS+= # posix1 # broken by reverting POSIX changes 74TESTS+= qequals 75TESTS+= recursive 76TESTS+= # suffixes # runs into an endless loop (try -dA) 77TESTS+= sunshcmd 78TESTS+= sysv 79TESTS+= ternary 80TESTS+= unexport 81TESTS+= unexport-env 82TESTS+= varcmd 83TESTS+= vardebug 84TESTS+= varfind 85TESTS+= varmisc 86TESTS+= varmod-edge 87TESTS+= varparse-dynamic 88TESTS+= varquote 89TESTS+= varshell 90 91# Override environment variables for some of the tests. 92ENV.counter= -i 93ENV.envfirst= FROM_ENV=value-from-env 94ENV.export= -i PATH=${PATH:Q} 95ENV.export-variants= -i PATH=${PATH:Q} 96ENV.lint= -i 97ENV.make-exported= -i PATH=${PATH:Q} 98ENV.recursive= -i 99ENV.varmisc= FROM_ENV=env 100ENV.varmisc+= FROM_ENV_BEFORE=env 101ENV.varmisc+= FROM_ENV_AFTER=env 102 103# Override make flags for some of the tests; default is -k. 104FLAGS.counter= -r -dv 105FLAGS.doterror= # none 106FLAGS.envfirst= -e 107FLAGS.export= -r 108FLAGS.lint= -dL -k 109FLAGS.order= -j1 110FLAGS.recursive= -dL -r 111FLAGS.vardebug= -k -dv FROM_CMDLINE= 112 113# Some tests need extra post-processing. 114SED_CMDS.moderrs+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 115SED_CMDS.modmisc+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),' 116SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,' 117SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,' 118SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' 119 120# Some tests need an additional round of postprocessing. 121POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 122POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' 123 124export-all.rawout: export.mk 125unexport.rawout: export.mk 126unexport-env.rawout: export.mk 127 128# End of the configuration section. 129 130.MAIN: all 131 132UNIT_TESTS:= ${.PARSEDIR} 133.PATH: ${UNIT_TESTS} 134 135OUTFILES= ${TESTS:=.out} 136 137all: ${OUTFILES} 138 139CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp 140CLEANFILES+= obj*.[och] lib*.a # posix1.mk 141CLEANFILES+= issue* .[ab]* # suffixes.mk 142CLEANRECURSIVE+= dir dummy # posix1.mk 143 144clean: 145 rm -f ${CLEANFILES} 146.if !empty(CLEANRECURSIVE) 147 rm -rf ${CLEANRECURSIVE} 148.endif 149 150TEST_MAKE?= ${.MAKE} 151TOOL_SED?= sed 152 153# ensure consistent results from sort(1) 154LC_ALL= C 155LANG= C 156.export LANG LC_ALL 157 158# the tests are actually done with sub-makes. 159.SUFFIXES: .mk .rawout .out 160.mk.rawout: 161 @echo testing ${.IMPSRC} 162 @set -eu; \ 163 cd ${.OBJDIR}; \ 164 env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \ 165 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 166 > ${.TARGET}.tmp 2>&1 \ 167 && status=$$? || status=$$?; \ 168 echo $$status > ${.TARGET:R}.status 169 @mv ${.TARGET}.tmp ${.TARGET} 170 171# Post-process the test output so that the results can be compared. 172# 173# always pretend .MAKE was called 'make' 174_SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,' 175_SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,' 176# replace anything after 'stopped in' with unit-tests 177_SED_CMDS+= -e '/stopped/s, /.*, unit-tests,' 178# strip ${.CURDIR}/ from the output 179_SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g' 180_SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g' 181 182.rawout.out: 183 @echo postprocess ${.TARGET} 184 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \ 185 < ${.IMPSRC} > ${.TARGET}.tmp1 186 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2 187 @rm ${.TARGET}.tmp1 188 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2 189 @mv ${.TARGET}.tmp2 ${.TARGET} 190 191# Compare all output files 192test: ${OUTFILES} .PHONY 193 @failed= ; \ 194 for test in ${TESTS}; do \ 195 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 196 || failed="$${failed}$${failed:+ }$${test}" ; \ 197 done ; \ 198 if [ -n "$${failed}" ]; then \ 199 echo "Failed tests: $${failed}" ; false ; \ 200 else \ 201 echo "All tests passed" ; \ 202 fi 203 204accept: 205 @for test in ${TESTS}; do \ 206 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 207 || { echo "Replacing $${test}.exp" ; \ 208 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 209 done 210 211SYNC_MI_AWK= \ 212 BEGIN { \ 213 testsdir = "usr.bin/make/unit-tests"; \ 214 linestart = "./usr/tests/" testsdir; \ 215 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \ 216 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \ 217 } \ 218 function startswith(s, prefix) { \ 219 return substr(s, 1, length(prefix)) == prefix; \ 220 } \ 221 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \ 222 { print $$0 } \ 223 $$1 == linestart "/Makefile" { system(cmd) } 224 225sync-mi: 226 @set -eu; \ 227 cd "${MAKEFILE:tA:H}/../../.."; \ 228 mi="distrib/sets/lists/tests/mi"; \ 229 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \ 230 mv -f "$$mi.$@" "$$mi"; \ 231 cvs diff "$$mi" || true 232 233.if exists(${TEST_MAKE}) 234${TESTS:=.rawout}: ${TEST_MAKE} 235.endif 236 237.-include <bsd.obj.mk> 238