Merge branch 'maint'
[platform/upstream/automake.git] / t / color.sh
1 #! /bin/sh
2 # Copyright (C) 2007-2012 Free Software Foundation, Inc.
3 #
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 2, or (at your option)
7 # any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Test Automake TESTS color output, by forcing it.
18 # Keep this in sync with the sister test 'color2.test'.
19
20 # For gen-testsuite-part: ==> try-with-serial-tests <==
21 . ./defs || Exit 1
22
23 esc='\e'
24 # Escape '[' for grep, below.
25 red="$esc\[0;31m"
26 grn="$esc\[0;32m"
27 lgn="$esc\[1;32m"
28 blu="$esc\[1;34m"
29 mgn="$esc\[0;35m"
30 std="$esc\[m"
31
32 # Check that grep can parse nonprinting characters.
33 # BSD 'grep' works from a pipe, but not a seekable file.
34 # GNU or BSD 'grep -a' works on files, but is not portable.
35 case $(echo "$std" | grep .) in
36   "$std") ;;
37   *) skip_ "grep can't parse nonprinting characters";;
38 esac
39
40 cat >>configure.ac <<END
41 AC_OUTPUT
42 END
43
44 cat >Makefile.am <<'END'
45 AUTOMAKE_OPTIONS = color-tests
46 TESTS = $(check_SCRIPTS)
47 check_SCRIPTS = pass fail skip xpass xfail error
48 XFAIL_TESTS = xpass xfail
49 END
50
51 cat >pass <<END
52 #! /bin/sh
53 exit 0
54 END
55
56 cat >fail <<END
57 #! /bin/sh
58 exit 1
59 END
60
61 cat >skip <<END
62 #! /bin/sh
63 exit 77
64 END
65
66 cat >error <<END
67 #! /bin/sh
68 exit 99
69 END
70
71 cp fail xfail
72 cp pass xpass
73 chmod +x pass fail skip xpass xfail error
74
75 $ACLOCAL
76 $AUTOCONF
77 $AUTOMAKE --add-missing
78
79 test_color ()
80 {
81   # Not a useless use of cat; see above comments about grep.
82   cat stdout | grep "^${grn}PASS${std}: .*pass"
83   cat stdout | grep "^${red}FAIL${std}: .*fail"
84   cat stdout | grep "^${blu}SKIP${std}: .*skip"
85   cat stdout | grep "^${lgn}XFAIL${std}: .*xfail"
86   cat stdout | grep "^${red}XPASS${std}: .*xpass"
87   # The old serial testsuite driver doesn't distinguish between failures
88   # and hard errors.
89   if test x"$am_serial_tests" = x"yes"; then
90     cat stdout | grep "^${red}FAIL${std}: .*error"
91   else
92     cat stdout | grep "^${mgn}ERROR${std}: .*error"
93   fi
94   :
95 }
96
97 test_no_color ()
98 {
99   # With make implementations that, like Solaris make, in case of errors
100   # print the whole failing recipe on standard output, we should content
101   # ourselves with a laxer check, to avoid false positives.
102   # Keep this in sync with lib/am/check.am:$(am__color_tests).
103   if $FGREP '= Xalways; then' stdout; then
104     # Extra verbose make, resort to laxer checks.
105     # Note that we also want to check that the testsuite summary is
106     # not unduly colorized.
107     (
108       set +e # In case some grepped regex below isn't matched.
109       # Not a useless use of cat; see above comments about grep.
110       cat stdout | grep "TOTAL.*:"
111       cat stdout | grep "PASS.*:"
112       cat stdout | grep "FAIL.*:"
113       cat stdout | grep "SKIP.*:"
114       cat stdout | grep "XFAIL.*:"
115       cat stdout | grep "XPASS.*:"
116       cat stdout | grep "ERROR.*:"
117       cat stdout | grep 'test.*expected'
118       cat stdout | grep 'test.*not run'
119       cat stdout | grep '===='
120       cat stdout | grep '[Ss]ee .*test-suite\.log'
121       cat stdout | grep '[Tt]estsuite summary'
122     ) | grep "$esc" && Exit 1
123     : For shells with broken 'set -e'
124   else
125     cat stdout | grep "$esc" && Exit 1
126     : For shells with broken 'set -e'
127   fi
128 }
129
130 for vpath in false :; do
131
132   if $vpath; then
133     mkdir build
134     cd build
135     srcdir=..
136   else
137     srcdir=.
138   fi
139
140   $srcdir/configure
141
142   # Forced colorization should take place also with non-ANSI terminals;
143   # hence the "TERM=dumb" definition.
144   TERM=dumb AM_COLOR_TESTS=always $MAKE -e check >stdout \
145     && { cat stdout; Exit 1; }
146   cat stdout
147   test_color
148
149   TERM=ansi $MAKE -e check >stdout && { cat stdout; Exit 1; }
150   cat stdout
151   test_no_color
152
153   $MAKE distclean
154   cd $srcdir
155
156 done
157
158 :