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