]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/Makefile
Update to bmake-20200902
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / Makefile
1 # $Id: Makefile,v 1.92 2020/09/02 18:39:29 sjg Exp $
2 #
3 # $NetBSD: Makefile,v 1.130 2020/09/02 05:33:57 rillig Exp $
4 #
5 # Unit tests for make(1)
6 #
7 # The main targets are:
8 #
9 # all:
10 #       run all the tests
11 # test:
12 #       run 'all', and compare to expected results
13 # accept:
14 #       move generated output to expected results
15 #
16 # Settable variables
17 #
18 # TEST_MAKE
19 #       The make program to be tested.
20 #
21 #
22 # Adding a test case
23 #
24 # Each feature should get its own set of tests in its own suitably
25 # named makefile (*.mk), with its own set of expected results (*.exp),
26 # and it should be added to the TESTS list.
27 #
28 # A few *.mk files are helper files for other tests (such as include-sub.mk)
29 # and are thus not added to TESTS.  Such files must be ignored in
30 # src/tests/usr.bin/make/t_make.sh.
31 #
32
33 # Each test is in a sub-makefile.
34 # Keep the list sorted.
35 # Any test that is commented out must be ignored in
36 # src/tests/usr.bin/make/t_make.sh as well.
37 TESTS+=         # archive       # broken on FreeBSD, enabled in t_make.sh
38 TESTS+=         archive-suffix
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-for
135 TESTS+=         directive-for-generating-endif
136 TESTS+=         directive-if
137 TESTS+=         directive-ifdef
138 TESTS+=         directive-ifmake
139 TESTS+=         directive-ifndef
140 TESTS+=         directive-ifnmake
141 TESTS+=         directive-info
142 TESTS+=         directive-undef
143 TESTS+=         directive-unexport
144 TESTS+=         directive-unexport-env
145 TESTS+=         directive-warning
146 TESTS+=         directives
147 TESTS+=         dollar
148 TESTS+=         doterror
149 TESTS+=         dotwait
150 TESTS+=         envfirst
151 TESTS+=         error
152 TESTS+=         # escape        # broken by reverting POSIX changes
153 TESTS+=         export
154 TESTS+=         export-all
155 TESTS+=         export-env
156 TESTS+=         export-variants
157 TESTS+=         forloop
158 TESTS+=         forsubst
159 TESTS+=         hash
160 TESTS+=         impsrc
161 TESTS+=         include-main
162 TESTS+=         lint
163 TESTS+=         make-exported
164 TESTS+=         misc
165 TESTS+=         moderrs
166 TESTS+=         modmatch
167 TESTS+=         modmisc
168 TESTS+=         modts
169 TESTS+=         modword
170 TESTS+=         opt
171 TESTS+=         opt-backwards
172 TESTS+=         opt-chdir
173 TESTS+=         opt-debug
174 TESTS+=         opt-debug-g1
175 TESTS+=         opt-define
176 TESTS+=         opt-env
177 TESTS+=         opt-file
178 TESTS+=         opt-ignore
179 TESTS+=         opt-include-dir
180 TESTS+=         opt-jobs
181 TESTS+=         opt-jobs-internal
182 TESTS+=         opt-keep-going
183 TESTS+=         opt-m-include-dir
184 TESTS+=         opt-no-action
185 TESTS+=         opt-no-action-at-all
186 TESTS+=         opt-query
187 TESTS+=         opt-raw
188 TESTS+=         opt-silent
189 TESTS+=         opt-touch
190 TESTS+=         opt-tracefile
191 TESTS+=         opt-var-expanded
192 TESTS+=         opt-var-literal
193 TESTS+=         opt-warnings-as-errors
194 TESTS+=         opt-where-am-i
195 TESTS+=         opt-x-reduce-exported
196 TESTS+=         order
197 TESTS+=         phony-end
198 TESTS+=         posix
199 TESTS+=         # posix1        # broken by reverting POSIX changes
200 TESTS+=         qequals
201 TESTS+=         recursive
202 TESTS+=         sh
203 TESTS+=         sh-dots
204 TESTS+=         sh-jobs
205 TESTS+=         sh-jobs-error
206 TESTS+=         sh-leading-at
207 TESTS+=         sh-leading-hyphen
208 TESTS+=         sh-leading-plus
209 TESTS+=         sh-meta-chars
210 TESTS+=         sh-multi-line
211 TESTS+=         sh-single-line
212 TESTS+=         # suffixes      # runs into an endless loop (try -dA)
213 TESTS+=         sunshcmd
214 TESTS+=         sysv
215 TESTS+=         ternary
216 TESTS+=         unexport
217 TESTS+=         unexport-env
218 TESTS+=         use-inference
219 TESTS+=         var-class
220 TESTS+=         var-class-cmdline
221 TESTS+=         var-class-env
222 TESTS+=         var-class-global
223 TESTS+=         var-class-local
224 TESTS+=         var-class-local-legacy
225 TESTS+=         var-op
226 TESTS+=         var-op-append
227 TESTS+=         var-op-assign
228 TESTS+=         var-op-default
229 TESTS+=         var-op-expand
230 TESTS+=         var-op-shell
231 TESTS+=         varcmd
232 TESTS+=         vardebug
233 TESTS+=         varfind
234 TESTS+=         varmisc
235 TESTS+=         varmod
236 TESTS+=         varmod-assign
237 TESTS+=         varmod-defined
238 TESTS+=         varmod-edge
239 TESTS+=         varmod-exclam-shell
240 TESTS+=         varmod-extension
241 TESTS+=         varmod-gmtime
242 TESTS+=         varmod-hash
243 TESTS+=         varmod-head
244 TESTS+=         varmod-ifelse
245 TESTS+=         varmod-l-name-to-value
246 TESTS+=         varmod-localtime
247 TESTS+=         varmod-loop
248 TESTS+=         varmod-match
249 TESTS+=         varmod-match-escape
250 TESTS+=         varmod-no-match
251 TESTS+=         varmod-order
252 TESTS+=         varmod-order-reverse
253 TESTS+=         varmod-order-shuffle
254 TESTS+=         varmod-path
255 TESTS+=         varmod-quote
256 TESTS+=         varmod-quote-dollar
257 TESTS+=         varmod-range
258 TESTS+=         varmod-remember
259 TESTS+=         varmod-root
260 TESTS+=         varmod-select-words
261 TESTS+=         varmod-shell
262 TESTS+=         varmod-subst
263 TESTS+=         varmod-subst-regex
264 TESTS+=         varmod-sysv
265 TESTS+=         varmod-tail
266 TESTS+=         varmod-to-abs
267 TESTS+=         varmod-to-lower
268 TESTS+=         varmod-to-many-words
269 TESTS+=         varmod-to-one-word
270 TESTS+=         varmod-to-separator
271 TESTS+=         varmod-to-upper
272 TESTS+=         varmod-undefined
273 TESTS+=         varmod-unique
274 TESTS+=         varname
275 TESTS+=         varname-dollar
276 TESTS+=         varname-dot-alltargets
277 TESTS+=         varname-dot-curdir
278 TESTS+=         varname-dot-includes
279 TESTS+=         varname-dot-includedfromdir
280 TESTS+=         varname-dot-includedfromfile
281 TESTS+=         varname-dot-libs
282 TESTS+=         varname-dot-make-dependfile
283 TESTS+=         varname-dot-make-expand_variables
284 TESTS+=         varname-dot-make-exported
285 TESTS+=         varname-dot-make-jobs
286 TESTS+=         varname-dot-make-jobs-prefix
287 TESTS+=         varname-dot-make-level
288 TESTS+=         varname-dot-make-makefile_preference
289 TESTS+=         varname-dot-make-makefiles
290 TESTS+=         varname-dot-make-meta-bailiwick
291 TESTS+=         varname-dot-make-meta-created
292 TESTS+=         varname-dot-make-meta-files
293 TESTS+=         varname-dot-make-meta-ignore_filter
294 TESTS+=         varname-dot-make-meta-ignore_paths
295 TESTS+=         varname-dot-make-meta-ignore_patterns
296 TESTS+=         varname-dot-make-meta-prefix
297 TESTS+=         varname-dot-make-mode
298 TESTS+=         varname-dot-make-path_filemon
299 TESTS+=         varname-dot-make-pid
300 TESTS+=         varname-dot-make-ppid
301 TESTS+=         varname-dot-make-save_dollars
302 TESTS+=         varname-dot-makeoverrides
303 TESTS+=         varname-dot-newline
304 TESTS+=         varname-dot-objdir
305 TESTS+=         varname-dot-parsedir
306 TESTS+=         varname-dot-parsefile
307 TESTS+=         varname-dot-path
308 TESTS+=         varname-dot-shell
309 TESTS+=         varname-dot-targets
310 TESTS+=         varname-empty
311 TESTS+=         varname-make
312 TESTS+=         varname-make_print_var_on_error
313 TESTS+=         varname-makeflags
314 TESTS+=         varname-pwd
315 TESTS+=         varname-vpath
316 TESTS+=         varparse-dynamic
317 TESTS+=         varquote
318 TESTS+=         varshell
319
320 # Additional environment variables for some of the tests.
321 # The base environment is -i PATH="$PATH".
322 ENV.envfirst=           FROM_ENV=value-from-env
323 ENV.varmisc=            FROM_ENV=env
324 ENV.varmisc+=           FROM_ENV_BEFORE=env
325 ENV.varmisc+=           FROM_ENV_AFTER=env
326
327 # Override make flags for some of the tests; default is -k.
328 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
329 # settings FLAGS.test=-dv here, since that is closer to the test code.
330 FLAGS.archive=          -dA
331 FLAGS.counter=          -dv
332 FLAGS.directive-ifmake= first second
333 FLAGS.doterror=         # none
334 FLAGS.envfirst=         -e
335 FLAGS.export=           # none
336 FLAGS.lint=             -dL -k
337 FLAGS.opt-debug-g1=     -dg1
338 FLAGS.opt-ignore=       -i
339 FLAGS.opt-keep-going=   -k
340 FLAGS.opt-no-action=    -n
341 FLAGS.opt-query=        -q
342 FLAGS.opt-var-expanded= -v VAR -v VALUE
343 FLAGS.opt-var-literal=  -V VAR -V VALUE
344 FLAGS.opt-warnings-as-errors= -W
345 FLAGS.order=            -j1
346 FLAGS.recursive=        -dL
347 FLAGS.sh-leading-plus=  -n
348 FLAGS.vardebug=         -k -dv FROM_CMDLINE=
349 FLAGS.varmod-match-escape= -dv
350 FLAGS.varname-dot-shell= -dpv
351 FLAGS.varname-empty=    -dv '$${:U}=cmdline-u' '=cmline-plain'
352
353 # Some tests need extra post-processing.
354 SED_CMDS.opt-debug-g1=  -e 's,${.CURDIR},CURDIR,'
355 SED_CMDS.opt-debug-g1+= -e '/Global Variables:/,/Suffixes:/d'
356 SED_CMDS.sh-dots=       -e 's,^.*\.\.\.:.*,<normalized: ...: not found>,'
357 SED_CMDS.varmod-subst-regex+= \
358                         -e 's,\(Regex compilation error:\).*,\1 (details omitted),'
359 SED_CMDS.varmod-edge+=  -e 's, line [0-9]*:, line omitted:,'
360 SED_CMDS.varshell+=     -e 's,^${.SHELL:T}: ,,'
361 SED_CMDS.varshell+=     -e '/command/s,No such.*,not found,'
362 SED_CMDS.varname-dot-shell=     -e 's, = /.*, = (details omitted),'
363 SED_CMDS.varname-dot-shell+=    -e 's,"/[^"]*","(details omitted)",'
364 SED_CMDS.varname-dot-shell+=    -e 's,\[/[^]]*\],[(details omitted)],'
365
366 # Some tests need an additional round of postprocessing.
367 POSTPROC.counter=       ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
368 POSTPROC.deptgt-suffixes= \
369                         ${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
370 POSTPROC.vardebug=      ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
371 POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
372 POSTPROC.varname-dot-shell= \
373                         awk '/\.SHELL/ || /^ParseReadLine/'
374 POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
375
376 # Some tests reuse other tests, which makes them unnecessarily fragile.
377 export-all.rawout: export.mk
378 unexport.rawout: export.mk
379 unexport-env.rawout: export.mk
380
381 # End of the configuration section.
382
383 .MAIN: all
384
385 .-include "Makefile.inc"
386 .-include "Makefile.config"
387
388 UNIT_TESTS:=    ${.PARSEDIR}
389 .PATH: ${UNIT_TESTS}
390
391 OUTFILES=       ${TESTS:=.out}
392
393 all: ${OUTFILES}
394
395 CLEANFILES=             *.rawout *.out *.status *.tmp *.core *.tmp
396 CLEANFILES+=            obj*.[och] lib*.a       # posix1.mk
397 CLEANFILES+=            issue* .[ab]*           # suffixes.mk
398 CLEANDIRS=              dir dummy               # posix1.mk
399
400 clean:
401         rm -f ${CLEANFILES}
402         rm -rf ${CLEANDIRS}
403
404 TEST_MAKE?=     ${.MAKE}
405 TOOL_SED?=      sed
406 TOOL_TR?=       tr
407 TOOL_DIFF?=     diff
408 DIFF_FLAGS?=    -u
409
410 .if defined(.PARSEDIR)
411 # ensure consistent results from sort(1)
412 LC_ALL=         C
413 LANG=           C
414 .export LANG LC_ALL
415 .endif
416
417 .if ${.MAKE.MODE:Unormal:Mmeta} != ""
418 # we don't need the noise
419 _MKMSG_TEST= :
420 .endif
421
422 # the tests are actually done with sub-makes.
423 .SUFFIXES: .mk .rawout .out
424 .mk.rawout:
425         @${_MKMSG_TEST:Uecho '#      test '} ${.PREFIX}
426         @set -eu; \
427         cd ${.OBJDIR}; \
428         env -i PATH="$$PATH" ${ENV.${.TARGET:R}} \
429           ${TEST_MAKE} \
430             -r -C ${.CURDIR} -f ${.IMPSRC} \
431             ${FLAGS.${.TARGET:R}:U-k} \
432             > ${.TARGET}.tmp 2>&1 \
433         && status=$$? || status=$$?; \
434         echo $$status > ${.TARGET:R}.status
435         @mv ${.TARGET}.tmp ${.TARGET}
436
437 # Post-process the test output so that the results can be compared.
438 #
439 # always pretend .MAKE was called 'make'
440 _SED_CMDS+=     -e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
441 _SED_CMDS+=     -e 's,${TEST_MAKE:S,.,\\.,g},make,'
442 # replace anything after 'stopped in' with unit-tests
443 _SED_CMDS+=     -e '/stopped/s, /.*, unit-tests,'
444 # strip ${.CURDIR}/ from the output
445 _SED_CMDS+=     -e 's,${.CURDIR:S,.,\\.,g}/,,g'
446 _SED_CMDS+=     -e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
447
448 .rawout.out:
449         @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
450           < ${.IMPSRC} > ${.TARGET}.tmp1
451         @${POSTPROC.${.TARGET:R}:Ucat} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
452         @rm ${.TARGET}.tmp1
453         @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
454         @mv ${.TARGET}.tmp2 ${.TARGET}
455
456 # Compare all output files
457 test:   ${OUTFILES} .PHONY
458         @failed= ; \
459         for test in ${TESTS}; do \
460           ${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/$${test}.exp $${test}.out \
461           || failed="$${failed}$${failed:+ }$${test}" ; \
462         done ; \
463         if [ -n "$${failed}" ]; then \
464           echo "Failed tests: $${failed}" ; false ; \
465         else \
466           echo "All tests passed" ; \
467         fi
468
469 accept:
470         @for test in ${TESTS}; do \
471           cmp -s ${UNIT_TESTS}/$${test}.exp $${test}.out \
472           || { echo "Replacing $${test}.exp" ; \
473                cp $${test}.out ${UNIT_TESTS}/$${test}.exp ; } \
474         done
475
476 .if exists(${TEST_MAKE})
477 ${TESTS:=.rawout}: ${TEST_MAKE} ${.PARSEDIR}/Makefile
478 .endif
479
480 .-include <obj.mk>