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