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