Makefile revision 1.89 1 # $NetBSD: Makefile,v 1.89 2020/08/07 19:24:27 rillig Exp $
2 #
3 # Unit tests for make(1)
4 #
5 # The main targets are:
6 #
7 # all:
8 # run all the tests
9 # test:
10 # run 'all', and compare to expected results
11 # accept:
12 # move generated output to expected results
13 #
14 # Settable variables
15 #
16 # TEST_MAKE
17 # The make program to be tested.
18 #
19 #
20 # Adding a test case
21 #
22 # Each feature should get its own set of tests in its own suitably
23 # named makefile (*.mk), with its own set of expected results (*.exp),
24 # and it should be added to the TESTS list.
25 #
26 # Any added files must also be added to src/distrib/sets/lists/tests/mi.
27 # To do that, just run "make sync-mi" in this directory.
28 #
29 # A few *.mk files are helper files for other tests (such as include-sub.mk)
30 # and are thus not added to TESTS. Such files must be ignored in
31 # src/tests/usr.bin/make/t_make.sh.
32 #
33
34 # Each test is in a sub-makefile.
35 # Keep the list sorted.
36 TESTS+= # archive # broken on FreeBSD
37 TESTS+= cmdline
38 TESTS+= comment
39 TESTS+= cond-late
40 TESTS+= cond-short
41 TESTS+= cond1
42 TESTS+= cond2
43 TESTS+= counter
44 TESTS+= dir
45 TESTS+= directives
46 TESTS+= dollar
47 TESTS+= doterror
48 TESTS+= dotwait
49 TESTS+= envfirst
50 TESTS+= error
51 TESTS+= # escape # broken by reverting POSIX changes
52 TESTS+= export
53 TESTS+= export-all
54 TESTS+= export-env
55 TESTS+= export-variants
56 TESTS+= forloop
57 TESTS+= forsubst
58 TESTS+= hash
59 TESTS+= impsrc
60 TESTS+= include-main
61 TESTS+= lint
62 TESTS+= misc
63 TESTS+= moderrs
64 TESTS+= modmatch
65 TESTS+= modmisc
66 TESTS+= modorder
67 TESTS+= modts
68 TESTS+= modword
69 TESTS+= order
70 TESTS+= phony-end
71 TESTS+= posix
72 TESTS+= # posix1 # broken by reverting POSIX changes
73 TESTS+= qequals
74 TESTS+= recursive
75 TESTS+= # suffixes # runs into an endless loop (try -dA)
76 TESTS+= sunshcmd
77 TESTS+= sysv
78 TESTS+= ternary
79 TESTS+= unexport
80 TESTS+= unexport-env
81 TESTS+= varcmd
82 TESTS+= vardebug
83 TESTS+= varfind
84 TESTS+= varmisc
85 TESTS+= varmod-edge
86 TESTS+= varparse-dynamic
87 TESTS+= varquote
88 TESTS+= varshell
89
90 # Override environment variables for some of the tests.
91 ENV.counter= -i
92 ENV.envfirst= FROM_ENV=value-from-env
93 ENV.export= -i PATH=${PATH:Q}
94 ENV.export-variants= -i PATH=${PATH:Q}
95 ENV.lint= -i
96 ENV.recursive= -i
97 ENV.varmisc= FROM_ENV=env
98 ENV.varmisc+= FROM_ENV_BEFORE=env
99 ENV.varmisc+= FROM_ENV_AFTER=env
100
101 # Override make flags for some of the tests; default is -k.
102 FLAGS.counter= -r -dv
103 FLAGS.doterror= # none
104 FLAGS.envfirst= -e
105 FLAGS.export= -r
106 FLAGS.lint= -dL -k
107 FLAGS.order= -j1
108 FLAGS.recursive= -dL -r
109 FLAGS.vardebug= -k -dv FROM_CMDLINE=
110
111 # Some tests need extra post-processing.
112 SED_CMDS.moderrs+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
113 SED_CMDS.modmisc+= -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
114 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
115 SED_CMDS.varshell+= -e 's,^[a-z]*sh: ,,'
116 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
117
118 # Some tests need an additional round of postprocessing.
119 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
120 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
121
122 export-all.rawout: export.mk
123 unexport.rawout: export.mk
124 unexport-env.rawout: export.mk
125
126 # End of the configuration section.
127
128 .MAIN: all
129
130 UNIT_TESTS:= ${.PARSEDIR}
131 .PATH: ${UNIT_TESTS}
132
133 OUTFILES= ${TESTS:=.out}
134
135 all: ${OUTFILES}
136
137 CLEANFILES+= *.rawout *.out *.status *.tmp *.core *.tmp
138 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
139 CLEANFILES+= issue* .[ab]* # suffixes.mk
140 CLEANRECURSIVE+= dir dummy # posix1.mk
141
142 clean:
143 rm -f ${CLEANFILES}
144 .if !empty(CLEANRECURSIVE)
145 rm -rf ${CLEANRECURSIVE}
146 .endif
147
148 TEST_MAKE?= ${.MAKE}
149 TOOL_SED?= sed
150
151 # ensure consistent results from sort(1)
152 LC_ALL= C
153 LANG= C
154 .export LANG LC_ALL
155
156 # the tests are actually done with sub-makes.
157 .SUFFIXES: .mk .rawout .out
158 .mk.rawout:
159 @echo testing ${.IMPSRC}
160 @set -eu; \
161 cd ${.OBJDIR}; \
162 env ${ENV.${.TARGET:R}} ${TEST_MAKE} -C ${.CURDIR} \
163 ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
164 > ${.TARGET}.tmp 2>&1 \
165 && status=$$? || status=$$?; \
166 echo $$status > ${.TARGET:R}.status
167 @mv ${.TARGET}.tmp ${.TARGET}
168
169 # Post-process the test output so that the results can be compared.
170 #
171 # always pretend .MAKE was called 'make'
172 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
173 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
174 # replace anything after 'stopped in' with unit-tests
175 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
176 # strip ${.CURDIR}/ from the output
177 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
178 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
179
180 .rawout.out:
181 @echo postprocess ${.TARGET}
182 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
183 < ${.IMPSRC} > ${.TARGET}.tmp1
184 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
185 @rm ${.TARGET}.tmp1
186 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
187 @mv ${.TARGET}.tmp2 ${.TARGET}
188
189 # Compare all output files
190 test: ${OUTFILES} .PHONY
191 @failed= ; \
192 for test in ${TESTS}; do \
193 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
194 || failed="$${failed}$${failed:+ }$${test}" ; \
195 done ; \
196 if [ -n "$${failed}" ]; then \
197 echo "Failed tests: $${failed}" ; false ; \
198 else \
199 echo "All tests passed" ; \
200 fi
201
202 accept:
203 @for test in ${TESTS}; do \
204 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
205 || { echo "Replacing $${test}.exp" ; \
206 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
207 done
208
209 SYNC_MI_AWK= \
210 BEGIN { \
211 testsdir = "usr.bin/make/unit-tests"; \
212 linestart = "./usr/tests/" testsdir; \
213 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
214 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
215 } \
216 function startswith(s, prefix) { \
217 return substr(s, 1, length(prefix)) == prefix; \
218 } \
219 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
220 { print $$0 } \
221 $$1 == linestart "/Makefile" { system(cmd) }
222
223 sync-mi:
224 @set -eu; \
225 cd "${MAKEFILE:tA:H}/../../.."; \
226 mi="distrib/sets/lists/tests/mi"; \
227 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
228 mv -f "$$mi.$@" "$$mi"; \
229 cvs diff "$$mi" || true
230
231 .if exists(${TEST_MAKE})
232 ${TESTS:=.rawout}: ${TEST_MAKE}
233 .endif
234
235 .-include <bsd.obj.mk>
236