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