Debian Codegraph @

unit-tests/Makefile

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