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