Makefile revision 1.47 1 # $NetBSD: Makefile,v 1.47 2014/08/24 11:52:45 apb 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
18 UNIT_TESTS:= ${.PARSEDIR}
19 .PATH: ${UNIT_TESTS}
20
21 # Each test is in a sub-makefile.
22 # Keep the list sorted.
23 TESTNAMES= \
24 comment \
25 cond1 \
26 error \
27 escape \
28 export \
29 export-all \
30 export-env \
31 doterror \
32 dotwait \
33 forloop \
34 forsubst \
35 hash \
36 impsrc \
37 misc \
38 moderrs \
39 modmatch \
40 modmisc \
41 modorder \
42 modts \
43 modword \
44 order \
45 phony-end \
46 posix \
47 posix1 \
48 qequals \
49 suffixes \
50 sunshcmd \
51 sysv \
52 ternary \
53 unexport \
54 unexport-env \
55 varcmd \
56 varmisc \
57 varshell
58
59 # Override make flags for certain tests
60 flags.doterror=
61 flags.order=-j1
62
63 OUTFILES= ${TESTNAMES:S/$/.out/}
64
65 all: ${OUTFILES}
66
67 clean:
68 rm -f *.rawout *.out *.status *.tmp *.core *.tmp
69
70 TEST_MAKE?= ${.MAKE}
71 TOOL_SED?= sed
72
73 # ensure consistent results from sort(1)
74 LC_ALL= C
75 LANG= C
76 .export LANG LC_ALL
77
78 # the tests are actually done with sub-makes.
79 .SUFFIXES: .mk .rawout .out
80 .mk.rawout:
81 @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
82 -@cd ${.OBJDIR} && \
83 { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
84 2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
85 @mv ${.TARGET}.tmp ${.TARGET}
86
87 # We always pretend .MAKE was called 'make'
88 # and strip ${.CURDIR}/ from the output
89 # and replace anything after 'stopped in' with unit-tests
90 # so the results can be compared.
91 .rawout.out:
92 @echo postprocess ${.TARGET}
93 @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
94 -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
95 -e '/stopped/s, /.*, unit-tests,' \
96 -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
97 -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' \
98 < ${.IMPSRC} > ${.TARGET}.tmp
99 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
100 @mv ${.TARGET}.tmp ${.TARGET}
101
102 # Compare all output files
103 test: ${OUTFILES} .PHONY
104 @failed= ; \
105 for test in ${TESTNAMES}; do \
106 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
107 || failed="$${failed}$${failed:+ }$${test}" ; \
108 done ; \
109 if [ -n "$${failed}" ]; then \
110 echo "Failed tests: $${failed}" ; false ; \
111 else \
112 echo "All tests passed" ; \
113 fi
114
115 accept:
116 @for test in ${TESTNAMES}; do \
117 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
118 || { echo "Replacing $${test}.exp" ; \
119 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
120 done
121
122 .-include <bsd.obj.mk>
123