Merge branch 'maint'
[platform/upstream/automake.git] / lib / am / check.am
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 2001, 2003, 2006, 2007, 2008, 2009, 2010, 2011 Free
3 ## Software Foundation, Inc.
4
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2, or (at your option)
8 ## any later version.
9
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 am__tty_colors_dummy = \
19   mgn= red= grn= lgn= blu= brg= std=; \
20   am__color_tests=no
21 if %?COLOR%
22 # If stdout is a non-dumb tty, use colors.  If test -t is not supported,
23 # then this fails; a conservative approach.  Of course do not redirect
24 # stdout here, just stderr.
25 am__tty_colors = \
26 $(am__tty_colors_dummy); \
27 test "X$(AM_COLOR_TESTS)" != Xno \
28 && test "X$$TERM" != Xdumb \
29 && { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
30 && { \
31   am__color_tests=yes; \
32   red='\e[0;31m'; \
33   grn='\e[0;32m'; \
34   lgn='\e[1;32m'; \
35   blu='\e[1;34m'; \
36   mgn='\e[0;35m'; \
37   brg='\e[1m'; \
38   std='\e[m'; \
39 }
40 else !%?COLOR%
41 am__tty_colors = $(am__tty_colors_dummy)
42 endif !%?COLOR%
43
44 .PHONY: check-TESTS
45
46 if %?PARALLEL_TESTS%
47
48 include inst-vars.am
49
50 ## New parallel test driver.
51 ##
52 ## The first version of the code here was adapted from check.mk, which was
53 ## originally written at EPITA/LRDE, further developed at Gostai, then made
54 ## its way from GNU coreutils to end up, largely rewritten, in Automake.
55 ## The current version is an heavy rewrite of that, to allow for support
56 ## of more test metadata, and the use of custom test derivers and protocols
57 ## (among them, TAP).
58
59 # Restructured Text title and section.
60 am__rst_title = sed 's/.*/   &   /;h;s/./=/g;p;x;p;g;p;s/.*//'
61 am__rst_section = sed 'p;s/./=/g;p;g'
62
63 # Solaris 10 'make', and several other traditional 'make' implementations,
64 # pass "-e" to $(SHELL), and POSIX 2008 even requires this.  Work around it
65 # by disabling -e (using the XSI extension "set +e") if it's set.
66 am__sh_e_setup = case $$- in *e*) set +e;; esac
67
68 # Default flags passed to test drivers.
69 am__common_driver_flags = \
70   --color-tests "$$am__color_tests" \
71   --enable-hard-errors "$$am__enable_hard_errors" \
72   --expect-failure "$$am__expect_failure"
73
74 # To be inserted before the command running the test.  Creates the
75 # directory for the log if needed.  Stores in $dir the directory
76 # containing $f, in $tst the test, in $log the log.  Executes the
77 # developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and
78 # passes TESTS_ENVIRONMENT.  Set up options for the wrapper that
79 # will run the test scripts (or their associated LOG_COMPILER, if
80 # thy have one).
81 am__check_pre =                                         \
82 $(am__sh_e_setup);                                      \
83 $(am__vpath_adj_setup) $(am__vpath_adj)                 \
84 $(am__tty_colors);                                      \
85 srcdir=$(srcdir); export srcdir;                        \
86 am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;            \
87 test "x$$am__odir" = x. || $(MKDIR_P) "$$am__odir" || exit $$?; \
88 if test -f "./$$f"; then dir=./;                        \
89 elif test -f "$$f"; then dir=;                          \
90 else dir="$(srcdir)/"; fi;                              \
91 tst=$$dir$$f; log='$@';                                 \
92 if test -n '$(DISABLE_HARD_ERRORS)'; then               \
93   am__enable_hard_errors=no;                            \
94 else                                                    \
95   am__enable_hard_errors=yes;                           \
96 fi;                                                     \
97 ## The use of $dir below is required to account for VPATH
98 ## rewriting done by Sun make.
99 case " $(XFAIL_TESTS) " in                              \
100   *[\ \ ]$$f[\ \        ]* | *[\ \      ]$$dir$$f[\ \   ]*) \
101     am__expect_failure=yes;;                            \
102   *)                                                    \
103     am__expect_failure=no;;                             \
104 esac;                                                   \
105 $(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT)
106
107 # A shell command to get the names of the tests scripts with any registered
108 # extension removed (i.e., equivalently, the names of the test logs, with
109 # the `.log' extension removed).  The result is saved in the shell variable
110 # `$bases'.  This honors runtime overriding of TESTS and TEST_LOGS.  Sadly,
111 # we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)",
112 # since that might cause problem with VPATH rewrites for suffix-less tests.
113 # See also 'test-harness-vpath-rewrite.test' and 'test-trs-basic.test'.
114 am__set_TESTS_bases = \
115   bases='$(TEST_LOGS)'; \
116   bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \
117 ## Trim away any extra whitespace.  This has already proved useful in
118 ## avoiding weird bug on lesser make implementations.
119   bases=`echo $$bases`
120
121 # Recover from deleted `.trs' file; this should ensure that
122 # "rm -f foo.log; make foo.trs" re-run `foo.test', and re-create
123 # both `foo.log' and `foo.trs'.  Break the recipe in two subshells
124 # to avoid problems with "make -n".
125 .log.trs:
126         rm -f $< $@
127         $(MAKE) $(AM_MAKEFLAGS) $<
128
129 # Helper recipe used by $(TEST_SUITE_LOG) below, to avoid problems with
130 # "make -n".  Break this recipe in multiple shell invocations too, to
131 # really work as expected with "make -n".
132 am--redo-logs:
133         @rm -f $$redo_logs
134         @rm -f $$redo_results
135 ## The use of the `am__remaking_logs' environment variable below is
136 ## required to ensure that we don't go into an infinite recursion in
137 ## case a test log in $(TEST_LOGS) is the same as $(TEST_SUITE_LOG).
138 ## Yes, this has already happened in practice.  Sigh!
139         @if test -n "$$am__remaking_logs"; then \
140           echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \
141                "recursion detected" >&2; \
142         else \
143           am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
144         fi;
145 ## Sanity check: each unreadable or non-existent test result file should
146 ## has been properly remade at this point, as should the corresponding log
147 ## file.
148         @st=0;  \
149         errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \
150         for i in $$redo_bases; do \
151           test -f $$i.trs && test -r $$i.trs \
152             || { echo "$$errmsg $$i.trs"; st=1; }; \
153           test -f $$i.log && test -r $$i.log \
154             || { echo "$$errmsg $$i.log"; st=1; }; \
155         done; \
156         test $$st -eq 0
157 .PHONY: am--redo-logs
158
159 $(TEST_SUITE_LOG): $(TEST_LOGS)
160         @$(am__set_TESTS_bases); \
161 ## Helper shell function, tells whether a path refers to an existing,
162 ## regular, readable file.
163         am__f_ok () { test -f "$$1" && test -r "$$1"; }; \
164 ## We need to ensures that all the required `.trs' and `.log' files will
165 ## be present and readable.  The direct dependencies of $(TEST_SUITE_LOG)
166 ## only ensure that all the `.log' files exists; they don't ensure that
167 ## the `.log' files are readable, and worse, they don't ensure that the
168 ## `.trs' files even exist.
169         redo_bases=`for i in $$bases; do \
170                       am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \
171                     done`; \
172         if test -n "$$redo_bases"; then \
173 ## Uh-oh, either some `.log' files were unreadable, or some `.trs' files
174 ## were missing (or unreadable).  We need to re-run the corresponding
175 ## tests in order to re-create them.
176           redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \
177           redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \
178 ## The exported variables are needed by the helper hook.
179           redo_bases="$$redo_bases" \
180           redo_logs="$$redo_logs" \
181           redo_results="$$redo_results" \
182             $(MAKE) $(AM_MAKEFLAGS) am--redo-logs || exit 1; \
183         else :; fi;
184 ## We need a new subshell to work portably with "make -n", since the
185 ## previous part of the recipe contained a $(MAKE) invocation.
186         @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \
187         ws='[   ]'; \
188 ## List of test result files.
189         results=`for b in $$bases; do echo $$b.trs; done`; \
190         test -n "$$results" || results=/dev/null; \
191 ## Prepare data for the test suite summary.  These do not take into account
192 ## unreadable test results, but they'll be appropriately updated later if
193 ## needed.
194         all=`  grep "^$$ws*:test-result:"           $$results | wc -l`; \
195         pass=` grep "^$$ws*:test-result:$$ws*PASS"  $$results | wc -l`; \
196         fail=` grep "^$$ws*:test-result:$$ws*FAIL"  $$results | wc -l`; \
197         skip=` grep "^$$ws*:test-result:$$ws*SKIP"  $$results | wc -l`; \
198         xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \
199         xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \
200         error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \
201 ## Whether the testsuite was successful or not.
202         if test `expr $$fail + $$xpass + $$error` -eq 0; then \
203           success=true; \
204         else \
205           success=false; \
206         fi; \
207 ## Make $br a line of exactly 76 `=' characters, that will be used to
208 ## enclose the testsuite summary report when displayed on the console.
209         br='==================='; br=$$br$$br$$br$$br; \
210 ## When writing the test summary to the console, we want to color a line
211 ## reporting the count of some result *only* if at least one test
212 ## experienced such a result.  This function is handy in this regard.
213         result_count () \
214         { \
215             if test x"$$1" = x"--maybe-color"; then \
216               maybe_colorize=yes; \
217             elif test x"$$1" = x"--no-color"; then \
218               maybe_colorize=no; \
219             else \
220               echo "$@: invalid 'result_count' usage" >&2; exit 4; \
221             fi; \
222             shift; \
223             desc=$$1 count=$$2; \
224             if test $$maybe_colorize = yes && test $$count -gt 0; then \
225               color_start=$$3 color_end=$$std; \
226             else \
227               color_start= color_end=; \
228             fi; \
229             echo "$${color_start}# $$desc $$count$${color_end}"; \
230         }; \
231 ## A shell function that creates the testsuite summary.  We need it
232 ## because we have to create *two* summaries, one for test-suite.log,
233 ## and a possibly-colorized one for console output.
234         create_testsuite_report () \
235         { \
236           result_count $$1 "TOTAL:" $$all   "$$brg"; \
237           result_count $$1 "PASS: " $$pass  "$$grn"; \
238           result_count $$1 "SKIP: " $$skip  "$$blu"; \
239           result_count $$1 "XFAIL:" $$xfail "$$lgn"; \
240           result_count $$1 "FAIL: " $$fail  "$$red"; \
241           result_count $$1 "XPASS:" $$xpass "$$red"; \
242           result_count $$1 "ERROR:" $$error "$$mgn"; \
243         }; \
244 ## Write "global" testsuite log.
245         {                                                               \
246           echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |       \
247             $(am__rst_title);                                           \
248           create_testsuite_report --no-color;                           \
249           echo;                                                         \
250           echo ".. contents:: :depth: 2";                               \
251           echo;                                                         \
252           for i in $$bases; do                                          \
253 ## FIXME: one fork per test -- this is horrendously inefficient!
254             if grep "^$$ws*:copy-in-global-log:$$ws*no$$ws*$$" $$i.trs \
255                  >/dev/null; then continue; \
256             fi; \
257 ## Get the declared "global result" of the test.
258 ## FIXME: yet another one fork per test here!
259             glob_res=`sed -n -e "s/$$ws*$$//" \
260                              -e "s/^$$ws*:global-test-result:$$ws*//p" \
261                         $$i.trs`; \
262 ## If no global result is explicitly declared, we'll merely mark the
263 ## test as "RUN" in the global test log.
264             test -n "$$glob_res" || glob_res=RUN; \
265 ## Write the name and result of the test as an RST section title.
266             echo "$$glob_res: $$i" | $(am__rst_section); \
267 ## If we should have remade any unreadable `.log', above.
268             if test ! -r $$i.log; then \
269               echo "fatal: making $@: $$i.log is unreadable" >&2; \
270               exit 1; \
271             fi; \
272             cat $$i.log; echo; \
273           done; \
274         } >$(TEST_SUITE_LOG).tmp;                                       \
275         mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);                     \
276 ## Emit the test summary on the console.
277         if $$success; then                                              \
278           col="$$grn";                                                  \
279          else                                                           \
280           col="$$red";                                                  \
281           test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG);               \
282         fi;                                                             \
283 ## Multi line coloring is problematic with "less -R", so we really need
284 ## to color each line individually.
285         echo "$${col}$$br$${std}";                                      \
286         echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}";   \
287         echo "$${col}$$br$${std}";                                      \
288 ## This is expected to go to the console, so it might have to be colorized.
289         create_testsuite_report --maybe-color;                          \
290         echo "$$col$$br$$std";                                          \
291         if $$success; then :; else                                      \
292           echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}";         \
293           if test -n "$(PACKAGE_BUGREPORT)"; then                       \
294             echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \
295           fi;                                                           \
296           echo "$$col$$br$$std";                                        \
297         fi;                                                             \
298 ## Be sure to exit with the proper exit status.  The use of "exit 1" below
299 ## is required to work around a FreeBSD make bug (present only when running
300 ## in concurrent mode).  See automake bug#9245:
301 ##  <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9245>
302 ## and FreeBSD PR bin/159730:
303 ##  <http://www.freebsd.org/cgi/query-pr.cgi?pr=159730>.
304         $$success || exit 1
305
306 RECHECK_LOGS = $(TEST_LOGS)
307
308 # Run all the tests.
309 check-TESTS:
310 ## Expand $(RECHECK_LOGS) only once, to avoid exceeding line length limits.
311         @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list
312         @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list
313 ## We always have to remove TEST_SUITE_LOG, to ensure its rule is run
314 ## in any case even in lazy mode: otherwise, if no test needs rerunning,
315 ## or a prior run plus reruns all happen within the same timestamp
316 ## (can happen with a prior `make TESTS=<subset>'),
317 ## then we get no log output.
318 ## OTOH, this means that, in the rule for `$(TEST_SUITE_LOG)', we
319 ## cannot use `$?' to compute the set of lazily rerun tests, lest
320 ## we rely on .PHONY to work portably.
321         @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
322         @list='' list2='$(TEST_LOGS)'; for i in $$list2; do \
323 ## Trailing whitespace in `TESTS = foo.test $(empty)' causes GNU make
324 ## 3.80 to erroneously expand $(TESTS_LOGS) to `foo.log .log'.
325 ## Work around this bug.
326           test .log = $$i && continue; \
327 ## Be careful to avoid extra whitespace in the definition of $list.  See
328 ## comments in `recheck' below for why this might be useful.
329           if test -z "$$list"; then list=$$i; else list="$$list $$i"; fi; \
330         done; \
331         $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$list"
332
333 AM_RECURSIVE_TARGETS += check
334
335 ## -------------- ##
336 ## Produce HTML.  ##
337 ## -------------- ##
338
339 .log.html:
340         @list='$(RST2HTML) $$RST2HTML rst2html rst2html.py';            \
341         for r2h in $$list; do                                           \
342           if ($$r2h --version) >/dev/null 2>&1; then                    \
343             R2H=$$r2h;                                                  \
344           fi;                                                           \
345         done;                                                           \
346         if test -z "$$R2H"; then                                        \
347           echo >&2 "cannot find rst2html, cannot create $@";            \
348           exit 2;                                                       \
349         fi;                                                             \
350         $$R2H $< >$@.tmp
351         @mv $@.tmp $@
352
353 # Be sure to run check first, and then to convert the result.
354 # Beware of concurrent executions.  Run "check" not "check-TESTS", as
355 # check-SCRIPTS and other dependencies are rebuilt by the former only.
356 # And expect check to fail.
357 check-html:
358         @if $(MAKE) $(AM_MAKEFLAGS) check; then                 \
359           rv=0; else rv=$$?;                                    \
360         fi;                                                     \
361         $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_HTML) || exit 4;   \
362         exit $$rv
363
364 .PHONY: check-html
365 .MAKE: check-html
366
367 AM_RECURSIVE_TARGETS += check-html
368
369 ## -------------------- ##
370 ## Rechecking failures. ##
371 ## -------------------- ##
372
373 ## Rerun all tests that experienced an error or an unexpected failure.
374 recheck recheck-html:
375         @ws='[  ]'; \
376         target=`echo $@ | sed 's,^re,,'`; \
377         list=''; $(am__set_TESTS_bases); \
378         for i in $$bases; do \
379 ## Skip tests that haven't been run, but recover gracefully from deleted
380 ## `.trs' files.
381           test -f $$i.trs || test -f $$i.log || continue; \
382 ## FIXME: one fork per test -- this is horrendously inefficient!
383           grep "^$$ws*:recheck:$$ws*no$$ws*$$" $$i.trs \
384             >/dev/null 2>&1 && continue; \
385 ## Be careful to avoid extra whitespace in the definition of $list, since
386 ## its value will be passed to the recursive make invocation below through
387 ## the TEST_LOGS macro, and leading/trailing white space in a make macro
388 ## definition can be problematic.  In this particular case, trailing white
389 ## space was known to cause a segmentation fault on Solaris 10 XPG4 make:
390 ## <http://lists.gnu.org/archive/html/bug-automake/2010-08/msg00004.html>
391           if test -z "$$list"; then list=$$i.log; else list="$$list $$i.log"; fi; \
392         done; \
393         $(MAKE) $(AM_MAKEFLAGS) $$target AM_MAKEFLAGS='$(AM_MAKEFLAGS) TEST_LOGS="'"$$list"'"'
394
395 .PHONY: recheck recheck-html
396 .MAKE: recheck recheck-html
397
398 AM_RECURSIVE_TARGETS += recheck recheck-html
399
400 else !%?PARALLEL_TESTS%
401
402 check-TESTS: $(TESTS)
403         @failed=0; all=0; xfail=0; xpass=0; skip=0; \
404         srcdir=$(srcdir); export srcdir; \
405 ## Make sure Solaris VPATH-expands all members of this list, even
406 ## the first and the last one; thus the spaces around $(TESTS)
407         list=' $(TESTS) '; \
408         $(am__tty_colors); \
409         if test -n "$$list"; then \
410           for tst in $$list; do \
411             if test -f ./$$tst; then dir=./; \
412 ## Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
413 ## why we also try `dir='
414             elif test -f $$tst; then dir=; \
415             else dir="$(srcdir)/"; fi; \
416             if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \
417 ## Success
418               all=`expr $$all + 1`; \
419               case " $(XFAIL_TESTS) " in \
420               *[\ \     ]$$tst[\ \      ]*) \
421                 xpass=`expr $$xpass + 1`; \
422                 failed=`expr $$failed + 1`; \
423                 col=$$red; res=XPASS; \
424               ;; \
425               *) \
426                 col=$$grn; res=PASS; \
427               ;; \
428               esac; \
429             elif test $$? -ne 77; then \
430 ## Failure
431               all=`expr $$all + 1`; \
432               case " $(XFAIL_TESTS) " in \
433               *[\ \     ]$$tst[\ \      ]*) \
434                 xfail=`expr $$xfail + 1`; \
435                 col=$$lgn; res=XFAIL; \
436               ;; \
437               *) \
438                 failed=`expr $$failed + 1`; \
439                 col=$$red; res=FAIL; \
440               ;; \
441               esac; \
442             else \
443 ## Skipped
444               skip=`expr $$skip + 1`; \
445               col=$$blu; res=SKIP; \
446             fi; \
447             echo "$${col}$$res$${std}: $$tst"; \
448           done; \
449 ## Prepare the banner
450           if test "$$all" -eq 1; then \
451             tests="test"; \
452             All=""; \
453           else \
454             tests="tests"; \
455             All="All "; \
456           fi; \
457           if test "$$failed" -eq 0; then \
458             if test "$$xfail" -eq 0; then \
459               banner="$$All$$all $$tests passed"; \
460             else \
461               if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
462               banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
463             fi; \
464           else \
465             if test "$$xpass" -eq 0; then \
466               banner="$$failed of $$all $$tests failed"; \
467             else \
468               if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
469               banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
470             fi; \
471           fi; \
472 ## DASHES should contain the largest line of the banner.
473           dashes="$$banner"; \
474           skipped=""; \
475           if test "$$skip" -ne 0; then \
476             if test "$$skip" -eq 1; then \
477               skipped="($$skip test was not run)"; \
478             else \
479               skipped="($$skip tests were not run)"; \
480             fi; \
481             test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
482               dashes="$$skipped"; \
483           fi; \
484           report=""; \
485           if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
486             report="Please report to $(PACKAGE_BUGREPORT)"; \
487             test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
488               dashes="$$report"; \
489           fi; \
490           dashes=`echo "$$dashes" | sed s/./=/g`; \
491           if test "$$failed" -eq 0; then \
492             col="$$grn"; \
493           else \
494             col="$$red"; \
495           fi; \
496 ## Multi line coloring is problematic with "less -R", so we really need
497 ## to color each line individually.
498           echo "$${col}$$dashes$${std}"; \
499           echo "$${col}$$banner$${std}"; \
500           test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
501           test -z "$$report" || echo "$${col}$$report$${std}"; \
502           echo "$${col}$$dashes$${std}"; \
503           test "$$failed" -eq 0; \
504         else :; fi
505
506 endif !%?PARALLEL_TESTS%