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