Makefile revision 1.119 1 # $NetBSD: Makefile,v 1.119 2020/08/23 14:46:33 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.sh-leading-plus= -n
338 FLAGS.vardebug= -k -dv FROM_CMDLINE=
339 FLAGS.varmod-match-escape= -dv
340 FLAGS.varname-dot-shell= -dpv
341 FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
342
343 # Some tests need extra post-processing.
344 SED_CMDS.sh-dots+= -e 's,^${.SHELL}: ,,' -e '/not found/s,command ,,'
345 SED_CMDS.varmod-subst-regex+= \
346 -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
347 SED_CMDS.varmod-edge+= -e 's, line [0-9]*:, line omitted:,'
348 SED_CMDS.varshell+= -e 's,^${.SHELL:T}: ,,'
349 SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
350 SED_CMDS.varname-dot-shell= -e 's, = /.*, = (details omitted),'
351 SED_CMDS.varname-dot-shell+= -e 's,"/[^"]*","(details omitted)",'
352 SED_CMDS.varname-dot-shell+= -e 's,\[/[^]]*\],[(details omitted)],'
353
354 # Some tests need an additional round of postprocessing.
355 POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
356 POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
357 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
358 POSTPROC.varname-dot-shell= \
359 awk '/\.SHELL/ || /^ParseReadLine/'
360 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
361
362 # Some tests reuse other tests, which makes them unnecessarily fragile.
363 export-all.rawout: export.mk
364 unexport.rawout: export.mk
365 unexport-env.rawout: export.mk
366
367 # End of the configuration section.
368
369 .MAIN: all
370
371 UNIT_TESTS:= ${.PARSEDIR}
372 .PATH: ${UNIT_TESTS}
373
374 OUTFILES= ${TESTS:=.out}
375
376 all: ${OUTFILES}
377
378 CLEANFILES= *.rawout *.out *.status *.tmp *.core *.tmp
379 CLEANFILES+= obj*.[och] lib*.a # posix1.mk
380 CLEANFILES+= issue* .[ab]* # suffixes.mk
381 CLEANDIRS= dir dummy # posix1.mk
382
383 clean:
384 rm -f ${CLEANFILES}
385 rm -rf ${CLEANDIRS}
386
387 TEST_MAKE?= ${.MAKE}
388 TOOL_SED?= sed
389
390 # ensure consistent results from sort(1)
391 LC_ALL= C
392 LANG= C
393 .export LANG LC_ALL
394
395 # the tests are actually done with sub-makes.
396 .SUFFIXES: .mk .rawout .out
397 .mk.rawout:
398 @${_MKMSG_TEST:Uecho '# test '} ${.PREFIX}
399 @set -eu; \
400 cd ${.OBJDIR}; \
401 env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \
402 ${TEST_MAKE} \
403 -r -C ${.CURDIR} -f ${.IMPSRC} \
404 ${FLAGS.${.TARGET:R}:U-k} \
405 > ${.TARGET}.tmp 2>&1 \
406 && status=$$? || status=$$?; \
407 echo $$status > ${.TARGET:R}.status
408 @mv ${.TARGET}.tmp ${.TARGET}
409
410 # Post-process the test output so that the results can be compared.
411 #
412 # always pretend .MAKE was called 'make'
413 _SED_CMDS+= -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
414 _SED_CMDS+= -e 's,${TEST_MAKE:S,.,\\.,g},make,'
415 # replace anything after 'stopped in' with unit-tests
416 _SED_CMDS+= -e '/stopped/s, /.*, unit-tests,'
417 # strip ${.CURDIR}/ from the output
418 _SED_CMDS+= -e 's,${.CURDIR:S,.,\\.,g}/,,g'
419 _SED_CMDS+= -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
420
421 .rawout.out:
422 @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
423 < ${.IMPSRC} > ${.TARGET}.tmp1
424 @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
425 @rm ${.TARGET}.tmp1
426 @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
427 @mv ${.TARGET}.tmp2 ${.TARGET}
428
429 # Compare all output files
430 test: ${OUTFILES} .PHONY
431 @failed= ; \
432 for test in ${TESTS}; do \
433 diff -u ${UNIT_TESTS}/$${test}.exp $${test}.out \
434 || failed="$${failed}$${failed:+ }$${test}" ; \
435 done ; \
436 if [ -n "$${failed}" ]; then \
437 echo "Failed tests: $${failed}" ; false ; \
438 else \
439 echo "All tests passed" ; \
440 fi
441
442 accept:
443 @for test in ${TESTS}; do \
444 cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
445 || { echo "Replacing $${test}.exp" ; \
446 cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
447 done
448
449 SYNC_MI_AWK= \
450 BEGIN { \
451 testsdir = "usr.bin/make/unit-tests"; \
452 linestart = "./usr/tests/" testsdir; \
453 fmt = linestart "/%s\ttests-usr.bin-tests\tcompattestfile,atf\\n"; \
454 cmd = "cd " testsdir " && ls *.exp *.mk | xargs printf '" fmt "'" \
455 } \
456 function startswith(s, prefix) { \
457 return substr(s, 1, length(prefix)) == prefix; \
458 } \
459 startswith($$1, linestart) && $$1 ~ /\.(exp|mk)$$/ { next } \
460 { print $$0 } \
461 $$1 == linestart "/Makefile" { system(cmd) }
462
463 sync-mi:
464 @set -eu; \
465 cd "${MAKEFILE:tA:H}/../../.."; \
466 mi="distrib/sets/lists/tests/mi"; \
467 cvs update "$$mi"; \
468 awk ${SYNC_MI_AWK:Q} < "$$mi" > "$$mi.$@"; \
469 mv -f "$$mi.$@" "$$mi"; \
470 cvs diff "$$mi" || true
471
472 .if exists(${TEST_MAKE})
473 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
474 .endif
475
476 .-include <bsd.obj.mk>
477