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