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