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