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