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