Implement colorized test output.
[automake/plouj.git] / lib / am / check.am
blob3ffe6a4d05ecf59be52b1ef70dd12b899db67beb
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 2001, 2003, 2006, 2007 Free Software Foundation, Inc.
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 3, or (at your option)
7 ## any later version.
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; if not, write to the Free Software
16 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 ## 02110-1301, USA.
19 if %?COLOR%
20 # If stdout is a non-dumb tty, use colors.  If test -t is not supported,
21 # then this fails; a conservative approach.  Of course do not redirect
22 # stdout here, just stderr.
23 am__tty_colors = \
24 red=; grn=; lgn=; blu=; std=; \
25 test "X$(AM_COLOR_TESTS)" != Xno \
26 && test "X$$TERM" != Xdumb \
27 && { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
28 && { \
29   red='\e[0;31m'; \
30   grn='\e[0;32m'; \
31   lgn='\e[1;32m'; \
32   blu='\e[1;34m'; \
33   std='\e[m'; \
35 else !%?COLOR%
36 am__tty_colors = \
37 red=; grn=; lgn=; blu=; std=
38 endif !%?COLOR%
40 .PHONY: check-TESTS
42 check-TESTS: $(TESTS)
43         @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
44         srcdir=$(srcdir); export srcdir; \
45 ## Make sure Solaris VPATH-expands all members of this list, even
46 ## the first and the last one; thus the spaces around $(TESTS)
47         list=' $(TESTS) '; \
48         $(am__tty_colors); \
49         if test -n "$$list"; then \
50           for tst in $$list; do \
51             if test -f ./$$tst; then dir=./; \
52 ## Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
53 ## why we also try `dir='
54             elif test -f $$tst; then dir=; \
55             else dir="$(srcdir)/"; fi; \
56             if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
57 ## Success
58               all=`expr $$all + 1`; \
59               case " $(XFAIL_TESTS) " in \
60               *$$ws$$tst$$ws*) \
61                 xpass=`expr $$xpass + 1`; \
62                 failed=`expr $$failed + 1`; \
63                 col=$$red; res=XPASS; \
64               ;; \
65               *) \
66                 col=$$grn; res=PASS; \
67               ;; \
68               esac; \
69             elif test $$? -ne 77; then \
70 ## Failure
71               all=`expr $$all + 1`; \
72               case " $(XFAIL_TESTS) " in \
73               *$$ws$$tst$$ws*) \
74                 xfail=`expr $$xfail + 1`; \
75                 col=$$lgn; res=XFAIL; \
76               ;; \
77               *) \
78                 failed=`expr $$failed + 1`; \
79                 col=$$red; res=FAIL; \
80               ;; \
81               esac; \
82             else \
83 ## Skipped
84               skip=`expr $$skip + 1`; \
85               col=$$blu; res=SKIP; \
86             fi; \
87             echo "$${col}$$res$${std}: $$tst"; \
88           done; \
89 ## Prepare the banner
90           if test "$$failed" -eq 0; then \
91             if test "$$xfail" -eq 0; then \
92               banner="All $$all tests passed"; \
93             else \
94               banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
95             fi; \
96           else \
97             if test "$$xpass" -eq 0; then \
98               banner="$$failed of $$all tests failed"; \
99             else \
100               banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
101             fi; \
102           fi; \
103 ## DASHES should contain the largest line of the banner.
104           dashes="$$banner"; \
105           skipped=""; \
106           if test "$$skip" -ne 0; then \
107             skipped="($$skip tests were not run)"; \
108             test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
109               dashes="$$skipped"; \
110           fi; \
111           report=""; \
112           if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
113             report="Please report to $(PACKAGE_BUGREPORT)"; \
114             test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
115               dashes="$$report"; \
116           fi; \
117           dashes=`echo "$$dashes" | sed s/./=/g`; \
118           if test "$$failed" -eq 0; then \
119             echo "$$grn$$dashes"; \
120           else \
121             echo "$$red$$dashes"; \
122           fi; \
123           echo "$$banner"; \
124           test -z "$$skipped" || echo "$$skipped"; \
125           test -z "$$report" || echo "$$report"; \
126           echo "$$dashes$$std"; \
127           test "$$failed" -eq 0; \
128         else :; fi