]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/Makefile
Update to bmake-20200704
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / Makefile
1 # $Id: Makefile,v 1.58 2020/07/04 22:33:00 sjg Exp $
2 #
3 # $NetBSD: Makefile,v 1.59 2020/06/28 09:42:40 rillig Exp $
4 #
5 # Unit tests for make(1)
6 # The main targets are:
7
8 # all:  run all the tests
9 # test: run 'all', and compare to expected results
10 # accept: move generated output to expected results
11 #
12 # Adding a test case.  
13 # Each feature should get its own set of tests in its own suitably
14 # named makefile (*.mk), with its own set of expected results (*.exp),
15 # and it should be added to the TESTNAMES list.
16
17
18 .MAIN: all
19
20 .-include "Makefile.config"
21
22 UNIT_TESTS:= ${.PARSEDIR}
23 .PATH: ${UNIT_TESTS}
24
25 # Each test is in a sub-makefile.
26 # Keep the list sorted.
27 TESTNAMES= \
28         comment \
29         cond-late \
30         cond-short \
31         cond1 \
32         cond2 \
33         dollar \
34         doterror \
35         dotwait \
36         error \
37         export \
38         export-all \
39         export-env \
40         forloop \
41         forsubst \
42         hash \
43         include-main \
44         misc \
45         moderrs \
46         modmatch \
47         modmisc \
48         modorder \
49         modts \
50         modword \
51         order \
52         posix \
53         qequals \
54         sunshcmd \
55         sysv \
56         ternary \
57         unexport \
58         unexport-env \
59         varcmd \
60         varmisc \
61         varmod-edge \
62         varquote \
63         varshell
64
65 # these tests were broken by referting POSIX chanegs
66 STRICT_POSIX_TESTS = \
67         escape \
68         impsrc \
69         phony-end \
70         posix1 \
71         suffixes
72
73 # Override make flags for certain tests
74 flags.doterror=
75 flags.order=-j1
76
77 OUTFILES= ${TESTNAMES:S/$/.out/}
78
79 all: ${OUTFILES}
80
81 CLEANFILES += *.rawout *.out *.status *.tmp *.core *.tmp
82 CLEANFILES += obj*.[och] lib*.a         # posix1.mk
83 CLEANFILES += issue* .[ab]*             # suffixes.mk
84 CLEANRECURSIVE += dir dummy             # posix1.mk
85
86 clean:
87         rm -f ${CLEANFILES}
88 .if !empty(CLEANRECURSIVE)
89         rm -rf ${CLEANRECURSIVE}
90 .endif
91
92 TEST_MAKE?= ${.MAKE}
93 TOOL_SED?= sed
94 TOOL_TR?= tr
95 TOOL_DIFF?= diff
96
97 .if defined(.PARSEDIR)
98 # ensure consistent results from sort(1)
99 LC_ALL= C
100 LANG= C
101 .export LANG LC_ALL
102 .endif
103
104 # some tests need extra post-processing
105 SED_CMDS.varshell = -e 's,^[a-z]*sh: ,,' \
106         -e '/command/s,No such.*,not found,'
107
108 # the detailed error message can vary across systems
109 SED_CMDS.modmisc = -e 's,\(substitution error:\).*,\1 details omitted,'
110
111 # the tests are actually done with sub-makes.
112 .SUFFIXES: .mk .rawout .out
113 .mk.rawout:
114         @echo ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC}
115         -@cd ${.OBJDIR} && \
116         { ${TEST_MAKE} ${flags.${.TARGET:R}:U-k} -f ${.IMPSRC} \
117           2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
118         @mv ${.TARGET}.tmp ${.TARGET}
119
120 # We always pretend .MAKE was called 'make' 
121 # and strip ${.CURDIR}/ from the output
122 # and replace anything after 'stopped in' with unit-tests
123 # so the results can be compared.
124 .rawout.out:
125         @echo postprocess ${.TARGET}
126         @${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}[][0-9]*:,make:,' \
127           -e 's,${TEST_MAKE:C/\./\\\./g},make,' \
128           -e '/stopped/s, /.*, unit-tests,' \
129           -e 's,${.CURDIR:C/\./\\\./g}/,,g' \
130           -e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' ${SED_CMDS.${.TARGET:T:R}} \
131           < ${.IMPSRC} > ${.TARGET}.tmp
132         @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
133         @mv ${.TARGET}.tmp ${.TARGET}
134
135 # Compare all output files
136 test:   ${OUTFILES} .PHONY
137         @failed= ; \
138         for test in ${TESTNAMES}; do \
139           ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
140           || failed="$${failed}$${failed:+ }$${test}" ; \
141         done ; \
142         if [ -n "$${failed}" ]; then \
143           echo "Failed tests: $${failed}" ; false ; \
144         else \
145           echo "All tests passed" ; \
146         fi
147
148 accept:
149         @for test in ${TESTNAMES}; do \
150           cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
151           || { echo "Replacing $${test}.exp" ; \
152                cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
153         done
154
155 .if exists(${TEST_MAKE})
156 ${TESTNAMES:S/$/.rawout/}: ${TEST_MAKE}
157 .endif
158
159 .-include <obj.mk>