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