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