Makefile revision 1.120 1 # $NetBSD: Makefile,v 1.120 2020/08/27 19:00:17 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-debug-g1
172 TESTS+= opt-define
173 TESTS+= opt-env
174 TESTS+= opt-file
175 TESTS+= opt-ignore
176 TESTS+= opt-include-dir
177 TESTS+= opt-jobs
178 TESTS+= opt-jobs-internal
179 TESTS+= opt-keep-going
180 TESTS+= opt-m-include-dir
181 TESTS+= opt-no-action
182 TESTS+= opt-no-action-at-all
183 TESTS+= opt-query
184 TESTS+= opt-raw
185 TESTS+= opt-silent
186 TESTS+= opt-touch
187 TESTS+= opt-tracefile
188 TESTS+= opt-var-expanded
189 TESTS+= opt-var-literal
190 TESTS+= opt-warnings-as-errors
191 TESTS+= opt-where-am-i
192 TESTS+= opt-x-reduce-exported
193 TESTS+= order
194 TESTS+= phony-end
195 TESTS+= posix
196 TESTS+= # posix1 # broken by reverting POSIX changes
197 TESTS+= qequals
198 TESTS+= recursive
199 TESTS+= sh
200 TESTS+= sh-dots
201 TESTS+= sh-jobs
202 TESTS+= sh-jobs-error
203 TESTS+= sh-leading-at
204 TESTS+= sh-leading-hyphen
205 TESTS+= sh-leading-plus
206 TESTS+= sh-meta-chars
207 TESTS+= sh-multi-line
208 TESTS+= sh-single-line
209 TESTS+= # suffixes # runs into an endless loop (try -dA)
210 TESTS+= sunshcmd
211 TESTS+= sysv
212 TESTS+= ternary
213 TESTS+= unexport
214 TESTS+= unexport-env
215 TESTS+= use-inference
216 TESTS+= var-class
217 TESTS+= var-class-cmdline
218 TESTS+= var-class-env
219 TESTS+= var-class-global
220 TESTS+= var-class-local
221 TESTS+= var-class-local-legacy
222 TESTS+= var-op
223 TESTS+= var-op-append
224 TESTS+= var-op-assign
225 TESTS+= var-op-default
226 TESTS+= var-op-expand
227 TESTS+= var-op-shell
228 TESTS+= varcmd
229 TESTS+= vardebug
230 TESTS+= varfind
231 TESTS+= varmisc
232 TESTS+= varmod
233 TESTS+= varmod-assign
234 TESTS+= varmod-defined
235 TESTS+= varmod-edge
236 TESTS+= varmod-exclam-shell
237 TESTS+= varmod-extension
238 TESTS+= varmod-gmtime
239 TESTS+= varmod-hash
240 TESTS+= varmod-head
241 TESTS+= varmod-ifelse
242 TESTS+= varmod-l-name-to-value
243 TESTS+= varmod-localtime
244 TESTS+= varmod-loop
245 TESTS+= varmod-match
246 TESTS+= varmod-match-escape
247 TESTS+= varmod-no-match
248 TESTS+= varmod-order
249 TESTS+= varmod-order-reverse
250 TESTS+= varmod-order-shuffle
251 TESTS+= varmod-path
252 TESTS+= varmod-quote
253 TESTS+= varmod-quote-dollar
254 TESTS+= varmod-range
255 TESTS+= varmod-remember
256 TESTS+= varmod-root
257 TESTS+= varmod-select-words
258 TESTS+= varmod-shell
259 TESTS+= varmod-subst
260 TESTS+= varmod-subst-regex
261 TESTS+= varmod-sysv
262 TESTS+= varmod-tail
263 TESTS+= varmod-to-abs
264 TESTS+= varmod-to-lower
265 TESTS+= varmod-to-many-words
266 TESTS+= varmod-to-one-word
267 TESTS+= varmod-to-separator
268 TESTS+= varmod-to-upper
269 TESTS+= varmod-undefined
270 TESTS+= varmod-unique
271 TESTS+= varname
272 TESTS+= varname-dollar
273 TESTS+= varname-dot-alltargets
274 TESTS+= varname-dot-curdir
275 TESTS+= varname-dot-includedfromdir
276 TESTS+= varname-dot-includedfromfile
277 TESTS+= varname-dot-make-dependfile
278 TESTS+= varname-dot-make-expand_variables
279 TESTS+= varname-dot-make-exported
280 TESTS+= varname-dot-make-jobs
281 TESTS+= varname-dot-make-jobs-prefix
282 TESTS+= varname-dot-make-level
283 TESTS+= varname-dot-make-makefile_preference
284 TESTS+= varname-dot-make-makefiles
285 TESTS+= varname-dot-make-meta-bailiwick
286 TESTS+= varname-dot-make-meta-created
287 TESTS+= varname-dot-make-meta-files
288 TESTS+= varname-dot-make-meta-ignore_filter
289 TESTS+= varname-dot-make-meta-ignore_paths
290 TESTS+= varname-dot-make-meta-ignore_patterns
291 TESTS+= varname-dot-make-meta-prefix
292 TESTS+= varname-dot-make-mode
293 TESTS+= varname-dot-make-path_filemon
294 TESTS+= varname-dot-make-pid
295 TESTS+= varname-dot-make-ppid
296 TESTS+= varname-dot-make-save_dollars
297 TESTS+= varname-dot-makeoverrides
298 TESTS+= varname-dot-newline
299 TESTS+= varname-dot-objdir
300 TESTS+= varname-dot-parsedir
301 TESTS+= varname-dot-parsefile
302 TESTS+= varname-dot-path
303 TESTS+= varname-dot-shell
304 TESTS+= varname-dot-targets
305 TESTS+= varname-empty
306 TESTS+= varname-make
307 TESTS+= varname-make_print_var_on_error
308 TESTS+= varname-makeflags
309 TESTS+= varname-pwd
310 TESTS+= varname-vpath
311 TESTS+= varparse-dynamic
312 TESTS+= varquote
313 TESTS+= varshell
314
315 # Additional environment variables for some of the tests.
316 # The base environment is -i PATH="$PATH".
317 ENV.envfirst= FROM_ENV=value-from-env
318 ENV.varmisc= FROM_ENV=env
319 ENV.varmisc+= FROM_ENV_BEFORE=env
320 ENV.varmisc+= FROM_ENV_AFTER=env
321
322 # Override make flags for some of the tests; default is -k.
323 FLAGS.archive= -dA
324 FLAGS.counter= -dv
325 FLAGS.doterror= # none
326 FLAGS.envfirst= -e
327 FLAGS.export= # none
328 FLAGS.lint= -dL -k
329 FLAGS.opt-debug-g1= -dg1
330 FLAGS.opt-ignore= -i
331 FLAGS.opt-keep-going= -k
332 FLAGS.opt-no-action= -n
333 FLAGS.opt-query= -q
334 FLAGS.opt-var-expanded= -v VAR -v VALUE
335 FLAGS.opt-var-literal= -V VAR -V VALUE
336 FLAGS.opt-warnings-as-errors= -W
337 FLAGS.order= -j1
338 FLAGS.recursive= -dL
339 FLAGS.sh-leading-plus= -n
340 FLAGS.vardebug= -k -dv FROM_CMDLINE=
341 FLAGS.varmod-match-escape= -dv
342 FLAGS.varname-dot-shell= -dpv
343 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
344
345 # Some tests need extra post-processing.
346 SED_CMDS.opt-debug-g1= -e 's,${.CURDIR},CURDIR,'
347 SED_CMDS.opt-debug-g1+= -e 's,[/[a-z]*/share/mk,/.../share/mk,'
348 SED_CMDS.opt-debug-g1+= -e '/Global Variables/,/Directory Cache/d'
349 SED_CMDS.sh-dots+= -e 's,^${.SHELL}: ,,' -e '/not found/s,command ,,'
350 SED_CMDS.varmod-subst-regex+= \
351 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
352 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
353 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
354 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
355 SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),'
356 SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",'
357 SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],'
358
359 # Some tests need an additional round of postprocessing.
360 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
361 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
362 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
363 POSTPROC.varname-dot-shell= \
364 awk '/\.SHELL/ || /^ParseReadLine/'
365 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
366
367 # Some tests reuse other tests, which makes them unnecessarily fragile.
368 export-all.rawout: export.mk
369 unexport.rawout: export.mk
370 unexport-env.rawout: export.mk
371
372 # End of the configuration section.
373
374 .MAIN: all
375
376 UNIT_TESTS:= ${.PARSEDIR}
377 .PATH: ${UNIT_TESTS}
378
379 OUTFILES= ${TESTS:=.out}
380
381 all: ${OUTFILES}
382
383 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
384 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
385 CLEANFILES+= issue* .[ab]* # suffixes.mk
386 CLEANDIRS= dir dummy # posix1.mk
387
388 clean:
389 rm -f ${CLEANFILES}
390 rm -rf ${CLEANDIRS}
391
392 TEST_MAKE?= ${.MAKE}
393 TOOL_SED?= sed
394
395 # ensure consistent results from sort(1)
396 LC_ALL= C
397 LANG= C
398 .export LANG LC_ALL
399
400 # the tests are actually done with sub-makes.
401 .SUFFIXES: .mk .rawout .out
402 .mk.rawout:
403 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
404 @set -eu; \
405 cd ${.OBJDIR}; \
406 env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \
407 ${TEST_MAKE} \
408 -r -C ${.CURDIR} -f ${.IMPSRC} \
409 ${FLAGS.${.TARGET:R}:U-k} \
410 > ${.TARGET}.tmp 2>&1 \
411 && status=$$? || status=$$?; \
412 echo $$status > ${.TARGET:R}.status
413 @mv ${.TARGET}.tmp ${.TARGET}
414
415 # Post-process the test output so that the results can be compared.
416 #
417 # always pretend .MAKE was called 'make'
418 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
419 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
420 # replace anything after 'stopped in' with unit-tests
421 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
422 # strip ${.CURDIR}/ from the output
423 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
424 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
425
426 .rawout.out:
427 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
428 < ${.IMPSRC} > ${.TARGET}.tmp1
429 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
430 @rm ${.TARGET}.tmp1
431 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
432 @mv ${.TARGET}.tmp2 ${.TARGET}
433
434 # Compare all output files
435 test: ${OUTFILES} .PHONY
436 @failed= ; \
437 for test in ${TESTS}; do \
438 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
439 || failed="$${failed}$${failed:+ }$${test}" ; \
440 done ; \
441 if [ -n "$${failed}" ]; then \
442 echo "Failed tests: $${failed}" ; false ; \
443 else \
444 echo "All tests passed" ; \
445 fi
446
447 accept:
448 @for test in ${TESTS}; do \
449 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
450 || { echo "Replacing $${test}.exp" ; \
451 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
452 done
453
454 SYNC_MI_AWK= \
455 BEGIN { \
456 testsdir = "usr.bin/make/unit-tests"; \
457 linestart = "./usr/tests/" testsdir; \
458 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
459 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
460 } \
461 function startswith(s, prefix) { \
462 return substr(s, 1, length(prefix)) == prefix; \
463 } \
464 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
465 { print $$0 } \
466 $$1 == linestart "/Makefile" { system(cmd) }
467
468 sync-mi:
469 @set -eu; \
470 cd "${MAKEFILE:tA:H}/../../.."; \
471 mi="distrib/sets/lists/tests/mi"; \
472 cvs update "$$mi"; \
473 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
474 mv -f "$$mi.$@" "$$mi"; \
475 cvs diff "$$mi" || true
476
477 .if exists(${TEST_MAKE})
478 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
479 .endif
480
481 .-include <bsd.obj.mk>
482