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