1 # $Id: Makefile.in,v 1.48 2015/12/07 04:06:29 sjg Exp $
3 # $NetBSD: Makefile,v 1.52 2015/05/05 21:51:09 sjg Exp $
5 # Unit tests for make(1)
6 # The main targets are:
8 # all: run all the tests
9 # test: run 'all', and compare to expected results
10 # accept: move generated output to expected results
13 # Each feature should get its own set of tests in its own suitably
14 # named makefile (*.mk), with its own set of expected results (*.exp),
15 # and it should be added to the TESTNAMES list.
22 UNIT_TESTS:= ${srcdir}
25 # Each test is in a sub-makefile.
26 # Keep the list sorted.
59 # these tests were broken by referting POSIX chanegs
60 STRICT_POSIX_TESTS = \
67 # Override make flags for certain tests
71 OUTFILES= ${TESTNAMES:S/$/.out/}
75 CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
76 CLEANFILES += obj*.[och] lib*.a # posix1.mk
77 CLEANFILES += issue* .[ab]* # suffixes.mk
78 CLEANRECURSIVE += dir dummy # posix1.mk
82 .if !empty(CLEANRECURSIVE)
83 rm -rf ${CLEANRECURSIVE}
92 .if defined(.PARSEDIR)
93 # ensure consistent results from sort(1)
99 # some tests need extra post-processing
100 SED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \
101 -e '/command/s,No such.*,not found,'
103 # the tests are actually done with sub-makes.
104 .SUFFIXES: .mk .rawout .out
106 @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
108 { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
109 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
110 @mv ${.TARGET}.tmp ${.TARGET}
112 # We always pretend .MAKE was called 'make'
113 # and strip ${.CURDIR}/ from the output
114 # and replace anything after 'stopped in' with unit-tests
115 # so the results can be compared.
117 @echo postprocess ${.TARGET}
118 @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
119 -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
120 -e '/stopped/s, /.*, unit-tests,' \
121 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
122 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \
123 < ${.IMPSRC} > ${.TARGET}.tmp
124 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
125 @mv ${.TARGET}.tmp ${.TARGET}
127 # Compare all output files
128 test: ${OUTFILES} .PHONY
130 for test in ${TESTNAMES}; do \
131 ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
132 || failed="$${failed}$${failed:+ }$${test}" ; \
134 if [ -n "$${failed}" ]; then \
135 echo "Failed tests: $${failed}" ; false ; \
137 echo "All tests passed" ; \
141 @for test in ${TESTNAMES}; do \
142 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
143 || { echo "Replacing $${test}.exp" ; \
144 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
147 .if exists(${TEST_MAKE})
148 ${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}