]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Implement colorized test output.
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Thu, 8 Nov 2007 21:32:15 +0000 (22:32 +0100)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Thu, 8 Nov 2007 21:33:15 +0000 (22:33 +0100)
* automake.in (handle_tests): Set COLOR depending on `color-tests'.
* configure.ac (AM_INIT_AUTOMAKE): Use `color-tests'.
* doc/automake.texi (Tests, Options): Document test results,
document new option, document AM_COLOR_TESTS.
* lib/Automake/Options.pm (_process_option_list): Handle it.
* lib/am/check.am (am__tty_colors): New variable.  Enable colored
output if TERM is not dumb and depending on AM_COLOR_TESTS and
whether stdout is connected to a terminal.
(check-TESTS): Use am__tty_colors.
* NEWS: Mention color-tests.
* tests/color.test: New test.
* tests/Makefile.am: Adjust.

ChangeLog
NEWS
automake.in
configure.ac
doc/automake.texi
lib/Automake/Options.pm
lib/Automake/tests/Makefile.in
lib/am/check.am
tests/Makefile.am
tests/Makefile.in
tests/color.test [new file with mode: 0755]

index aeb85054419ea3ad39eb683719575c1cb6a20d77..22cab109ddcd1a1473ac7c66d0c2df0bb18b6198 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2007-11-08  Akim Demaille  <akim@lrde.epita.fr>
+           Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+           Bob Proulx <bob@proulx.com>
+
+       Implement colorized test output.
+       * automake.in (handle_tests): Set COLOR depending on `color-tests'.
+       * configure.ac (AM_INIT_AUTOMAKE): Use `color-tests'.
+       * doc/automake.texi (Tests, Options): Document test results,
+       document new option, document AM_COLOR_TESTS.
+       * lib/Automake/Options.pm (_process_option_list): Handle it.
+       * lib/am/check.am (am__tty_colors): New variable.  Enable colored
+       output if TERM is not dumb and depending on AM_COLOR_TESTS and
+       whether stdout is connected to a terminal.
+       (check-TESTS): Use am__tty_colors.
+       * NEWS: Mention color-tests.
+       * tests/color.test: New test.
+       * tests/Makefile.am: Adjust.
+
 2007-11-08  NightStrike  <nightstrike@gmail.com>  (tiny change)
 
        For PR automake/526:
diff --git a/NEWS b/NEWS
index b9aa1d3d58f81c65dd102ba587e294b5711abfef..79a3deac17fd95d3f68cee91c06032999920de5e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -48,6 +48,8 @@ New in 1.10a:
     stub rules.  This allows `make' to trigger a rerun of `aclocal'
     also if some previously needed macro file has been removed.
 
+  - The `color-tests' option causes colored test result output on terminals.
+
 Bugs fixed in 1.10a:
 
 * Long standing bugs:
index 3c47cc1d96d0502ea1c40bc5f722d3b501c5bea4..127a6072beefaf318d4046b958e6766a113ee6c7 100755 (executable)
@@ -4604,7 +4604,8 @@ sub handle_tests
   if (var ('TESTS'))
     {
       push (@check_tests, 'check-TESTS');
-      $output_rules .= &file_contents ('check', new Automake::Location);
+      $output_rules .= &file_contents ('check', new Automake::Location,
+                                      COLOR => !! option 'color-tests');
 
       # Tests that are known programs should have $(EXEEXT) appended.
       # For matching purposes, we need to adjust XFAIL_TESTS as well.
index 8f2ca704e4d543bd75cb3dedb41aad78b7f41f09..fcc89023c344fa12d9a758e484bb6102cfca7a4a 100644 (file)
@@ -32,7 +32,7 @@ AC_CANONICAL_BUILD
 # suite) without being bothered by `missing'.
 AC_SUBST([am_AUTOCONF], ["${AUTOCONF-autoconf}"])
 
-AM_INIT_AUTOMAKE([1.8a dist-bzip2 filename-length-max=99])
+AM_INIT_AUTOMAKE([1.8a dist-bzip2 filename-length-max=99 color-tests])
 
 # The API version is the base version.  We must guarantee
 # compatibility for all releases with the same API version.
index c2e496eece1117a083534e7e4f40aaf1e00e382a..2a39ec180a735afb9c80177c5a04c770cec7e6e0 100644 (file)
@@ -8127,6 +8127,12 @@ work when building in a separate directory (@pxref{Build Directories,
 , Build Directories , autoconf, The Autoconf Manual}), and in
 particular for the @code{distcheck} rule (@pxref{Dist}).
 
+For each of the @code{TESTS}, the result of execution is printed along
+with the test name, where @code{PASS} denotes a successful test,
+@code{FAIL} denotes a failed test, @code{XFAIL} an expected failure,
+@code{XPASS} an unexpected pass for a test that is supposed to fail,
+and @code{SKIP} denotes a skipped test.
+
 @cindex Exit status 77, special interpretation
 
 The number of failures will be printed at the end of the run.  If a
@@ -8134,6 +8140,14 @@ given test program exits with a status of 77, then its result is ignored
 in the final count.  This feature allows non-portable tests to be
 ignored in environments where they don't make sense.
 
+@vindex AM_COLOR_TESTS
+If the Automake option @code{color-tests} is used (@pxref{Options})
+and standard output is connected to a capable terminal, then the test
+results and the summary are colored appropriately.  The user can disable
+colored output by setting the @command{make} variable
+@samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
+terminal with @samp{AM_COLOR_TESTS=always}.
+
 @vindex TESTS
 @vindex TESTS_ENVIRONMENT
 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
@@ -8365,6 +8379,12 @@ currently does not check this).
 Cause @samp{make dist} to fail unless the current version number appears
 in the first few lines of the @file{NEWS} file.
 
+@item @option{color-tests}
+@cindex Option, @option{color-tests}
+@opindex color-tests
+Cause output of the simple test suite (@pxref{Tests}) to be
+colorized on capable terminals.
+
 @item @option{dejagnu}
 @cindex Option, @option{dejagnu}
 @opindex dejagnu
index a63f97ad6b2ae3a1d9503ac8784fadff9cf46cfc..da51b70e9f5357afa333fe59412cbc900b553ac8 100644 (file)
@@ -268,6 +268,7 @@ sub _process_option_list (\%$@)
             || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
             || $_ eq 'no-exeext' || $_ eq 'no-define'
             || $_ eq 'std-options'
+            || $_ eq 'color-tests'
             || $_ eq 'cygnus' || $_ eq 'no-dependencies')
        {
          # Explicitly recognize these.
index f03165ccdf684d6860618f1ff090db44f5cfdf69..1959da133f77805caa8dba9552f9b4edc5597d0e 100644 (file)
@@ -48,6 +48,21 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/lib/mkinstalldirs
 CONFIG_CLEAN_FILES =
 SOURCES =
 DIST_SOURCES =
+# If stdout is a non-dumb tty, use colors.  If test -t is not supported,
+# then this fails; a conservative approach.  Of course do not redirect
+# stdout here, just stderr.
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=; \
+test "X$(AM_COLOR_TESTS)" != Xno \
+&& test "X$$TERM" != Xdumb \
+&& { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
+&& { \
+  red='\e[0;31m'; \
+  grn='\e[0;32m'; \
+  lgn='\e[1;32m'; \
+  blu='\e[1;34m'; \
+  std='\e[m'; \
+}
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -185,6 +200,7 @@ check-TESTS: $(TESTS)
        @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
        srcdir=$(srcdir); export srcdir; \
        list=' $(TESTS) '; \
+       $(am__tty_colors); \
        if test -n "$$list"; then \
          for tst in $$list; do \
            if test -f ./$$tst; then dir=./; \
@@ -196,10 +212,10 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
-               echo "XPASS: $$tst"; \
+               col=$$red; res=XPASS; \
              ;; \
              *) \
-               echo "PASS: $$tst"; \
+               col=$$grn; res=PASS; \
              ;; \
              esac; \
            elif test $$? -ne 77; then \
@@ -207,17 +223,18 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
-               echo "XFAIL: $$tst"; \
+               col=$$lgn; res=XFAIL; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
-               echo "FAIL: $$tst"; \
+               col=$$red; res=FAIL; \
              ;; \
              esac; \
            else \
              skip=`expr $$skip + 1`; \
-             echo "SKIP: $$tst"; \
+             col=$$blu; res=SKIP; \
            fi; \
+           echo "$${col}$$res$${std}: $$tst"; \
          done; \
          if test "$$failed" -eq 0; then \
            if test "$$xfail" -eq 0; then \
@@ -246,11 +263,15 @@ check-TESTS: $(TESTS)
              dashes="$$report"; \
          fi; \
          dashes=`echo "$$dashes" | sed s/./=/g`; \
-         echo "$$dashes"; \
+         if test "$$failed" -eq 0; then \
+           echo "$$grn$$dashes"; \
+         else \
+           echo "$$red$$dashes"; \
+         fi; \
          echo "$$banner"; \
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
-         echo "$$dashes"; \
+         echo "$$dashes$$std"; \
          test "$$failed" -eq 0; \
        else :; fi
 
index 776c2a51ed8e888badd91431c4bb81b75dd5f7db..3ffe6a4d05ecf59be52b1ef70dd12b899db67beb 100644 (file)
@@ -1,5 +1,5 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 2001, 2003, 2006 Free Software Foundation, Inc.
+## Copyright (C) 2001, 2003, 2006, 2007 Free Software Foundation, Inc.
 
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 ## 02110-1301, USA.
 
+if %?COLOR%
+# If stdout is a non-dumb tty, use colors.  If test -t is not supported,
+# then this fails; a conservative approach.  Of course do not redirect
+# stdout here, just stderr.
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=; \
+test "X$(AM_COLOR_TESTS)" != Xno \
+&& test "X$$TERM" != Xdumb \
+&& { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
+&& { \
+  red='\e[0;31m'; \
+  grn='\e[0;32m'; \
+  lgn='\e[1;32m'; \
+  blu='\e[1;34m'; \
+  std='\e[m'; \
+}
+else !%?COLOR%
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=
+endif !%?COLOR%
+
 .PHONY: check-TESTS
 
 check-TESTS: $(TESTS)
@@ -24,6 +45,7 @@ check-TESTS: $(TESTS)
 ## Make sure Solaris VPATH-expands all members of this list, even
 ## the first and the last one; thus the spaces around $(TESTS)
        list=' $(TESTS) '; \
+       $(am__tty_colors); \
        if test -n "$$list"; then \
          for tst in $$list; do \
            if test -f ./$$tst; then dir=./; \
@@ -38,10 +60,10 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
-               echo "XPASS: $$tst"; \
+               col=$$red; res=XPASS; \
              ;; \
              *) \
-               echo "PASS: $$tst"; \
+               col=$$grn; res=PASS; \
              ;; \
              esac; \
            elif test $$? -ne 77; then \
@@ -50,18 +72,19 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
-               echo "XFAIL: $$tst"; \
+               col=$$lgn; res=XFAIL; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
-               echo "FAIL: $$tst"; \
+               col=$$red; res=FAIL; \
              ;; \
              esac; \
            else \
 ## Skipped
              skip=`expr $$skip + 1`; \
-             echo "SKIP: $$tst"; \
+             col=$$blu; res=SKIP; \
            fi; \
+           echo "$${col}$$res$${std}: $$tst"; \
          done; \
 ## Prepare the banner
          if test "$$failed" -eq 0; then \
@@ -92,10 +115,14 @@ check-TESTS: $(TESTS)
              dashes="$$report"; \
          fi; \
          dashes=`echo "$$dashes" | sed s/./=/g`; \
-         echo "$$dashes"; \
+         if test "$$failed" -eq 0; then \
+           echo "$$grn$$dashes"; \
+         else \
+           echo "$$red$$dashes"; \
+         fi; \
          echo "$$banner"; \
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
-         echo "$$dashes"; \
+         echo "$$dashes$$std"; \
          test "$$failed" -eq 0; \
        else :; fi
index 5d61ae783b3dc4f3d4baed6ae47528e0ccbb358e..79a89d0b3c674b7704a1e33b7024295326f6429b 100644 (file)
@@ -102,6 +102,7 @@ colon4.test \
 colon5.test \
 colon6.test \
 colon7.test \
+color.test \
 comment.test \
 comment2.test \
 comment3.test \
index b9367bf9ece8ba6e9a56929a9977e95ecdff8e55..e0e30ca94d50c335ecdb5ddad7e1cf9b043f13b4 100644 (file)
@@ -49,6 +49,21 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/lib/mkinstalldirs
 CONFIG_CLEAN_FILES = defs aclocal-${APIVERSION} automake-${APIVERSION}
 SOURCES =
 DIST_SOURCES =
+# If stdout is a non-dumb tty, use colors.  If test -t is not supported,
+# then this fails; a conservative approach.  Of course do not redirect
+# stdout here, just stderr.
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=; \
+test "X$(AM_COLOR_TESTS)" != Xno \
+&& test "X$$TERM" != Xdumb \
+&& { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
+&& { \
+  red='\e[0;31m'; \
+  grn='\e[0;32m'; \
+  lgn='\e[1;32m'; \
+  blu='\e[1;34m'; \
+  std='\e[m'; \
+}
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -235,6 +250,7 @@ colon4.test \
 colon5.test \
 colon6.test \
 colon7.test \
+color.test \
 comment.test \
 comment2.test \
 comment3.test \
@@ -807,6 +823,7 @@ check-TESTS: $(TESTS)
        @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
        srcdir=$(srcdir); export srcdir; \
        list=' $(TESTS) '; \
+       $(am__tty_colors); \
        if test -n "$$list"; then \
          for tst in $$list; do \
            if test -f ./$$tst; then dir=./; \
@@ -818,10 +835,10 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
-               echo "XPASS: $$tst"; \
+               col=$$red; res=XPASS; \
              ;; \
              *) \
-               echo "PASS: $$tst"; \
+               col=$$grn; res=PASS; \
              ;; \
              esac; \
            elif test $$? -ne 77; then \
@@ -829,17 +846,18 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
-               echo "XFAIL: $$tst"; \
+               col=$$lgn; res=XFAIL; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
-               echo "FAIL: $$tst"; \
+               col=$$red; res=FAIL; \
              ;; \
              esac; \
            else \
              skip=`expr $$skip + 1`; \
-             echo "SKIP: $$tst"; \
+             col=$$blu; res=SKIP; \
            fi; \
+           echo "$${col}$$res$${std}: $$tst"; \
          done; \
          if test "$$failed" -eq 0; then \
            if test "$$xfail" -eq 0; then \
@@ -868,11 +886,15 @@ check-TESTS: $(TESTS)
              dashes="$$report"; \
          fi; \
          dashes=`echo "$$dashes" | sed s/./=/g`; \
-         echo "$$dashes"; \
+         if test "$$failed" -eq 0; then \
+           echo "$$grn$$dashes"; \
+         else \
+           echo "$$red$$dashes"; \
+         fi; \
          echo "$$banner"; \
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
-         echo "$$dashes"; \
+         echo "$$dashes$$std"; \
          test "$$failed" -eq 0; \
        else :; fi
 
diff --git a/tests/color.test b/tests/color.test
new file mode 100755 (executable)
index 0000000..b7ba486
--- /dev/null
@@ -0,0 +1,104 @@
+#! /bin/sh
+# Copyright (C) 2007  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test Automake TESTS color output.
+
+. ./defs || exit 1
+
+set -e
+
+red='\e[0;31m'
+grn='\e[0;32m'
+lgn='\e[1;32m'
+blu='\e[1;34m'
+std='\e[m'
+
+cat >>configure.in <<END
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+AUTOMAKE_OPTIONS = color-tests
+TESTS = $(check_SCRIPTS)
+check_SCRIPTS = pass fail skip xpass xfail
+XFAIL_TESTS = xpass xfail
+END
+
+cat >pass <<END
+#! /bin/sh
+exit 0
+END
+
+cat >fail <<END
+#! /bin/sh
+exit 1
+END
+
+cat >skip <<END
+#! /bin/sh
+exit 77
+END
+
+cp fail xfail
+cp pass xpass
+chmod +x pass fail skip xpass xfail
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+./configure
+
+test_color ()
+{
+  grep ": pass" stdout | $FGREP "$grn"
+  grep ": fail" stdout | $FGREP "$red"
+  grep ": xfail" stdout | $FGREP "$lgn"
+  grep ": xpass" stdout | $FGREP "$red"
+  grep ": skip" stdout | $FGREP "$blu"
+}
+
+test_no_color ()
+{
+  grep ": pass" stdout | $FGREP "$grn" && exit 1
+  grep ": fail" stdout | $FGREP "$red" && exit 1
+  grep ": xfail" stdout | $FGREP "$lgn" && exit 1
+  grep ": xpass" stdout | $FGREP "$red" && exit 1
+  grep ": skip" stdout | $FGREP "$blu" && exit 1
+  :
+}
+
+cat >expect-make <<'END'
+#! /usr/bin/expect -f
+spawn $env(MAKE) check $argv
+expect eof
+END
+
+$MAKE check AM_COLOR_TESTS=always >stdout && { cat stdout; exit 1; }
+cat stdout
+test_color
+
+MAKE=$MAKE expect -f expect-make foo= >stdout || exit 77
+cat stdout
+test_color
+
+MAKE=$MAKE expect -f expect-make AM_COLOR_TESTS=no >stdout || exit 77
+cat stdout
+test_no_color
+: