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