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