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