1 ## Vaucanson, a generic library for finite state machines.
2 ## Copyright (C) 2006, 2007 The Vaucanson Group.
4 ## This program is free software; you can redistribute it and/or
5 ## modify it under the terms of the GNU General Public License
6 ## as published by the Free Software Foundation; either version 2
7 ## of the License, or (at your option) any later version.
9 ## The complete GNU General Public Licence Notice can be found as the
10 ## `COPYING' file in the root directory.
12 ## Override the definition from Automake to generate a log file with
13 ## failed tests. It also supports parallel make checks.
15 ## This file provides special support for "unit tests", that is to
16 ## say, tests that (once run) no longer need to be re-compiled and
17 ## re-run at each "make check", unless their sources changed. To
18 ## enable unit-test supports, define LAZY_TEST_SUITE. In such a
19 ## setting, that heavily relies on correct dependencies, its users may
20 ## prefer to define EXTRA_PROGRAMS instead of check_PROGRAMS, because
21 ## it allows intertwined compilation and execution of the tests.
22 ## Sometimes this helps catching errors earlier (you don't have to
23 ## wait for all the tests to be compiled).
25 ## Define TEST_SUITE_LOG to be the name of the global log to create.
26 ## Define TEST_LOGS to the set of logs to include in it. One possibility
27 ## is $(TESTS:.test=.log).
29 ## In addition to the magic "exit 77 means SKIP" feature (which was
30 ## imported from automake), there is a magic "exit 177 means FAIL" feature
31 ## which is useful if you need to issue a hard error no matter whether the
32 ## test is XFAIL or not.
34 # Use a POSIX-compatible shell if available, as this file uses
35 # features of the POSIX shell that are not supported by some standard
36 # shell implementations (e.g., Solaris 10 /bin/sh).
37 SHELL
= $(PREFERABLY_POSIX_SHELL
)
39 # Set this to `false' to disable hard errors.
40 ENABLE_HARD_ERRORS
= :
42 ## We use GNU Make extensions (%-rules) inside GNU_MAKE checks,
43 ## and we override check-TESTS.
44 AUTOMAKE_OPTIONS
= -Wno-portability
-Wno-override
46 # Restructured Text title and section.
47 am__rst_title
= sed
's/.*/ & /;h;s/./=/g;p;x;p;g;p;s/.*//'
48 am__rst_section
= sed
'p;s/./=/g;p;g'
50 # Put stdin (possibly several lines separated by ". ") in a box.
51 am__text_box
= $(AWK
) '{gsub ("\\. ", "\n"); print $$0; }' | \
54 final= final (final ? "\n" : "") " " $$0; \
58 for (i = 0; i < max + 2 ; ++i) \
65 # If stdout is a tty and TERM is smart then use colors. If test -t or
66 # tput are not supported then this fails; a conservative approach. Of
67 # course do not redirect stdout here, just stderr...
74 test "X$$TERM" != Xdumb
&& \
75 test -t
1 2>/dev
/null
&& \
76 tput bold
1 >/dev
/null
2>&1 && \
77 tput setaf
1 >/dev
/null
2>&1 && \
78 tput sgr0
>/dev
/null
2>&1 && \
80 red
=$$(tput setaf
1); \
81 grn
=$$(tput setaf
2); \
82 lgn
=$$(tput bold
)$$(tput setaf
2); \
83 blu
=$$(tput setaf
4); \
87 # Solaris 10 'make', and several other traditional 'make' implementations,
88 # pass "-e" to $(SHELL). This contradicts POSIX. Work around the problem
89 # by disabling -e (using the XSI extension "set +e") if it's set.
90 SH_E_WORKAROUND
= case
$$- in
*e
*) set
+e
;; esac
92 # Emulate dirname with sed.
93 _d_no_slash
= s
,^
[^
/]*$$,.
,
94 _d_strip_trailing
= s
,\
([^
/]\
)//*$$,\
1,
95 _d_abs_trivial
= s
,^
//*[^
/]*$$,/,
96 _d_rm_basename
= s
,\
([^
/]\
)//*[^
/]*$$,\
1,
98 sed
'$(_d_no_slash);$(_d_strip_trailing);$(_d_abs_trivial);$(_d_rm_basename)'
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 $src, and passes TESTS_ENVIRONMENT.
103 # Save and restore TERM around use of TESTS_ENVIRONMENT,
104 # in case that unsets it.
106 $(SH_E_WORKAROUND
); \
107 tst
=`echo "$$src" | sed 's|^.*/||'`; \
109 trap
'st=$$?; rm -f '\''$(abs_builddir)/$@-t'\''; (exit $$st); exit $$st' \
111 $(mkdir_p
) "$$(echo '$@'|$(_dirname))" || exit
; \
112 if
test -f
"./$$src"; then
dir=.
/; \
113 elif
test -f
"$$src"; then
dir=; \
114 else dir="$(srcdir)/"; fi
; \
115 __SAVED_TERM
=$$TERM; \
118 # To be appended to the command running the test. Handles the stdout
119 # and stderr redirection, and catch the exit status.
123 if
test $$estatus -eq
177; then \
124 $(ENABLE_HARD_ERRORS
) || estatus
=1; \
126 TERM
=$$__SAVED_TERM; export TERM
; \
129 for xfail in
: $(XFAIL_TESTS
); do \
131 $$xfail |
*/$$xfail) xfailed
=XFAIL
; break
; \
134 case
$$estatus:$$xfailed in \
135 0:XFAIL
) col
=$$red; res
=XPASS
;; \
136 0:*) col
=$$grn; res
=PASS
;; \
137 77:*) col
=$$blu; res
=SKIP
;; \
138 177:*) col
=$$red; res
=FAIL
;; \
139 *:XFAIL
) col
=$$lgn; res
=XFAIL
;; \
140 *:*) col
=$$red; res
=FAIL
;; \
142 echo
"$${col}$$res$${std}: $@"; \
143 echo
"$$res: $@ (exit: $$estatus)" | \
144 $(am__rst_section
) >$@
; \
148 SUFFIXES
= .html .log
150 # From a test (with no extension) to a log file.
153 @src
='$<'; $(am__check_pre
) "$$dir$$src" $(am__check_post
)
155 # With POSIX 'make', inference rules cannot have FOO.log depend on FOO.
156 # Work around the problem by calculating the dependency dynamically, and
157 # then invoking a submake with the calculated dependency.
159 DEPENDENCY
= CHECK-FORCE
160 $(TEST_LOGS
): $(DEPENDENCY
)
161 @if
test '$(DEPENDENCY)' = CHECK-FORCE
; then \
163 exec
$(MAKE
) $(AM_MAKEFLAGS
) DEPENDENCY
='$(srcdir)'/$${dst
%.log
} $@
;\
165 src
='$(DEPENDENCY)'; \
166 $(am__check_pre
) "$$dir$$src" $(am__check_post
); \
170 #TEST_LOGS = $(TESTS:.test=.log)
171 TEST_SUITE_LOG
= test-suite.log
173 $(TEST_SUITE_LOG
): $(TEST_LOGS
)
174 @
$(SH_E_WORKAROUND
); \
175 results
=$$(for f in
$(TEST_LOGS
); do sed
1q
$$f; done
); \
176 all=$$(echo
"$$results" | wc
-l | sed
-e
's/^[ \t]*//'); \
177 fail
=$$(echo
"$$results" | grep
-c
'^FAIL'); \
178 pass
=$$(echo
"$$results" | grep
-c
'^PASS'); \
179 skip
=$$(echo
"$$results" | grep
-c
'^SKIP'); \
180 xfail
=$$(echo
"$$results" | grep
-c
'^XFAIL'); \
181 xpass
=$$(echo
"$$results" | grep
-c
'^XPASS'); \
182 failures
=$$(expr
$$fail + $$xpass); \
183 case fail
=$$fail:xpass
=$$xpass:xfail
=$$xfail in \
184 fail
=0:xpass
=0:xfail
=0) \
185 msg
="All $$all tests passed. "; \
187 fail
=0:xpass
=0:xfail
=*) \
188 msg
="All $$all tests behaved as expected"; \
189 msg
="$$msg ($$xfail expected failures). "; \
191 fail
=*:xpass
=0:xfail
=*) \
192 msg
="$$fail of $$all tests failed. "; \
194 fail
=*:xpass
=*:xfail
=*) \
195 msg
="$$failures of $$all tests did not behave as expected"; \
196 msg
="$$msg ($$xpass unexpected passes). "; \
199 echo
>&2 "incorrect case"; exit
4;; \
201 if
test "$$skip" -ne
0; then \
202 msg
="$$msg($$skip tests were not run). "; \
204 if
test "$$failures" -ne
0; then \
206 echo
"$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \
210 echo
".. contents:: :depth: 2"; \
212 for f in
$(TEST_LOGS
); \
214 case
$$(sed
1q
$$f) in \
215 SKIP
:*|PASS
:*|XFAIL
:*);; \
219 } >$(TEST_SUITE_LOG
).tmp
; \
220 mv
$(TEST_SUITE_LOG
).tmp
$(TEST_SUITE_LOG
); \
221 msg
="$${msg}See $(subdir)/$(TEST_SUITE_LOG). "; \
222 if
test -n
"$(PACKAGE_BUGREPORT)"; then \
223 msg
="$${msg}Please report it to $(PACKAGE_BUGREPORT). "; \
227 if
$$exit; then echo
$$grn; else echo
$$red; fi
; \
228 echo
"$$msg" |
$(am__text_box
); \
230 test x
"$$VERBOSE" = x ||
$$exit || cat
$(TEST_SUITE_LOG
); \
233 # if test x"$$VERBOSE" != x && ! $exit; then
237 @if
test -z
'$(LAZY_TEST_SUITE)'; then \
238 rm -f
$(TEST_SUITE_LOG
) $(TEST_LOGS
); \
240 @
$(MAKE
) $(TEST_SUITE_LOG
)
247 TEST_SUITE_HTML
= $(TEST_SUITE_LOG
:.log
=.html
)
250 @for r2h in
$(RST2HTML
) $$RST2HTML rst2html rst2html.py
; \
252 if
($$r2h --version
) >/dev
/null
2>&1; then \
256 if
test -z
"$$R2H"; then \
257 echo
>&2 "cannot find rst2html, cannot create $@"; \
263 # Be sure to run check-TESTS first, and then to convert the result.
264 # Beware of concurrent executions. And expect check-TESTS to fail.
266 @if
$(MAKE
) $(AM_MAKEFLAGS
) check-TESTS
; then
:; else \
268 $(MAKE
) $(AM_MAKEFLAGS
) $(TEST_SUITE_HTML
); \
280 rm -f
$(CHECK_CLEANFILES
) $(TEST_SUITE_LOG
) $(TEST_SUITE_HTML
) $(TEST_LOGS
)
282 clean-local
: check-clean