automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

colorful tests


From: Ralf Wildenhues
Subject: colorful tests
Date: Sun, 4 Nov 2007 18:41:03 +0100
User-agent: Mutt/1.5.17 (2007-11-02)

Hello colorful world,

I took the various bits of code from the parallel tests check.mk from
Akim and tried to mangle that suitable for inclusion in Automake.
This is what I ended up with.  (More topics to follow.)
What do you think about it?

Does anybody know how to test that colorful output actually happens?
I assume 'expect' or something similar can do this (I have no idea)?

Do I have to assume that tput may not work as expected if I redirect
stdout to /dev/null as well?  I'm not sure if the checks in
am__tty_colors won't cause bogus output on stdout on some of the weirder
systems.

Is the list of contributors sufficient/ok?

Thanks,
Ralf

2007-11-04  Akim Demaille  <address@hidden>
            Ralf Wildenhues <address@hidden>
            Bob Proulx <address@hidden>

    Implement option `color-tests' for colorized TESTS 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.
    * lib/Automake/Options.pm (_process_option_list): Handle it.
    * lib/am/check.am (am__tty_colors): New variable.  Use ...
    (check-TESTS): ... here.
    * NEWS: Mention color-tests.
    * tests/Makefile.in, lib/Automake/tests/Makefile.in: Regenerate.

diff --git a/NEWS b/NEWS
index b9aa1d3..79a3dea 100644
--- 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:
diff --git a/automake.in b/automake.in
index 3c47cc1..127a607 100755
--- a/automake.in
+++ b/automake.in
@@ -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.
diff --git a/configure.ac b/configure.ac
index 8f2ca70..fcc8902 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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.
diff --git a/doc/automake.texi b/doc/automake.texi
index c9fd901..eb4947e 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -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,
address@hidden denotes a failed test, @code{XFAIL} an expected failure,
address@hidden 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,10 @@ 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.
 
+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.
+
 @vindex TESTS
 @vindex TESTS_ENVIRONMENT
 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
@@ -8365,6 +8375,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.
 
address@hidden @option{color-tests}
address@hidden Option, @option{color-tests}
address@hidden 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
diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm
index a63f97a..da51b70 100644
--- a/lib/Automake/Options.pm
+++ b/lib/Automake/Options.pm
@@ -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.
diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in
index f03165c..785c591 100644
--- a/lib/Automake/tests/Makefile.in
+++ b/lib/Automake/tests/Makefile.in
@@ -48,6 +48,20 @@ 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$$TERM" != Xdumb && test -t 1 2>/dev/null               \
+&& (tput bold 1 && tput setaf 1 && tput sgr0) 2>/dev/null      \
+&& {                                                           \
+  red=`tput setaf 1`;                                          \
+  grn=`tput setaf 2`;                                          \
+  lgn=`tput bold``tput setaf 2`;                               \
+  blu=`tput setaf 4`;                                          \
+  std=`tput sgr0`;                                             \
+}
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -185,6 +199,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 +211,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 +222,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 +262,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/lib/am/check.am b/lib/am/check.am
index 776c2a5..a8e59aa 100644
--- a/lib/am/check.am
+++ b/lib/am/check.am
@@ -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
@@ -16,6 +16,26 @@
 ## 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$$TERM" != Xdumb && test -t 1 2>/dev/null               \
+&& (tput bold 1 && tput setaf 1 && tput sgr0) 2>/dev/null      \
+&& {                                                           \
+  red=`tput setaf 1`;                                          \
+  grn=`tput setaf 2`;                                          \
+  lgn=`tput bold``tput setaf 2`;                               \
+  blu=`tput setaf 4`;                                          \
+  std=`tput sgr0`;                                             \
+}
+else !%?COLOR%
+am__tty_colors =                                               \
+red=; grn=; lgn=; blu=; std=
+endif !%?COLOR%
+
 .PHONY: check-TESTS
 
 check-TESTS: $(TESTS)
@@ -24,6 +44,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 +59,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 +71,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 +114,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
diff --git a/tests/Makefile.in b/tests/Makefile.in
index b9367bf..e357909 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -49,6 +49,20 @@ 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$$TERM" != Xdumb && test -t 1 2>/dev/null               \
+&& (tput bold 1 && tput setaf 1 && tput sgr0) 2>/dev/null      \
+&& {                                                           \
+  red=`tput setaf 1`;                                          \
+  grn=`tput setaf 2`;                                          \
+  lgn=`tput bold``tput setaf 2`;                               \
+  blu=`tput setaf 4`;                                          \
+  std=`tput sgr0`;                                             \
+}
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -807,6 +821,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 +833,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 +844,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 +884,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
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]