Merge branch 'maint' into yacc-work
[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, 2012
3 ## Free 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 if %?COLOR%
19 # If stdout is a non-dumb tty, use colors.  If test -t is not supported,
20 # then this fails; a conservative approach.  Of course do not redirect
21 # stdout here, just stderr.
22 am__tty_colors = \
23 red=; grn=; lgn=; blu=; std=; \
24 test "X$(AM_COLOR_TESTS)" != Xno \
25 && test "X$$TERM" != Xdumb \
26 && { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
27 && { \
28   red='\e[0;31m'; \
29   grn='\e[0;32m'; \
30   lgn='\e[1;32m'; \
31   blu='\e[1;34m'; \
32   std='\e[m'; \
33 }
34 else !%?COLOR%
35 am__tty_colors = \
36 red=; grn=; lgn=; blu=; std=
37 endif !%?COLOR%
38
39 .PHONY: check-TESTS
40
41 if %?PARALLEL_TESTS%
42
43 include inst-vars.am
44
45 ## New parallel test driver.
46 ##
47 ## This code is adapted from check.mk which was originally
48 ## written at EPITA/LRDE, further developed at Gostai, then made
49 ## its way from GNU coreutils to end up, largely rewritten, in
50 ## Automake.
51 ##
52 ## It provides special support for "unit tests", that is to say,
53 ## tests that (once run) no longer need to be re-compiled and
54 ## re-run at each "make check", unless their sources changed.  To
55 ## enable unit-test supports, set RECHECK_LOGS to empty.  In such a
56 ## setting, that heavily relies on correct dependencies, its users may
57 ## prefer to define EXTRA_PROGRAMS instead of check_PROGRAMS, because
58 ## it allows intertwined compilation and execution of the tests.
59 ## Sometimes this helps catching errors earlier (you don't have to
60 ## wait for all the tests to be compiled).
61 ##
62 ## Define TEST_SUITE_LOG to be the name of the global log to create.
63 ## Define TEST_LOGS to the set of logs to include in it.  It defaults
64 ## to $(TESTS), with `.test' and `@EXEEXT@' removed, and `'.log'
65 ## appended.
66 ##
67 ## In addition to the magic "exit 77 means SKIP" feature (which was
68 ## imported from automake), there is a magic "exit 99 means FAIL" feature
69 ## which is useful if you need to issue a hard error no matter whether the
70 ## test is XFAIL or not.  You can disable this feature by setting the
71 ## variable DISABLE_HARD_ERRORS to a nonempty value.
72
73 # Restructured Text title and section.
74 am__rst_title   = sed 's/.*/   &   /;h;s/./=/g;p;x;p;g;p;s/.*//'
75 am__rst_section = sed 'p;s/./=/g;p;g'
76
77 # Put stdin (possibly several lines separated by ".  ") in a box.
78 # Prefix each line by 'col' and terminate each with 'std', for coloring.
79 # Multi line coloring is problematic with "less -R", so we really need
80 # to color each line individually.
81 am__text_box = $(AWK) '{                        \
82   n = split($$0, lines, "\\.  "); max = 0;      \
83   for (i = 1; i <= n; ++i)                      \
84     if (max < length(lines[i]))                 \
85       max = length(lines[i]);                   \
86   for (i = 0; i < max; ++i)                     \
87     line = line "=";                            \
88   print col line std;                           \
89   for (i = 1; i <= n; ++i)                      \
90     if (lines[i])                               \
91       print col lines[i] std;                   \
92   print col line std;                           \
93 }'
94
95 # Solaris 10 'make', and several other traditional 'make' implementations,
96 # pass "-e" to $(SHELL), and POSIX 2008 even requires this.  Work around it
97 # by disabling -e (using the XSI extension "set +e") if it's set.
98 am__sh_e_setup = case $$- in *e*) set +e;; esac
99
100 # To be inserted before the command running the test.  Creates the
101 # directory for the log if needed.  Stores in $dir the directory
102 # containing $f, in $tst the test, in $log the log, and passes
103 # TESTS_ENVIRONMENT.  Save and restore TERM around use of
104 # TESTS_ENVIRONMENT, in case that unsets it.
105 am__check_pre =                                         \
106 $(am__sh_e_setup);                                      \
107 $(am__vpath_adj_setup) $(am__vpath_adj)                 \
108 srcdir=$(srcdir); export srcdir;                        \
109 rm -f $@-t;                                             \
110 am__trap='rm -f '\''$(abs_builddir)/$@-t'\''; (exit $$st); exit $$st'; \
111 trap "st=129; $$am__trap" 1; trap "st=130; $$am__trap" 2;       \
112 trap "st=141; $$am__trap" 13; trap "st=143; $$am__trap" 15; \
113 am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;            \
114 test "x$$am__odir" = x. || $(MKDIR_P) "$$am__odir" || exit $$?; \
115 if test -f "./$$f"; then dir=./;                        \
116 elif test -f "$$f"; then dir=;                          \
117 else dir="$(srcdir)/"; fi;                              \
118 tst=$$dir$$f; log='$@'; __SAVED_TERM=$$TERM;            \
119 $(TESTS_ENVIRONMENT)
120
121 # To be appended to the command running the test.  Handle the stdout
122 # and stderr redirection, and catch the exit status.
123 am__check_post =                                        \
124 >$@-t 2>&1;                                             \
125 estatus=$$?;                                            \
126 if test -n '$(DISABLE_HARD_ERRORS)'                     \
127    && test $$estatus -eq 99; then                       \
128   estatus=1;                                            \
129 fi;                                                     \
130 TERM=$$__SAVED_TERM; export TERM;                       \
131 $(am__tty_colors);                                      \
132 xfailed=PASS;                                           \
133 case " $(XFAIL_TESTS) " in                              \
134   *[\ \ ]$$f[\ \        ]* | *[\ \      ]$$dir$$f[\ \   ]*) \
135     xfailed=XFAIL;;                                     \
136 esac;                                                   \
137 case $$estatus.$$xfailed in                             \
138     0.XFAIL) col=$$red; res=XPASS;;                     \
139     0.*)     col=$$grn; res=PASS ;;                     \
140     77.*)    col=$$blu; res=SKIP ;;                     \
141     99.*)    col=$$red; res=FAIL ;;                     \
142     *.XFAIL) col=$$lgn; res=XFAIL;;                     \
143     *.*)     col=$$red; res=FAIL ;;                     \
144 esac;                                                   \
145 echo "$${col}$$res$${std}: $$f";                        \
146 echo "$$res: $$f (exit: $$estatus)" |                   \
147   $(am__rst_section) >$@;                               \
148 cat $@-t >>$@;                                          \
149 rm -f $@-t
150
151 $(TEST_SUITE_LOG): $(TEST_LOGS)
152         @$(am__sh_e_setup);                                             \
153         list='$(TEST_LOGS)';                                            \
154         results=`for f in $$list; do                                    \
155                    test -r $$f && read line < $$f && echo "$$line"      \
156                      || echo FAIL;                                      \
157                  done`;                                                 \
158         all=`echo "$$results" | sed '/^$$/d' | wc -l | sed -e 's/^[      ]*//'`; \
159         fail=`echo "$$results" | grep -c '^FAIL'`;                      \
160         pass=`echo "$$results" | grep -c '^PASS'`;                      \
161         skip=`echo "$$results" | grep -c '^SKIP'`;                      \
162         xfail=`echo "$$results" | grep -c '^XFAIL'`;                    \
163         xpass=`echo "$$results" | grep -c '^XPASS'`;                    \
164         failures=`expr $$fail + $$xpass`;                               \
165         all=`expr $$all - $$skip`;                                      \
166         if test "$$all" -eq 1; then tests=test; All=;                   \
167         else tests=tests; All="All "; fi;                               \
168         case fail=$$fail:xpass=$$xpass:xfail=$$xfail in                 \
169           fail=0:xpass=0:xfail=0)                                       \
170             msg="$$All$$all $$tests passed.  ";                         \
171             exit=true;;                                                 \
172           fail=0:xpass=0:xfail=*)                                       \
173             msg="$$All$$all $$tests behaved as expected";               \
174             if test "$$xfail" -eq 1; then xfailures=failure;            \
175             else xfailures=failures; fi;                                \
176             msg="$$msg ($$xfail expected $$xfailures).  ";              \
177             exit=true;;                                                 \
178           fail=*:xpass=0:xfail=*)                                       \
179             msg="$$fail of $$all $$tests failed.  ";                    \
180             exit=false;;                                                \
181           fail=*:xpass=*:xfail=*)                                       \
182             msg="$$failures of $$all $$tests did not behave as expected"; \
183             if test "$$xpass" -eq 1; then xpasses=pass;                 \
184             else xpasses=passes; fi;                                    \
185             msg="$$msg ($$xpass unexpected $$xpasses).  ";              \
186             exit=false;;                                                \
187           *)                                                            \
188             echo >&2 "incorrect case"; exit 4;;                         \
189         esac;                                                           \
190         if test "$$skip" -ne 0; then                                    \
191           if test "$$skip" -eq 1; then                                  \
192             msg="$$msg($$skip test was not run).  ";                    \
193           else                                                          \
194             msg="$$msg($$skip tests were not run).  ";                  \
195           fi;                                                           \
196         fi;                                                             \
197         {                                                               \
198           echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |       \
199             $(am__rst_title);                                           \
200           echo "$$msg";                                                 \
201           echo;                                                         \
202           echo ".. contents:: :depth: 2";                               \
203           echo;                                                         \
204           for f in $$list; do                                           \
205             test -r $$f && read line < $$f || line=;                    \
206             case $$line in                                              \
207               PASS:*|XFAIL:*);;                                         \
208               *) echo; cat $$f;;                                        \
209             esac;                                                       \
210           done;                                                         \
211         } >$(TEST_SUITE_LOG).tmp;                                       \
212         mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);                     \
213         if test "$$failures" -ne 0; then                                \
214           msg="$${msg}See $(subdir)/$(TEST_SUITE_LOG).  ";              \
215           if test -n "$(PACKAGE_BUGREPORT)"; then                       \
216             msg="$${msg}Please report to $(PACKAGE_BUGREPORT).  ";      \
217           fi;                                                           \
218         fi;                                                             \
219         test x"$$VERBOSE" = x || $$exit || cat $(TEST_SUITE_LOG);       \
220         $(am__tty_colors);                                              \
221         if $$exit; then                                                 \
222           col="$$grn";                                                  \
223          else                                                           \
224           col="$$red";                                                  \
225         fi;                                                             \
226         echo "$$msg" | $(am__text_box) "col=$$col" "std=$$std";         \
227 ## The use of "exit 1" below is required to work around a FreeBSD make bug
228 ## (present only when running in concurrent mode).  See automake bug#9245:
229 ##  <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9245>
230 ## and FreeBSD PR bin/159730:
231 ##  <http://www.freebsd.org/cgi/query-pr.cgi?pr=159730>.
232         $$exit || exit 1
233
234 RECHECK_LOGS = $(TEST_LOGS)
235
236 check-TESTS recheck:
237 ## If we are running "make recheck", it's not the user which can decide
238 ## which tests to consider for re-execution, so we must ignore the value
239 ## of $(RECHECK_LOGS).
240         @if test $@ != recheck; then \
241 ## Expand $(RECHECK_LOGS) only once, to avoid exceeding line length limits.
242            list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list; \
243          fi
244 ## We always have to remove TEST_SUITE_LOG, to ensure its rule is run
245 ## in any case even in lazy mode: otherwise, if no test needs rerunning,
246 ## or a prior run plus reruns all happen within the same timestamp (can
247 ## happen with a prior `make TESTS=<subset>'), then we get no log output.
248 ## OTOH, this means that, in the rule for `$(TEST_SUITE_LOG)', we
249 ## cannot use `$?' to compute the set of lazily rerun tests, lest
250 ## we rely on .PHONY to work portably.
251         @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
252         @list='' list2='$(TEST_LOGS)'; for f in $$list2; do \
253 ## Trailing whitespace in `TESTS = foo.test $(empty)' causes GNU make
254 ## 3.80 to erroneously expand $(TESTS_LOGS) to `foo.log .log'.
255 ## Work around this bug.
256           test .log = $$f && continue; \
257 ## If running a "make recheck", we must only consider tests that had
258 ## an unexpected outcome (FAIL or XPASS) in the earlier run.
259           if test $@ = recheck; then \
260             test -f $$f || continue; \
261             if test -r $$f && read line < $$f; then \
262               case $$line in FAIL*|XPASS*) : ;; *) continue;; esac; \
263             fi; \
264           fi; \
265 ## Be careful to avoid extra whitespace in the definition of $list, since
266 ## its value will be passed to the recursive make invocation below through
267 ## the TEST_LOGS macro, and leading/trailing white space in a make macro
268 ## definition can be problematic.  In this particular case, trailing white
269 ## space was known to cause a segmentation fault on Solaris 10 XPG4 make:
270 ## <http://lists.gnu.org/archive/html/bug-automake/2010-08/msg00004.html>
271           if test -z "$$list"; then list=$$f; else list="$$list $$f"; fi; \
272         done; \
273 ## Under "make recheck", remove the logs of the files to recheck, so that
274 ## those will be rerun by the "make test-suite.log" recursive invocation
275 ## below.  But avoid extra files removal when running under "make -n".
276         if test $@ = recheck && test -n "$$list"; then \
277           $(am__make_dryrun) || rm -f $$list || exit 1; \
278         fi; \
279         $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$list"
280
281 ## Recheck must depend on $(check_SCRIPTS), $(check_PROGRAMS), etc.
282 recheck: %CHECK_DEPS%
283
284 AM_RECURSIVE_TARGETS += check recheck
285
286 .PHONY: recheck
287
288 ## ----------------------------------------------- ##
289 ## Produce HTML.  To be removed in automake 1.12.  ##
290 ## ----------------------------------------------- ##
291
292 include check-html.am
293
294 else !%?PARALLEL_TESTS%
295
296 check-TESTS: $(TESTS)
297         @failed=0; all=0; xfail=0; xpass=0; skip=0; \
298         srcdir=$(srcdir); export srcdir; \
299 ## Make sure Solaris VPATH-expands all members of this list, even
300 ## the first and the last one; thus the spaces around $(TESTS)
301         list=' $(TESTS) '; \
302         $(am__tty_colors); \
303         if test -n "$$list"; then \
304           for tst in $$list; do \
305             if test -f ./$$tst; then dir=./; \
306 ## Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
307 ## why we also try `dir='
308             elif test -f $$tst; then dir=; \
309             else dir="$(srcdir)/"; fi; \
310             if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
311 ## Success
312               all=`expr $$all + 1`; \
313               case " $(XFAIL_TESTS) " in \
314               *[\ \     ]$$tst[\ \      ]*) \
315                 xpass=`expr $$xpass + 1`; \
316                 failed=`expr $$failed + 1`; \
317                 col=$$red; res=XPASS; \
318               ;; \
319               *) \
320                 col=$$grn; res=PASS; \
321               ;; \
322               esac; \
323             elif test $$? -ne 77; then \
324 ## Failure
325               all=`expr $$all + 1`; \
326               case " $(XFAIL_TESTS) " in \
327               *[\ \     ]$$tst[\ \      ]*) \
328                 xfail=`expr $$xfail + 1`; \
329                 col=$$lgn; res=XFAIL; \
330               ;; \
331               *) \
332                 failed=`expr $$failed + 1`; \
333                 col=$$red; res=FAIL; \
334               ;; \
335               esac; \
336             else \
337 ## Skipped
338               skip=`expr $$skip + 1`; \
339               col=$$blu; res=SKIP; \
340             fi; \
341             echo "$${col}$$res$${std}: $$tst"; \
342           done; \
343 ## Prepare the banner
344           if test "$$all" -eq 1; then \
345             tests="test"; \
346             All=""; \
347           else \
348             tests="tests"; \
349             All="All "; \
350           fi; \
351           if test "$$failed" -eq 0; then \
352             if test "$$xfail" -eq 0; then \
353               banner="$$All$$all $$tests passed"; \
354             else \
355               if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
356               banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
357             fi; \
358           else \
359             if test "$$xpass" -eq 0; then \
360               banner="$$failed of $$all $$tests failed"; \
361             else \
362               if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
363               banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
364             fi; \
365           fi; \
366 ## DASHES should contain the largest line of the banner.
367           dashes="$$banner"; \
368           skipped=""; \
369           if test "$$skip" -ne 0; then \
370             if test "$$skip" -eq 1; then \
371               skipped="($$skip test was not run)"; \
372             else \
373               skipped="($$skip tests were not run)"; \
374             fi; \
375             test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
376               dashes="$$skipped"; \
377           fi; \
378           report=""; \
379           if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
380             report="Please report to $(PACKAGE_BUGREPORT)"; \
381             test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
382               dashes="$$report"; \
383           fi; \
384           dashes=`echo "$$dashes" | sed s/./=/g`; \
385           if test "$$failed" -eq 0; then \
386             col="$$grn"; \
387           else \
388             col="$$red"; \
389           fi; \
390 ## Multi line coloring is problematic with "less -R", so we really need
391 ## to color each line individually.
392           echo "$${col}$$dashes$${std}"; \
393           echo "$${col}$$banner$${std}"; \
394           test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
395           test -z "$$report" || echo "$${col}$$report$${std}"; \
396           echo "$${col}$$dashes$${std}"; \
397           test "$$failed" -eq 0; \
398         else :; fi
399
400 endif !%?PARALLEL_TESTS%