Merge branch 'msvc' into maint
[platform/upstream/automake.git] / tests / color2.test
1 #! /bin/sh
2 # Copyright (C) 2007, 2008, 2010 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 set -e
23
24 TERM=ansi
25 export TERM
26
27 red='\e[0;31m'
28 grn='\e[0;32m'
29 lgn='\e[1;32m'
30 blu='\e[1;34m'
31 std='\e[m'
32
33 # Check that grep can parse nonprinting characters.
34 # BSD 'grep' works from a pipe, but not a seekable file.
35 # GNU or BSD 'grep -a' works on files, but is not portable.
36 case `echo "$std" | grep .` in
37   "$std") ;;
38   *) echo "$me: grep can't parse nonprinting characters" >&2; Exit 77;;
39 esac
40
41 # This test requires a working a working `expect' program.
42 # Creative quoting required to avoid spurious maintainer-check failure.
43 (set +e; expect -c 'exit ''77'; test $? -eq 77) \
44   || skip_ "requires a working expect program"
45
46 # Also, if the $MAKE program fails to consider the standard output as a
47 # tty (this happens with e.g., BSD make and Solaris dmake when they're
48 # run in parallel mode; see the autoconf manual), there is little point
49 # in proceeding.
50 cat > Makefile <<'END'
51 all:
52 ## Creaive quoting in the `echo' below to avoid risk of spurious output
53 ## matches by `expect', below.
54         @test -t 1 && echo "stdout" "is" "a" "tty"
55 END
56 cat > expect-check <<'END'
57 spawn $env(MAKE)
58 expect {
59   "stdout is a tty" { exit 0 }
60   default { exit 1 }
61 }
62 exit 1
63 END
64 MAKE=$MAKE expect -f expect-check \
65   || skip_ "make spawned by expect should have a tty stdout"
66 rm -f check Makefile
67
68 # Do the tests.
69
70 cat >>configure.in <<END
71 AC_OUTPUT
72 END
73
74 cat >Makefile.am <<'END'
75 AUTOMAKE_OPTIONS = color-tests
76 TESTS = $(check_SCRIPTS)
77 check_SCRIPTS = pass fail skip xpass xfail
78 XFAIL_TESTS = xpass xfail
79 END
80
81 cat >pass <<END
82 #! /bin/sh
83 exit 0
84 END
85
86 cat >fail <<END
87 #! /bin/sh
88 exit 1
89 END
90
91 cat >skip <<END
92 #! /bin/sh
93 exit 77
94 END
95
96 cp fail xfail
97 cp pass xpass
98 chmod +x pass fail skip xpass xfail
99
100 $ACLOCAL
101 $AUTOMAKE
102 $AUTOCONF
103 ./configure
104
105 test_color ()
106 {
107   # Not a useless use of cat; see above comments about grep.
108   cat stdout | grep ": pass" | $FGREP "$grn"
109   cat stdout | grep ": fail" | $FGREP "$red"
110   cat stdout | grep ": xfail" | $FGREP "$lgn"
111   cat stdout | grep ": xpass" | $FGREP "$red"
112   cat stdout | grep ": skip" | $FGREP "$blu"
113 }
114
115 test_no_color ()
116 {
117   # Not a useless use of cat; see above comments about grep.
118   cat stdout | grep ": pass" | $FGREP "$grn" && Exit 1
119   cat stdout | grep ": fail" | $FGREP "$red" && Exit 1
120   cat stdout | grep ": xfail" | $FGREP "$lgn" && Exit 1
121   cat stdout | grep ": xpass" | $FGREP "$red" && Exit 1
122   cat stdout | grep ": skip" | $FGREP "$blu" && Exit 1
123   :
124 }
125
126 cat >expect-make <<'END'
127 spawn $env(MAKE) -e check
128 expect eof
129 END
130
131 MAKE=$MAKE expect -f expect-make >stdout \
132   || { cat stdout; Exit 1; }
133 cat stdout
134 test_color
135
136 AM_COLOR_TESTS=no MAKE=$MAKE expect -f expect-make >stdout \
137   || { cat stdout; Exit 1; }
138 cat stdout
139 test_no_color