Makefile revision 1.22 1 # $NetBSD: Makefile,v 1.22 2008/03/31 00:12:21 sjg Exp $
2 #
3 # Unit tests for make(1)
4 # The main targets are:
5 #
6 # all: run all the tests
7 # test: run 'all', capture output 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 which should be added to SUBFILES to hook it in.
13 #
14
15 .MAIN: all
16
17 UNIT_TESTS:= ${.PARSEDIR}
18
19 # Simple sub-makefiles - we run them as a black box
20 # keep the list sorted.
21 SUBFILES= \
22 comment \
23 cond1 \
24 export \
25 export-all \
26 dotwait \
27 moderrs \
28 modmatch \
29 modmisc \
30 modorder \
31 modts \
32 modword \
33 posix \
34 qequals \
35 ternary \
36 varcmd
37
38 all: ${SUBFILES}
39
40 # the tests are actually done with sub-makes.
41 .PHONY: ${SUBFILES}
42 .PRECIOUS: ${SUBFILES}
43 ${SUBFILES}:
44 -@${.MAKE} -k -f ${UNIT_TESTS}/$@
45
46 clean:
47 rm -f *.out *.fail *.core
48
49 .include <bsd.obj.mk>
50
51 TEST_MAKE?= ${.MAKE}
52
53 # The driver.
54 # We always pretend .MAKE was called 'make'
55 # and strip ${.CURDIR}/ from the output
56 # and replace anything after 'stopped in' with unit-tests
57 # so the results can be compared.
58 test:
59 @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
60 @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
61 sed -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \
62 -e '/stopped/s, /.*, unit-tests,' \
63 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
64 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
65 tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
66 diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
67
68 accept:
69 mv test.out ${.CURDIR}/test.exp
70
71