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