Merge branch 'maint'
[platform/upstream/automake.git] / t / color2.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, using the expect(1) program.
18 # Keep this in sync with the sister test 'color.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 # This test requires a working a working 'expect' program.
41 # Creative quoting required to avoid spurious maintainer-check failure.
42 (set +e; expect -c 'exit ''77'; test $? -eq 77) \
43   || skip_ "requires a working expect program"
44
45 # Also, if the $MAKE program fails to consider the standard output as a
46 # tty (this happens with e.g., BSD make and Solaris dmake when they're
47 # run in parallel mode; see the autoconf manual), there is little point
48 # in proceeding.
49 cat > Makefile <<'END'
50 all:
51 ## Creative quoting in the 'echo' below to avoid risk of spurious output
52 ## matches by 'expect', below.
53         @test -t 1 && echo "stdout" "is" "a" "tty"
54 END
55
56 cat > expect-check <<'END'
57 eval spawn $env(MAKE)
58 expect {
59   "stdout is a tty" { exit 0 }
60   default { exit 1 }
61 }
62 exit 1
63 END
64 MAKE=$MAKE expect -f expect-check \
65   || skip_ "make spawned by expect should have a tty stdout"
66 rm -f expect-check Makefile
67
68 # Do the tests.
69
70 cat >>configure.ac <<END
71 AC_OUTPUT
72 END
73
74 cat >Makefile.am <<'END'
75 AUTOMAKE_OPTIONS = color-tests
76 TESTS = $(check_SCRIPTS)
77 check_SCRIPTS = pass fail skip xpass xfail error
78 XFAIL_TESTS = xpass xfail
79 END
80
81 cat >pass <<END
82 #! /bin/sh
83 exit 0
84 END
85
86 cat >fail <<END
87 #! /bin/sh
88 exit 1
89 END
90
91 cat >skip <<END
92 #! /bin/sh
93 exit 77
94 END
95
96 cat >error <<END
97 #! /bin/sh
98 exit 99
99 END
100
101 cp fail xfail
102 cp pass xpass
103 chmod +x pass fail skip xpass xfail error
104
105 $ACLOCAL
106 $AUTOCONF
107 $AUTOMAKE --add-missing
108
109 test_color ()
110 {
111   # Not a useless use of cat; see above comments about grep.
112   cat stdout | grep "^${grn}PASS${std}: .*pass"
113   cat stdout | grep "^${red}FAIL${std}: .*fail"
114   cat stdout | grep "^${blu}SKIP${std}: .*skip"
115   cat stdout | grep "^${lgn}XFAIL${std}: .*xfail"
116   cat stdout | grep "^${red}XPASS${std}: .*xpass"
117   # The old serial testsuite driver doesn't distinguish between failures
118   # and hard errors.
119   if test x"$am_serial_tests" = x"yes"; then
120     cat stdout | grep "^${red}FAIL${std}: .*error"
121   else
122     cat stdout | grep "^${mgn}ERROR${std}: .*error"
123   fi
124   :
125 }
126
127 test_no_color ()
128 {
129   # With make implementations that, like Solaris make, in case of errors
130   # print the whole failing recipe on standard output, we should content
131   # ourselves with a laxer check, to avoid false positives.
132   # Keep this in sync with lib/am/check.am:$(am__color_tests).
133   if $FGREP '= Xalways; then' stdout; then
134     # Extra verbose make, resort to laxer checks.
135     # Note that we also want to check that the testsuite summary is
136     # not unduly colorized.
137     (
138       set +e # In case some grepped regex below isn't matched.
139       # Not a useless use of cat; see above comments about grep.
140       cat stdout | grep "TOTAL.*:"
141       cat stdout | grep "PASS.*:"
142       cat stdout | grep "FAIL.*:"
143       cat stdout | grep "SKIP.*:"
144       cat stdout | grep "XFAIL.*:"
145       cat stdout | grep "XPASS.*:"
146       cat stdout | grep "ERROR.*:"
147       cat stdout | grep 'test.*expected'
148       cat stdout | grep 'test.*not run'
149       cat stdout | grep '===='
150       cat stdout | grep '[Ss]ee .*test-suite\.log'
151       cat stdout | grep '[Tt]estsuite summary'
152     ) | grep "$esc" && Exit 1
153     : For shells with broken 'set -e'
154   else
155     cat stdout | grep "$esc" && Exit 1
156     : For shells with broken 'set -e'
157   fi
158 }
159
160 cat >expect-make <<'END'
161 eval spawn $env(MAKE) -e check
162 expect eof
163 END
164
165 for vpath in false :; do
166
167   if $vpath; then
168     mkdir build
169     cd build
170     srcdir=..
171   else
172     srcdir=.
173   fi
174
175   $srcdir/configure
176
177   TERM=ansi MAKE=$MAKE expect -f $srcdir/expect-make >stdout \
178     || { cat stdout; Exit 1; }
179   cat stdout
180   test_color
181
182   TERM=dumb MAKE=$MAKE expect -f $srcdir/expect-make >stdout \
183     || { cat stdout; Exit 1; }
184   cat stdout
185   test_no_color
186
187   AM_COLOR_TESTS=no MAKE=$MAKE expect -f $srcdir/expect-make >stdout \
188     || { cat stdout; Exit 1; }
189   cat stdout
190   test_no_color
191
192   $MAKE distclean
193   cd $srcdir
194
195 done
196
197 :