tests: expose automake bug#14560
[platform/upstream/automake.git] / t / color-tests.sh
1 #! /bin/sh
2 # Copyright (C) 2007-2013 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, by forcing it.
18 # Keep this in sync with the sister test 'color-tests2.sh'.
19
20 required='grep-nonprint'
21 # For gen-testsuite-part: ==> try-with-serial-tests <==
22 . test-init.sh
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 cat >>configure.ac <<END
33 AC_OUTPUT
34 END
35
36 cat >Makefile.am <<'END'
37 TESTS = $(check_SCRIPTS)
38 check_SCRIPTS = pass fail skip xpass xfail error
39 XFAIL_TESTS = xpass xfail
40 END
41
42 cat >pass <<END
43 #! /bin/sh
44 exit 0
45 END
46
47 cat >fail <<END
48 #! /bin/sh
49 exit 1
50 END
51
52 cat >skip <<END
53 #! /bin/sh
54 exit 77
55 END
56
57 cat >error <<END
58 #! /bin/sh
59 exit 99
60 END
61
62 cp fail xfail
63 cp pass xpass
64 chmod +x pass fail skip xpass xfail error
65
66 $ACLOCAL
67 $AUTOCONF
68 $AUTOMAKE --add-missing
69
70 test_color ()
71 {
72   # Not a useless use of cat; see above comments "grep-nonprinting"
73   # requirement in 'test-init.sh'.
74   cat stdout | grep "^${grn}PASS${std}: .*pass"
75   cat stdout | grep "^${red}FAIL${std}: .*fail"
76   cat stdout | grep "^${blu}SKIP${std}: .*skip"
77   cat stdout | grep "^${lgn}XFAIL${std}: .*xfail"
78   cat stdout | grep "^${red}XPASS${std}: .*xpass"
79   # The old serial testsuite driver doesn't distinguish between failures
80   # and hard errors.
81   if test x"$am_serial_tests" = x"yes"; then
82     cat stdout | grep "^${red}FAIL${std}: .*error"
83   else
84     cat stdout | grep "^${mgn}ERROR${std}: .*error"
85   fi
86   :
87 }
88
89 test_no_color ()
90 {
91   # With make implementations that, like Solaris make, in case of errors
92   # print the whole failing recipe on standard output, we should content
93   # ourselves with a laxer check, to avoid false positives.
94   # Keep this in sync with lib/am/check.am:$(am__color_tests).
95   if $FGREP '= Xalways; then' stdout; then
96     # Extra verbose make, resort to laxer checks.
97     # Note that we also want to check that the testsuite summary is
98     # not unduly colorized.
99     (
100       set +e # In case some grepped regex below isn't matched.
101       # Not a useless use of cat; see above comments "grep-nonprinting"
102       # requirement in 'test-init.sh'.
103       cat stdout | grep "TOTAL.*:"
104       cat stdout | grep "PASS.*:"
105       cat stdout | grep "FAIL.*:"
106       cat stdout | grep "SKIP.*:"
107       cat stdout | grep "XFAIL.*:"
108       cat stdout | grep "XPASS.*:"
109       cat stdout | grep "ERROR.*:"
110       cat stdout | grep 'test.*expected'
111       cat stdout | grep 'test.*not run'
112       cat stdout | grep '===='
113       cat stdout | grep '[Ss]ee .*test-suite\.log'
114       cat stdout | grep '[Tt]estsuite summary'
115     ) | grep "$esc" && exit 1
116     : For shells with broken 'set -e'
117   else
118     cat stdout | grep "$esc" && exit 1
119     : For shells with broken 'set -e'
120   fi
121 }
122
123 for vpath in false :; do
124
125   if $vpath; then
126     mkdir build
127     cd build
128     srcdir=..
129   else
130     srcdir=.
131   fi
132
133   $srcdir/configure
134
135   # Forced colorization should take place also with non-ANSI terminals;
136   # hence the "TERM=dumb" definition.
137   AM_COLOR_TESTS=always; export AM_COLOR_TESTS
138   run_make -e FAIL -O TERM=dumb check
139   test_color
140
141   unset AM_COLOR_TESTS
142   run_make -e FAIL -O TERM=ansi check
143   test_no_color
144
145   $MAKE distclean
146   cd $srcdir
147
148 done
149
150 :