Makefile revision 1.118 1 # $NetBSD: Makefile,v 1.118 2020/08/23 14:28:04 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 # Any test that is commented out must be ignored in
37 # src/tests/usr.bin/make/t_make.sh as well.
38 TESTS+= # archive # broken on FreeBSD, enabled in t_make.sh
39 TESTS+= cmdline
40 TESTS+= comment
41 TESTS+= cond-cmp-numeric
42 TESTS+= cond-cmp-numeric-eq
43 TESTS+= cond-cmp-numeric-ge
44 TESTS+= cond-cmp-numeric-gt
45 TESTS+= cond-cmp-numeric-le
46 TESTS+= cond-cmp-numeric-lt
47 TESTS+= cond-cmp-numeric-ne
48 TESTS+= cond-cmp-string
49 TESTS+= cond-func
50 TESTS+= cond-func-commands
51 TESTS+= cond-func-defined
52 TESTS+= cond-func-empty
53 TESTS+= cond-func-exists
54 TESTS+= cond-func-make
55 TESTS+= cond-func-target
56 TESTS+= cond-late
57 TESTS+= cond-op
58 TESTS+= cond-op-and
59 TESTS+= cond-op-not
60 TESTS+= cond-op-or
61 TESTS+= cond-op-parentheses
62 TESTS+= cond-short
63 TESTS+= cond-token-number
64 TESTS+= cond-token-plain
65 TESTS+= cond-token-string
66 TESTS+= cond-token-var
67 TESTS+= cond1
68 TESTS+= cond2
69 TESTS+= counter
70 TESTS+= dep
71 TESTS+= dep-colon
72 TESTS+= dep-double-colon
73 TESTS+= dep-exclam
74 TESTS+= dep-none
75 TESTS+= dep-var
76 TESTS+= dep-wildcards
77 TESTS+= depsrc
78 TESTS+= depsrc-exec
79 TESTS+= depsrc-ignore
80 TESTS+= depsrc-made
81 TESTS+= depsrc-make
82 TESTS+= depsrc-meta
83 TESTS+= depsrc-nometa
84 TESTS+= depsrc-nometa_cmp
85 TESTS+= depsrc-nopath
86 TESTS+= depsrc-notmain
87 TESTS+= depsrc-optional
88 TESTS+= depsrc-phony
89 TESTS+= depsrc-precious
90 TESTS+= depsrc-recursive
91 TESTS+= depsrc-silent
92 TESTS+= depsrc-use
93 TESTS+= depsrc-usebefore
94 TESTS+= depsrc-usebefore-double-colon
95 TESTS+= depsrc-wait
96 TESTS+= deptgt
97 TESTS+= deptgt-begin
98 TESTS+= deptgt-default
99 TESTS+= deptgt-delete_on_error
100 TESTS+= deptgt-end
101 TESTS+= deptgt-error
102 TESTS+= deptgt-ignore
103 TESTS+= deptgt-interrupt
104 TESTS+= deptgt-main
105 TESTS+= deptgt-makeflags
106 TESTS+= deptgt-no_parallel
107 TESTS+= deptgt-nopath
108 TESTS+= deptgt-notparallel
109 TESTS+= deptgt-objdir
110 TESTS+= deptgt-order
111 TESTS+= deptgt-path
112 TESTS+= deptgt-path-suffix
113 TESTS+= deptgt-phony
114 TESTS+= deptgt-precious
115 TESTS+= deptgt-shell
116 TESTS+= deptgt-silent
117 TESTS+= deptgt-stale
118 TESTS+= deptgt-suffixes
119 TESTS+= dir
120 TESTS+= dir-expand-path
121 TESTS+= directive
122 TESTS+= directive-elif
123 TESTS+= directive-elifdef
124 TESTS+= directive-elifmake
125 TESTS+= directive-elifndef
126 TESTS+= directive-elifnmake
127 TESTS+= directive-else
128 TESTS+= directive-endif
129 TESTS+= directive-error
130 TESTS+= directive-export
131 TESTS+= directive-export-env
132 TESTS+= directive-export-literal
133 TESTS+= directive-if
134 TESTS+= directive-ifdef
135 TESTS+= directive-ifmake
136 TESTS+= directive-ifndef
137 TESTS+= directive-ifnmake
138 TESTS+= directive-info
139 TESTS+= directive-undef
140 TESTS+= directive-unexport
141 TESTS+= directive-unexport-env
142 TESTS+= directive-warning
143 TESTS+= directives
144 TESTS+= dollar
145 TESTS+= doterror
146 TESTS+= dotwait
147 TESTS+= envfirst
148 TESTS+= error
149 TESTS+= # escape # broken by reverting POSIX changes
150 TESTS+= export
151 TESTS+= export-all
152 TESTS+= export-env
153 TESTS+= export-variants
154 TESTS+= forloop
155 TESTS+= forsubst
156 TESTS+= hash
157 TESTS+= impsrc
158 TESTS+= include-main
159 TESTS+= lint
160 TESTS+= make-exported
161 TESTS+= misc
162 TESTS+= moderrs
163 TESTS+= modmatch
164 TESTS+= modmisc
165 TESTS+= modts
166 TESTS+= modword
167 TESTS+= opt
168 TESTS+= opt-backwards
169 TESTS+= opt-chdir
170 TESTS+= opt-debug
171 TESTS+= opt-define
172 TESTS+= opt-env
173 TESTS+= opt-file
174 TESTS+= opt-ignore
175 TESTS+= opt-include-dir
176 TESTS+= opt-jobs
177 TESTS+= opt-jobs-internal
178 TESTS+= opt-keep-going
179 TESTS+= opt-m-include-dir
180 TESTS+= opt-no-action
181 TESTS+= opt-no-action-at-all
182 TESTS+= opt-query
183 TESTS+= opt-raw
184 TESTS+= opt-silent
185 TESTS+= opt-touch
186 TESTS+= opt-tracefile
187 TESTS+= opt-var-expanded
188 TESTS+= opt-var-literal
189 TESTS+= opt-warnings-as-errors
190 TESTS+= opt-where-am-i
191 TESTS+= opt-x-reduce-exported
192 TESTS+= order
193 TESTS+= phony-end
194 TESTS+= posix
195 TESTS+= # posix1 # broken by reverting POSIX changes
196 TESTS+= qequals
197 TESTS+= recursive
198 TESTS+= sh
199 TESTS+= sh-dots
200 TESTS+= sh-jobs
201 TESTS+= sh-jobs-error
202 TESTS+= sh-leading-at
203 TESTS+= sh-leading-hyphen
204 TESTS+= sh-leading-plus
205 TESTS+= sh-meta-chars
206 TESTS+= sh-multi-line
207 TESTS+= sh-single-line
208 TESTS+= # suffixes # runs into an endless loop (try -dA)
209 TESTS+= sunshcmd
210 TESTS+= sysv
211 TESTS+= ternary
212 TESTS+= unexport
213 TESTS+= unexport-env
214 TESTS+= use-inference
215 TESTS+= var-class
216 TESTS+= var-class-cmdline
217 TESTS+= var-class-env
218 TESTS+= var-class-global
219 TESTS+= var-class-local
220 TESTS+= var-class-local-legacy
221 TESTS+= var-op
222 TESTS+= var-op-append
223 TESTS+= var-op-assign
224 TESTS+= var-op-default
225 TESTS+= var-op-expand
226 TESTS+= var-op-shell
227 TESTS+= varcmd
228 TESTS+= vardebug
229 TESTS+= varfind
230 TESTS+= varmisc
231 TESTS+= varmod
232 TESTS+= varmod-assign
233 TESTS+= varmod-defined
234 TESTS+= varmod-edge
235 TESTS+= varmod-exclam-shell
236 TESTS+= varmod-extension
237 TESTS+= varmod-gmtime
238 TESTS+= varmod-hash
239 TESTS+= varmod-head
240 TESTS+= varmod-ifelse
241 TESTS+= varmod-l-name-to-value
242 TESTS+= varmod-localtime
243 TESTS+= varmod-loop
244 TESTS+= varmod-match
245 TESTS+= varmod-match-escape
246 TESTS+= varmod-no-match
247 TESTS+= varmod-order
248 TESTS+= varmod-order-reverse
249 TESTS+= varmod-order-shuffle
250 TESTS+= varmod-path
251 TESTS+= varmod-quote
252 TESTS+= varmod-quote-dollar
253 TESTS+= varmod-range
254 TESTS+= varmod-remember
255 TESTS+= varmod-root
256 TESTS+= varmod-select-words
257 TESTS+= varmod-shell
258 TESTS+= varmod-subst
259 TESTS+= varmod-subst-regex
260 TESTS+= varmod-sysv
261 TESTS+= varmod-tail
262 TESTS+= varmod-to-abs
263 TESTS+= varmod-to-lower
264 TESTS+= varmod-to-many-words
265 TESTS+= varmod-to-one-word
266 TESTS+= varmod-to-separator
267 TESTS+= varmod-to-upper
268 TESTS+= varmod-undefined
269 TESTS+= varmod-unique
270 TESTS+= varname
271 TESTS+= varname-dollar
272 TESTS+= varname-dot-alltargets
273 TESTS+= varname-dot-curdir
274 TESTS+= varname-dot-includedfromdir
275 TESTS+= varname-dot-includedfromfile
276 TESTS+= varname-dot-make-dependfile
277 TESTS+= varname-dot-make-expand_variables
278 TESTS+= varname-dot-make-exported
279 TESTS+= varname-dot-make-jobs
280 TESTS+= varname-dot-make-jobs-prefix
281 TESTS+= varname-dot-make-level
282 TESTS+= varname-dot-make-makefile_preference
283 TESTS+= varname-dot-make-makefiles
284 TESTS+= varname-dot-make-meta-bailiwick
285 TESTS+= varname-dot-make-meta-created
286 TESTS+= varname-dot-make-meta-files
287 TESTS+= varname-dot-make-meta-ignore_filter
288 TESTS+= varname-dot-make-meta-ignore_paths
289 TESTS+= varname-dot-make-meta-ignore_patterns
290 TESTS+= varname-dot-make-meta-prefix
291 TESTS+= varname-dot-make-mode
292 TESTS+= varname-dot-make-path_filemon
293 TESTS+= varname-dot-make-pid
294 TESTS+= varname-dot-make-ppid
295 TESTS+= varname-dot-make-save_dollars
296 TESTS+= varname-dot-makeoverrides
297 TESTS+= varname-dot-newline
298 TESTS+= varname-dot-objdir
299 TESTS+= varname-dot-parsedir
300 TESTS+= varname-dot-parsefile
301 TESTS+= varname-dot-path
302 TESTS+= varname-dot-shell
303 TESTS+= varname-dot-targets
304 TESTS+= varname-empty
305 TESTS+= varname-make
306 TESTS+= varname-make_print_var_on_error
307 TESTS+= varname-makeflags
308 TESTS+= varname-pwd
309 TESTS+= varname-vpath
310 TESTS+= varparse-dynamic
311 TESTS+= varquote
312 TESTS+= varshell
313
314 # Additional environment variables for some of the tests.
315 # The base environment is -i PATH="$PATH".
316 ENV.envfirst= FROM_ENV=value-from-env
317 ENV.varmisc= FROM_ENV=env
318 ENV.varmisc+= FROM_ENV_BEFORE=env
319 ENV.varmisc+= FROM_ENV_AFTER=env
320
321 # Override make flags for some of the tests; default is -k.
322 FLAGS.archive= -dA
323 FLAGS.counter= -dv
324 FLAGS.doterror= # none
325 FLAGS.envfirst= -e
326 FLAGS.export= # none
327 FLAGS.lint= -dL -k
328 FLAGS.opt-ignore= -i
329 FLAGS.opt-keep-going= -k
330 FLAGS.opt-no-action= -n
331 FLAGS.opt-query= -q
332 FLAGS.opt-var-expanded= -v VAR -v VALUE
333 FLAGS.opt-var-literal= -V VAR -V VALUE
334 FLAGS.opt-warnings-as-errors= -W
335 FLAGS.order= -j1
336 FLAGS.recursive= -dL
337 FLAGS.vardebug= -k -dv FROM_CMDLINE=
338 FLAGS.varmod-match-escape= -dv
339 FLAGS.varname-dot-shell= -dpv
340 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
341
342 # Some tests need extra post-processing.
343 SED_CMDS.sh-dots+= -e 's,^${.SHELL}: ,,' -e '/not found/s,command ,,'
344 SED_CMDS.varmod-subst-regex+= \
345 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
346 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
347 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
348 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
349 SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),'
350 SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",'
351 SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],'
352
353 # Some tests need an additional round of postprocessing.
354 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
355 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
356 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
357 POSTPROC.varname-dot-shell= \
358 awk '/\.SHELL/ || /^ParseReadLine/'
359 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
360
361 # Some tests reuse other tests, which makes them unnecessarily fragile.
362 export-all.rawout: export.mk
363 unexport.rawout: export.mk
364 unexport-env.rawout: export.mk
365
366 # End of the configuration section.
367
368 .MAIN: all
369
370 UNIT_TESTS:= ${.PARSEDIR}
371 .PATH: ${UNIT_TESTS}
372
373 OUTFILES= ${TESTS:=.out}
374
375 all: ${OUTFILES}
376
377 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
378 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
379 CLEANFILES+= issue* .[ab]* # suffixes.mk
380 CLEANDIRS= dir dummy # posix1.mk
381
382 clean:
383 rm -f ${CLEANFILES}
384 rm -rf ${CLEANDIRS}
385
386 TEST_MAKE?= ${.MAKE}
387 TOOL_SED?= sed
388
389 # ensure consistent results from sort(1)
390 LC_ALL= C
391 LANG= C
392 .export LANG LC_ALL
393
394 # the tests are actually done with sub-makes.
395 .SUFFIXES: .mk .rawout .out
396 .mk.rawout:
397 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
398 @set -eu; \
399 cd ${.OBJDIR}; \
400 env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \
401 ${TEST_MAKE} \
402 -r -C ${.CURDIR} -f ${.IMPSRC} \
403 ${FLAGS.${.TARGET:R}:U-k} \
404 > ${.TARGET}.tmp 2>&1 \
405 && status=$$? || status=$$?; \
406 echo $$status > ${.TARGET:R}.status
407 @mv ${.TARGET}.tmp ${.TARGET}
408
409 # Post-process the test output so that the results can be compared.
410 #
411 # always pretend .MAKE was called 'make'
412 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
413 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
414 # replace anything after 'stopped in' with unit-tests
415 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
416 # strip ${.CURDIR}/ from the output
417 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
418 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
419
420 .rawout.out:
421 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
422 < ${.IMPSRC} > ${.TARGET}.tmp1
423 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
424 @rm ${.TARGET}.tmp1
425 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
426 @mv ${.TARGET}.tmp2 ${.TARGET}
427
428 # Compare all output files
429 test: ${OUTFILES} .PHONY
430 @failed= ; \
431 for test in ${TESTS}; do \
432 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
433 || failed="$${failed}$${failed:+ }$${test}" ; \
434 done ; \
435 if [ -n "$${failed}" ]; then \
436 echo "Failed tests: $${failed}" ; false ; \
437 else \
438 echo "All tests passed" ; \
439 fi
440
441 accept:
442 @for test in ${TESTS}; do \
443 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
444 || { echo "Replacing $${test}.exp" ; \
445 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
446 done
447
448 SYNC_MI_AWK= \
449 BEGIN { \
450 testsdir = "usr.bin/make/unit-tests"; \
451 linestart = "./usr/tests/" testsdir; \
452 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
453 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
454 } \
455 function startswith(s, prefix) { \
456 return substr(s, 1, length(prefix)) == prefix; \
457 } \
458 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
459 { print $$0 } \
460 $$1 == linestart "/Makefile" { system(cmd) }
461
462 sync-mi:
463 @set -eu; \
464 cd "${MAKEFILE:tA:H}/../../.."; \
465 mi="distrib/sets/lists/tests/mi"; \
466 cvs update "$$mi"; \
467 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
468 mv -f "$$mi.$@" "$$mi"; \
469 cvs diff "$$mi" || true
470
471 .if exists(${TEST_MAKE})
472 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
473 .endif
474
475 .-include <bsd.obj.mk>
476