From: Ralf Wildenhues Date: Thu, 8 Nov 2007 21:32:15 +0000 (+0100) Subject: Implement colorized test output. X-Git-Tag: v1.10b~225 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8db74fc05ddadc2af4115ed4b88957f33473757;p=thirdparty%2Fautomake.git 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. --- diff --git a/ChangeLog b/ChangeLog index aeb850544..22cab109d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2007-11-08 Akim Demaille + Ralf Wildenhues + Bob Proulx + + 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 (tiny change) For PR automake/526: diff --git a/NEWS b/NEWS index b9aa1d3d5..79a3deac1 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 3c47cc1d9..127a6072b 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 8f2ca704e..fcc89023c 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 c2e496eec..2a39ec180 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, +@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 diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm index a63f97ad6..da51b70e9 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 f03165ccd..1959da133 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -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=''; \ + grn=''; \ + lgn=''; \ + blu=''; \ + std=''; \ +} 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 diff --git a/lib/am/check.am b/lib/am/check.am index 776c2a51e..3ffe6a4d0 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,27 @@ ## 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=''; \ + grn=''; \ + lgn=''; \ + blu=''; \ + std=''; \ +} +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 diff --git a/tests/Makefile.am b/tests/Makefile.am index 5d61ae783..79a89d0b3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -102,6 +102,7 @@ colon4.test \ colon5.test \ colon6.test \ colon7.test \ +color.test \ comment.test \ comment2.test \ comment3.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index b9367bf9e..e0e30ca94 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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=''; \ + grn=''; \ + lgn=''; \ + blu=''; \ + std=''; \ +} 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 index 000000000..b7ba486ce --- /dev/null +++ b/tests/color.test @@ -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='' +grn='' +lgn='' +blu='' +std='' + +cat >>configure.in <Makefile.am <<'END' +AUTOMAKE_OPTIONS = color-tests +TESTS = $(check_SCRIPTS) +check_SCRIPTS = pass fail skip xpass xfail +XFAIL_TESTS = xpass xfail +END + +cat >pass <fail <skip <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 +: