Makefile revision 1.29 1 # $NetBSD: Makefile,v 1.29 2010/12/10 00:36:33 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 error \
25 export \
26 export-all \
27 doterror \
28 dotwait \
29 forsubst \
30 moderrs \
31 modmatch \
32 modmisc \
33 modorder \
34 modts \
35 modword \
36 posix \
37 qequals \
38 ternary \
39 unexport \
40 unexport-env \
41 varcmd
42
43 all: ${SUBFILES}
44
45 flags.doterror=
46
47 # the tests are actually done with sub-makes.
48 .PHONY: ${SUBFILES}
49 .PRECIOUS: ${SUBFILES}
50 ${SUBFILES}:
51 -@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
52
53 clean:
54 rm -f *.out *.fail *.core
55
56 .-include <bsd.obj.mk>
57
58 TEST_MAKE?= ${.MAKE}
59 TOOL_SED?= sed
60
61 # ensure consistent results from sort(1)
62 LC_ALL = C
63 LANG= C
64 .export LANG LC_ALL
65
66 # The driver.
67 # We always pretend .MAKE was called 'make'
68 # and strip ${.CURDIR}/ from the output
69 # and replace anything after 'stopped in' with unit-tests
70 # so the results can be compared.
71 test:
72 @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1"
73 @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \
74 ${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \
75 -e '/stopped/s, /.*, unit-tests,' \
76 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
77 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
78 tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
79 diff -u ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
80
81 accept:
82 mv test.out ${.CURDIR}/test.exp
83
84