Makefile revision 1.55
1# $NetBSD: Makefile,v 1.55 2020/04/29 23:15:21 rillig Exp $ 2# 3# Unit tests for make(1) 4# The main targets are: 5# 6# all: run all the tests 7# test: run 'all', and compare to expected results 8# accept: move generated output to expected results 9# 10# Adding a test case. 11# Each feature should get its own set of tests in its own suitably 12# named makefile (*.mk), with its own set of expected results (*.exp), 13# and it should be added to the TESTNAMES list. 14# 15 16.MAIN: all 17 18UNIT_TESTS:= ${.PARSEDIR} 19.PATH: ${UNIT_TESTS} 20 21# Each test is in a sub-makefile. 22# Keep the list sorted. 23TESTNAMES= \ 24 comment \ 25 cond-late \ 26 cond1 \ 27 cond2 \ 28 error \ 29 export \ 30 export-all \ 31 export-env \ 32 doterror \ 33 dotwait \ 34 forloop \ 35 forsubst \ 36 hash \ 37 misc \ 38 moderrs \ 39 modmatch \ 40 modmisc \ 41 modorder \ 42 modts \ 43 modword \ 44 order \ 45 posix \ 46 qequals \ 47 sunshcmd \ 48 sysv \ 49 ternary \ 50 unexport \ 51 unexport-env \ 52 varcmd \ 53 varmisc \ 54 varmod-edge \ 55 varquote \ 56 varshell 57 58# these tests were broken by referting POSIX chanegs 59STRICT_POSIX_TESTS = \ 60 escape \ 61 impsrc \ 62 phony-end \ 63 posix1 \ 64 suffixes 65 66# Override make flags for certain tests 67flags.doterror= 68flags.order=-j1 69 70OUTFILES= ${TESTNAMES:S/$/.out/} 71 72all: ${OUTFILES} 73 74CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp 75CLEANFILES += obj*.[och] lib*.a # posix1.mk 76CLEANFILES += issue* .[ab]* # suffixes.mk 77CLEANRECURSIVE += dir dummy # posix1.mk 78 79clean: 80 rm -f ${CLEANFILES} 81.if !empty(CLEANRECURSIVE) 82 rm -rf ${CLEANRECURSIVE} 83.endif 84 85TEST_MAKE?= ${.MAKE} 86TOOL_SED?= sed 87 88# ensure consistent results from sort(1) 89LC_ALL= C 90LANG= C 91.export LANG LC_ALL 92 93# the tests are actually done with sub-makes. 94.SUFFIXES: .mk .rawout .out 95.mk.rawout: 96 @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} 97 -@cd ${.OBJDIR} && \ 98 { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \ 99 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp 100 @mv ${.TARGET}.tmp ${.TARGET} 101 102# We always pretend .MAKE was called 'make' 103# and strip ${.CURDIR}/ from the output 104# and replace anything after 'stopped in' with unit-tests 105# so the results can be compared. 106.rawout.out: 107 @echo postprocess ${.TARGET} 108 @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \ 109 -e 's,${TEST_MAKE:C/\./\\\./g},make,' \ 110 -e '/stopped/s, /.*, unit-tests,' \ 111 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ 112 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \ 113 < ${.IMPSRC} > ${.TARGET}.tmp 114 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp 115 @mv ${.TARGET}.tmp ${.TARGET} 116 117# Compare all output files 118test: ${OUTFILES} .PHONY 119 @failed= ; \ 120 for test in ${TESTNAMES}; do \ 121 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \ 122 || failed="$${failed}$${failed:+ }$${test}" ; \ 123 done ; \ 124 if [ -n "$${failed}" ]; then \ 125 echo "Failed tests: $${failed}" ; false ; \ 126 else \ 127 echo "All tests passed" ; \ 128 fi 129 130accept: 131 @for test in ${TESTNAMES}; do \ 132 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \ 133 || { echo "Replacing $${test}.exp" ; \ 134 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \ 135 done 136 137.if exists(${TEST_MAKE}) 138${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE} 139.endif 140 141.-include <bsd.obj.mk> 142