Merge branch 'maint'
[platform/upstream/automake.git] / t / tap-color.sh
1 #! /bin/sh
2 # Copyright (C) 2011-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 # TAP support:
18 #  - colorization of TAP results and diagnostic messages
19
20 am_parallel_tests=yes
21 . ./defs || Exit 1
22
23 TERM=ansi; export TERM
24
25 esc='\e'
26 # Escape '[' for grep, below.
27 red="$esc\[0;31m"
28 grn="$esc\[0;32m"
29 lgn="$esc\[1;32m"
30 blu="$esc\[1;34m"
31 mgn="$esc\[0;35m"
32 std="$esc\[m"
33
34 # Check that grep can parse nonprinting characters.
35 # BSD 'grep' works from a pipe, but not a seekable file.
36 # GNU or BSD 'grep -a' works on files, but is not portable.
37 case `echo "$std" | grep .` in
38   "$std") ;;
39   *) echo "$me: grep can't parse nonprinting characters" >&2; Exit 77;;
40 esac
41
42 cat > Makefile.am << 'END'
43 AUTOMAKE_OPTIONS = color-tests
44 AM_TEST_LOG_DRIVER_FLAGS = --comments
45 TEST_LOG_COMPILER = cat
46 TESTS = all.test skip.test bail.test badplan.test noplan.test \
47         few.test many.test order.test afterlate.test
48 END
49
50 . "$am_testauxdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh"
51
52 cat > all.test << 'END'
53 1..5
54 ok 1 - foo
55 # Hi! I shouldn't be colorized!
56 not ok 2 - bar # TODO td
57 ok 3 - baz # SKIP sk
58 not ok 4 - quux
59 ok 5 - zardoz # TODO
60 END
61
62 cat > skip.test << 'END'
63 1..0 # SKIP whole script
64 END
65
66 cat > bail.test << 'END'
67 1..1
68 ok 1
69 Bail out!
70 END
71
72 cat > badplan.test << 'END'
73 1..2
74 ok 1
75 1..2
76 ok 2
77 END
78
79 cat > noplan.test << 'END'
80 ok 1
81 END
82
83 cat > few.test << 'END'
84 1..2
85 ok 1
86 END
87
88 cat > many.test << 'END'
89 1..1
90 ok 1
91 ok 2
92 END
93
94 cat > order.test << 'END'
95 1..1
96 ok 5
97 END
98
99 cat > afterlate.test << 'END'
100 ok 1
101 1..2
102 ok 2
103 END
104
105 AM_COLOR_TESTS=always $MAKE check >stdout && { cat stdout; Exit 1; }
106 cat stdout
107
108 test_color ()
109 {
110   # Not a useless use of cat; see above comments about grep.
111   cat stdout | grep "^${grn}PASS${std}: all\.test 1 - foo$"
112   cat stdout | grep "^${lgn}XFAIL${std}: all\.test 2 - bar # TODO td$"
113   cat stdout | grep "^${blu}SKIP${std}: all\.test 3 - baz # SKIP sk$"
114   cat stdout | grep "^${red}FAIL${std}: all\.test 4 - quux$"
115   cat stdout | grep "^${red}XPASS${std}: all\.test 5 - zardoz # TODO$"
116   cat stdout | grep "^${blu}SKIP${std}: skip\.test - whole script$"
117   cat stdout | grep "^${grn}PASS${std}: bail\.test 1$"
118   cat stdout | grep "^${mgn}ERROR${std}: bail\.test - Bail out!$"
119   cat stdout | grep "^${mgn}ERROR${std}: badplan\.test - multiple test plans$"
120   cat stdout | grep "^${mgn}ERROR${std}: noplan\.test - missing test plan$"
121   cat stdout | grep "^${mgn}ERROR${std}: few.test - too few tests run (expected 2, got 1)$"
122   cat stdout | grep "^${mgn}ERROR${std}: many.test - too many tests run (expected 1, got 2)$"
123   cat stdout | grep "^${mgn}ERROR${std}: many.test 2 # UNPLANNED$"
124   cat stdout | grep "^${mgn}ERROR${std}: order.test 5 # OUT-OF-ORDER (expecting 1)$"
125   cat stdout | grep "^${mgn}ERROR${std}: afterlate\.test 2 # AFTER LATE PLAN$"
126   # Diagnostic messages shouldn't be colorized.
127   cat stdout | grep "^# all\.test: Hi! I shouldn't be colorized!$"
128   :
129 }
130
131 test_no_color ()
132 {
133   # With make implementations that, like Solaris make, in case of errors
134   # print the whole failing recipe on standard output, we should content
135   # ourselves with a laxer check, to avoid false positives.
136   # Keep this in sync with lib/am/check.am:$(am__color_tests).
137   if $FGREP '= Xalways || test -t 1 ' stdout; then
138     # Extra verbose make, resort to laxer checks.
139     # But we also want to check that the testsuite summary is not unduly
140     # colorized.
141     (
142       set +e # In case some grepped regex below isn't matched.
143       # Not a useless use of cat; see above comments about grep.
144       cat stdout | grep "TOTAL.*:"
145       cat stdout | grep "PASS.*:"
146       cat stdout | grep "FAIL.*:"
147       cat stdout | grep "SKIP.*:"
148       cat stdout | grep "XFAIL.*:"
149       cat stdout | grep "XPASS.*:"
150       cat stdout | grep "ERROR.*:"
151       cat stdout | grep "^#"
152       cat stdout | grep 'test.*expected'
153       cat stdout | grep 'test.*not run'
154       cat stdout | grep '===='
155       cat stdout | grep '[Ss]ee .*test-suite\.log'
156       cat stdout | grep '[Tt]estsuite summary'
157     ) | grep "$esc" && Exit 1
158     : For shells with broken 'set -e'
159   else
160     cat stdout | grep "$esc" && Exit 1
161     : For shells with broken 'set -e'
162   fi
163 }
164
165 AM_COLOR_TESTS=always $MAKE check >stdout && { cat stdout; Exit 1; }
166 cat stdout
167 test_color
168
169 $MAKE -e check >stdout && { cat stdout; Exit 1; }
170 cat stdout
171 test_no_color
172
173 :