Add comment to check-TESTS rule working around make 3.80 bug.
[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 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 am__text_box = $(AWK) '{                                \
79   n = split($$0, lines, "\\.  "); max = 0;              \
80   for (i = 1; i <= n; ++i)                              \
81     if (max < length(lines[i]))                         \
82       max = length(lines[i]);                           \
83   for (i = 0; i < max; ++i) line = line "=";            \
84   print line;                                           \
85   for (i = 1; i <= n; ++i) if (lines[i]) print lines[i];\
86   print line;                                           \
87 }'
88
89 # Solaris 10 'make', and several other traditional 'make' implementations,
90 # pass "-e" to $(SHELL), and POSIX 2008 even requires this.  Work around it
91 # by disabling -e (using the XSI extension "set +e") if it's set.
92 am__sh_e_setup = case $$- in *e*) set +e;; esac
93
94 # To be inserted before the command running the test.  Creates the
95 # directory for the log if needed.  Stores in $dir the directory
96 # containing $f, in $tst the test, in $log the log, and passes
97 # TESTS_ENVIRONMENT.  Save and restore TERM around use of
98 # TESTS_ENVIRONMENT, in case that unsets it.
99 am__check_pre =                                         \
100 $(am__sh_e_setup);                                      \
101 $(am__vpath_adj_setup) $(am__vpath_adj)                 \
102 srcdir=$(srcdir); export srcdir;                        \
103 rm -f $@-t;                                             \
104 am__trap='rm -f '\''$(abs_builddir)/$@-t'\''; (exit $$st); exit $$st'; \
105 trap "st=129; $$am__trap" 1; trap "st=130; $$am__trap" 2;       \
106 trap "st=141; $$am__trap" 13; trap "st=143; $$am__trap" 15; \
107 am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;            \
108 test "x$$am__odir" = x. || $(MKDIR_P) "$$am__odir" || exit $$?; \
109 if test -f "./$$f"; then dir=./;                        \
110 elif test -f "$$f"; then dir=;                          \
111 else dir="$(srcdir)/"; fi;                              \
112 tst=$$dir$$f; log='$@'; __SAVED_TERM=$$TERM;            \
113 $(TESTS_ENVIRONMENT)
114
115 # To be appended to the command running the test.  Handle the stdout
116 # and stderr redirection, and catch the exit status.
117 am__check_post =                                        \
118 >$@-t 2>&1;                                             \
119 estatus=$$?;                                            \
120 if test -n '$(DISABLE_HARD_ERRORS)'                     \
121    && test $$estatus -eq 99; then                       \
122   estatus=1;                                            \
123 fi;                                                     \
124 TERM=$$__SAVED_TERM; export TERM;                       \
125 $(am__tty_colors);                                      \
126 xfailed=PASS;                                           \
127 case " $(XFAIL_TESTS) " in                              \
128   *[\ \ ]$$f[\ \        ]* | *[\ \      ]$$dir$$f[\ \   ]*) \
129     xfailed=XFAIL;;                                     \
130 esac;                                                   \
131 case $$estatus.$$xfailed in                             \
132     0.XFAIL) col=$$red; res=XPASS;;                     \
133     0.*)     col=$$grn; res=PASS ;;                     \
134     77.*)    col=$$blu; res=SKIP ;;                     \
135     99.*)    col=$$red; res=FAIL ;;                     \
136     *.XFAIL) col=$$lgn; res=XFAIL;;                     \
137     *.*)     col=$$red; res=FAIL ;;                     \
138 esac;                                                   \
139 echo "$${col}$$res$${std}: $$f";                        \
140 echo "$$res: $$f (exit: $$estatus)" |                   \
141   $(am__rst_section) >$@;                               \
142 cat $@-t >>$@;                                          \
143 rm -f $@-t
144
145 $(TEST_SUITE_LOG): $(TEST_LOGS)
146         @$(am__sh_e_setup);                                             \
147         list='$(TEST_LOGS)';                                            \
148         results=`for f in $$list; do                                    \
149                    test -r $$f && read line < $$f && echo "$$line"      \
150                      || echo FAIL;                                      \
151                  done`;                                                 \
152         all=`echo "$$results" | sed '/^$$/d' | wc -l | sed -e 's/^[      ]*//'`; \
153         fail=`echo "$$results" | grep -c '^FAIL'`;                      \
154         pass=`echo "$$results" | grep -c '^PASS'`;                      \
155         skip=`echo "$$results" | grep -c '^SKIP'`;                      \
156         xfail=`echo "$$results" | grep -c '^XFAIL'`;                    \
157         xpass=`echo "$$results" | grep -c '^XPASS'`;                    \
158         failures=`expr $$fail + $$xpass`;                               \
159         all=`expr $$all - $$skip`;                                      \
160         if test "$$all" -eq 1; then tests=test; All=;                   \
161         else tests=tests; All="All "; fi;                               \
162         case fail=$$fail:xpass=$$xpass:xfail=$$xfail in                 \
163           fail=0:xpass=0:xfail=0)                                       \
164             msg="$$All$$all $$tests passed.  ";                         \
165             exit=true;;                                                 \
166           fail=0:xpass=0:xfail=*)                                       \
167             msg="$$All$$all $$tests behaved as expected";               \
168             if test "$$xfail" -eq 1; then xfailures=failure;            \
169             else xfailures=failures; fi;                                \
170             msg="$$msg ($$xfail expected $$xfailures).  ";              \
171             exit=true;;                                                 \
172           fail=*:xpass=0:xfail=*)                                       \
173             msg="$$fail of $$all $$tests failed.  ";                    \
174             exit=false;;                                                \
175           fail=*:xpass=*:xfail=*)                                       \
176             msg="$$failures of $$all $$tests did not behave as expected"; \
177             if test "$$xpass" -eq 1; then xpasses=pass;                 \
178             else xpasses=passes; fi;                                    \
179             msg="$$msg ($$xpass unexpected $$xpasses).  ";              \
180             exit=false;;                                                \
181           *)                                                            \
182             echo >&2 "incorrect case"; exit 4;;                         \
183         esac;                                                           \
184         if test "$$skip" -ne 0; then                                    \
185           if test "$$skip" -eq 1; then                                  \
186             msg="$$msg($$skip test was not run).  ";                    \
187           else                                                          \
188             msg="$$msg($$skip tests were not run).  ";                  \
189           fi;                                                           \
190         fi;                                                             \
191         {                                                               \
192           echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |       \
193             $(am__rst_title);                                           \
194           echo "$$msg";                                                 \
195           echo;                                                         \
196           echo ".. contents:: :depth: 2";                               \
197           echo;                                                         \
198           for f in $$list; do                                           \
199             test -r $$f && read line < $$f || line=;                    \
200             case $$line in                                              \
201               PASS:*|XFAIL:*);;                                         \
202               *) echo; cat $$f;;                                        \
203             esac;                                                       \
204           done;                                                         \
205         } >$(TEST_SUITE_LOG).tmp;                                       \
206         mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);                     \
207         if test "$$failures" -ne 0; then                                \
208           msg="$${msg}See $(subdir)/$(TEST_SUITE_LOG).  ";              \
209           if test -n "$(PACKAGE_BUGREPORT)"; then                       \
210             msg="$${msg}Please report to $(PACKAGE_BUGREPORT).  ";      \
211           fi;                                                           \
212         fi;                                                             \
213         test x"$$VERBOSE" = x || $$exit || cat $(TEST_SUITE_LOG);       \
214         $(am__tty_colors);                                              \
215         if $$exit; then                                                 \
216           echo $(ECHO_N) "$$grn$(ECHO_C)";                              \
217          else                                                           \
218           echo $(ECHO_N) "$$red$(ECHO_C)";                              \
219         fi;                                                             \
220         echo "$$msg" | $(am__text_box);                                 \
221         echo $(ECHO_N) "$$std$(ECHO_C)";                                \
222         $$exit
223
224 RECHECK_LOGS = $(TEST_LOGS)
225
226 # Run all the tests.
227 check-TESTS:
228 ## Expand $(RECHECK_LOGS) only once, to avoid exceeding line length limits.
229         @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list
230 ## We always have to remove TEST_SUITE_LOG, to ensure its rule is run
231 ## in any case even in lazy mode: otherwise, if no test needs rerunning,
232 ## or a prior run plus reruns all happen within the same timestamp
233 ## (can happen with a prior `make TESTS=<subset>'),
234 ## then we get no log output.
235 ## OTOH, this means that, in the rule for `$(TEST_SUITE_LOG)', we
236 ## cannot use `$?' to compute the set of lazily rerun tests, lest
237 ## we rely on .PHONY to work portably.
238 ##
239 ## Trailing whitespace in `TESTS = foo.test $(empty)' causes GNU make
240 ## 3.80 to erroneously expand $(TESTS_LOGS) to `foo.log .log'.
241 ## Work around this bug.
242         @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
243         @list='$(TEST_LOGS)';                                           \
244         list=`for f in $$list; do                                       \
245           test .log = $$f || echo $$f;                                  \
246         done | tr '\012\015' '  '`;                                     \
247         $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$list"
248
249 AM_RECURSIVE_TARGETS += check
250
251 ## -------------- ##
252 ## Produce HTML.  ##
253 ## -------------- ##
254
255 .log.html:
256         @list='$(RST2HTML) $$RST2HTML rst2html rst2html.py';            \
257         for r2h in $$list; do                                           \
258           if ($$r2h --version) >/dev/null 2>&1; then                    \
259             R2H=$$r2h;                                                  \
260           fi;                                                           \
261         done;                                                           \
262         if test -z "$$R2H"; then                                        \
263           echo >&2 "cannot find rst2html, cannot create $@";            \
264           exit 2;                                                       \
265         fi;                                                             \
266         $$R2H $< >$@.tmp
267         @mv $@.tmp $@
268
269 # Be sure to run check first, and then to convert the result.
270 # Beware of concurrent executions.  Run "check" not "check-TESTS", as
271 # check-SCRIPTS and other dependencies are rebuilt by the former only.
272 # And expect check to fail.
273 check-html:
274         @if $(MAKE) $(AM_MAKEFLAGS) check; then                 \
275           rv=0; else rv=$$?;                                    \
276         fi;                                                     \
277         $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_HTML) || exit 4;   \
278         exit $$rv
279
280 .PHONY: check-html
281 .MAKE: check-html
282
283 AM_RECURSIVE_TARGETS += check-html
284
285 ## -------------------- ##
286 ## Rechecking failures. ##
287 ## -------------------- ##
288
289 ## Rerun all FAILed or XPASSed tests.
290 recheck recheck-html:
291         @target=`echo $@ | sed 's,^re,,'`;                              \
292         list='$(TEST_LOGS)';                                            \
293         list=`for f in $$list; do                                       \
294                 test -f $$f || continue;                                \
295                 if test -r $$f && read line < $$f; then                 \
296                   case $$line in FAIL*|XPASS*) echo $$f;; esac;         \
297                 else echo $$f; fi;                                      \
298               done | tr '\012\015' '  '`;                               \
299 ## This apparently useless munging helps to avoid a nasty bug (a
300 ## segmentation fault!) on Solaris XPG4 make.
301         list=`echo "$$list" | sed 's/ *$$//'`;                          \
302         $(MAKE) $(AM_MAKEFLAGS) $$target AM_MAKEFLAGS='$(AM_MAKEFLAGS) TEST_LOGS="'"$$list"'"'
303
304 .PHONY: recheck recheck-html
305 .MAKE: recheck recheck-html
306
307 AM_RECURSIVE_TARGETS += recheck recheck-html
308
309 else !%?PARALLEL_TESTS%
310
311 check-TESTS: $(TESTS)
312         @failed=0; all=0; xfail=0; xpass=0; skip=0; \
313         srcdir=$(srcdir); export srcdir; \
314 ## Make sure Solaris VPATH-expands all members of this list, even
315 ## the first and the last one; thus the spaces around $(TESTS)
316         list=' $(TESTS) '; \
317         $(am__tty_colors); \
318         if test -n "$$list"; then \
319           for tst in $$list; do \
320             if test -f ./$$tst; then dir=./; \
321 ## Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
322 ## why we also try `dir='
323             elif test -f $$tst; then dir=; \
324             else dir="$(srcdir)/"; fi; \
325             if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
326 ## Success
327               all=`expr $$all + 1`; \
328               case " $(XFAIL_TESTS) " in \
329               *[\ \     ]$$tst[\ \      ]*) \
330                 xpass=`expr $$xpass + 1`; \
331                 failed=`expr $$failed + 1`; \
332                 col=$$red; res=XPASS; \
333               ;; \
334               *) \
335                 col=$$grn; res=PASS; \
336               ;; \
337               esac; \
338             elif test $$? -ne 77; then \
339 ## Failure
340               all=`expr $$all + 1`; \
341               case " $(XFAIL_TESTS) " in \
342               *[\ \     ]$$tst[\ \      ]*) \
343                 xfail=`expr $$xfail + 1`; \
344                 col=$$lgn; res=XFAIL; \
345               ;; \
346               *) \
347                 failed=`expr $$failed + 1`; \
348                 col=$$red; res=FAIL; \
349               ;; \
350               esac; \
351             else \
352 ## Skipped
353               skip=`expr $$skip + 1`; \
354               col=$$blu; res=SKIP; \
355             fi; \
356             echo "$${col}$$res$${std}: $$tst"; \
357           done; \
358 ## Prepare the banner
359           if test "$$all" -eq 1; then \
360             tests="test"; \
361             All=""; \
362           else \
363             tests="tests"; \
364             All="All "; \
365           fi; \
366           if test "$$failed" -eq 0; then \
367             if test "$$xfail" -eq 0; then \
368               banner="$$All$$all $$tests passed"; \
369             else \
370               if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
371               banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
372             fi; \
373           else \
374             if test "$$xpass" -eq 0; then \
375               banner="$$failed of $$all $$tests failed"; \
376             else \
377               if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
378               banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
379             fi; \
380           fi; \
381 ## DASHES should contain the largest line of the banner.
382           dashes="$$banner"; \
383           skipped=""; \
384           if test "$$skip" -ne 0; then \
385             if test "$$skip" -eq 1; then \
386               skipped="($$skip test was not run)"; \
387             else \
388               skipped="($$skip tests were not run)"; \
389             fi; \
390             test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
391               dashes="$$skipped"; \
392           fi; \
393           report=""; \
394           if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
395             report="Please report to $(PACKAGE_BUGREPORT)"; \
396             test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
397               dashes="$$report"; \
398           fi; \
399           dashes=`echo "$$dashes" | sed s/./=/g`; \
400           if test "$$failed" -eq 0; then \
401             echo "$$grn$$dashes"; \
402           else \
403             echo "$$red$$dashes"; \
404           fi; \
405           echo "$$banner"; \
406           test -z "$$skipped" || echo "$$skipped"; \
407           test -z "$$report" || echo "$$report"; \
408           echo "$$dashes$$std"; \
409           test "$$failed" -eq 0; \
410         else :; fi
411
412 endif !%?PARALLEL_TESTS%