convert the rest to use proper_name -- manually
[coreutils.git] / build-aux / check.mk
blob165ea366bda5736d2454d38d06f3915aa56fee05
1 ## Vaucanson, a generic library for finite state machines.
2 ## Copyright (C) 2006, 2007 The Vaucanson Group.
3 ##
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.
8 ##
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; }' | \
52 $(AWK) ' \
53 max < length($$0) { \
54 final= final (final ? "\n" : "") " " $$0; \
55 max = length($$0); \
56 } \
57 END { \
58 for (i = 0; i < max + 2 ; ++i) \
59 line = line "="; \
60 print line; \
61 print final; \
62 print line; \
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...
68 am__tty_colors = \
69 red=; \
70 grn=; \
71 lgn=; \
72 blu=; \
73 std=; \
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 && \
79 { \
80 red=$$(tput setaf 1); \
81 grn=$$(tput setaf 2); \
82 lgn=$$(tput bold)$$(tput setaf 2); \
83 blu=$$(tput setaf 4); \
84 std=$$(tput sgr0); \
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,
97 _dirname = \
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.
105 am__check_pre = \
106 $(SH_E_WORKAROUND); \
107 tst=`echo "$$src" | sed 's|^.*/||'`; \
108 rm -f $@-t; \
109 trap 'st=$$?; rm -f '\''$(abs_builddir)/$@-t'\''; (exit $$st); exit $$st' \
110 1 2 13 15; \
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; \
116 $(TESTS_ENVIRONMENT)
118 # To be appended to the command running the test. Handles the stdout
119 # and stderr redirection, and catch the exit status.
120 am__check_post = \
121 >$@-t 2>&1; \
122 estatus=$$?; \
123 if test $$estatus -eq 177; then \
124 $(ENABLE_HARD_ERRORS) || estatus=1; \
125 fi; \
126 TERM=$$__SAVED_TERM; export TERM; \
127 $(am__tty_colors); \
128 xfailed=PASS; \
129 for xfail in : $(XFAIL_TESTS); do \
130 case $$src in \
131 $$xfail | */$$xfail) xfailed=XFAIL; break; \
132 esac; \
133 done; \
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 ;; \
141 esac; \
142 echo "$${col}$$res$${std}: $@"; \
143 echo "$$res: $@ (exit: $$estatus)" | \
144 $(am__rst_section) >$@; \
145 cat $@-t >>$@; \
146 rm $@-t
148 SUFFIXES = .html .log
150 # From a test (with no extension) to a log file.
151 if GNU_MAKE
152 %.log: %
153 @src='$<'; $(am__check_pre) "$$dir$$src" $(am__check_post)
154 else
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.
158 CHECK-FORCE:
159 DEPENDENCY = CHECK-FORCE
160 $(TEST_LOGS): $(DEPENDENCY)
161 @if test '$(DEPENDENCY)' = CHECK-FORCE; then \
162 dst=$@; \
163 exec $(MAKE) $(AM_MAKEFLAGS) DEPENDENCY='$(srcdir)'/$${dst%.log} $@;\
164 else \
165 src='$(DEPENDENCY)'; \
166 $(am__check_pre) "$$dir$$src" $(am__check_post); \
168 endif
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. "; \
186 exit=true;; \
187 fail=0:xpass=0:xfail=*) \
188 msg="All $$all tests behaved as expected"; \
189 msg="$$msg ($$xfail expected failures). "; \
190 exit=true;; \
191 fail=*:xpass=0:xfail=*) \
192 msg="$$fail of $$all tests failed. "; \
193 exit=false;; \
194 fail=*:xpass=*:xfail=*) \
195 msg="$$failures of $$all tests did not behave as expected"; \
196 msg="$$msg ($$xpass unexpected passes). "; \
197 exit=false;; \
198 *) \
199 echo >&2 "incorrect case"; exit 4;; \
200 esac; \
201 if test "$$skip" -ne 0; then \
202 msg="$$msg($$skip tests were not run). "; \
203 fi; \
204 if test "$$failures" -ne 0; then \
206 echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \
207 $(am__rst_title); \
208 echo "$$msg"; \
209 echo; \
210 echo ".. contents:: :depth: 2"; \
211 echo; \
212 for f in $(TEST_LOGS); \
213 do \
214 case $$(sed 1q $$f) in \
215 SKIP:*|PASS:*|XFAIL:*);; \
216 *) echo; cat $$f;; \
217 esac; \
218 done; \
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). "; \
224 fi; \
225 fi; \
226 $(am__tty_colors); \
227 if $$exit; then echo $$grn; else echo $$red; fi; \
228 echo "$$msg" | $(am__text_box); \
229 echo $$std; \
230 test x"$$VERBOSE" = x || $$exit || cat $(TEST_SUITE_LOG); \
231 $$exit
233 # if test x"$$VERBOSE" != x && ! $exit; then
235 # Run all the tests.
236 check-TESTS:
237 @if test -z '$(LAZY_TEST_SUITE)'; then \
238 rm -f $(TEST_SUITE_LOG) $(TEST_LOGS); \
240 @$(MAKE) $(TEST_SUITE_LOG)
243 ## -------------- ##
244 ## Produce HTML. ##
245 ## -------------- ##
247 TEST_SUITE_HTML = $(TEST_SUITE_LOG:.log=.html)
249 .log.html:
250 @for r2h in $(RST2HTML) $$RST2HTML rst2html rst2html.py; \
251 do \
252 if ($$r2h --version) >/dev/null 2>&1; then \
253 R2H=$$r2h; \
254 fi; \
255 done; \
256 if test -z "$$R2H"; then \
257 echo >&2 "cannot find rst2html, cannot create $@"; \
258 exit 2; \
259 fi; \
260 $$R2H $< >$@.tmp
261 @mv $@.tmp $@
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.
265 check-html:
266 @if $(MAKE) $(AM_MAKEFLAGS) check-TESTS; then :; else \
267 rv=$$?; \
268 $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_HTML); \
269 exit $$rv; \
272 .PHONY: check-html
275 ## ------- ##
276 ## Clean. ##
277 ## ------- ##
279 check-clean:
280 rm -f $(CHECK_CLEANFILES) $(TEST_SUITE_LOG) $(TEST_SUITE_HTML) $(TEST_LOGS)
281 .PHONY: check-clean
282 clean-local: check-clean