maint: Update 'git-tag-release' rule
[automake.git] / t / tap-color.sh
blob2ca453fcfe8c8c0a4196a2fd2852a7b29d7bfc21
1 #! /bin/sh
2 # Copyright (C) 2011-2017 Free Software Foundation, Inc.
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.
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.
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/>.
17 # TAP support:
18 # - colorization of TAP results and diagnostic messages
20 required='grep-nonprint'
21 . test-init.sh
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"
31 cat > Makefile.am << 'END'
32 AUTOMAKE_OPTIONS = color-tests
33 AM_TEST_LOG_DRIVER_FLAGS = --comments
34 TEST_LOG_COMPILER = cat
35 TESTS = all.test skip.test bail.test badplan.test noplan.test \
36 few.test many.test order.test afterlate.test
37 END
39 . tap-setup.sh
41 cat > all.test << 'END'
42 1..5
43 ok 1 - foo
44 # Hi! I shouldn't be colorized!
45 not ok 2 - bar # TODO td
46 ok 3 - baz # SKIP sk
47 not ok 4 - quux
48 ok 5 - zardoz # TODO
49 END
51 cat > skip.test << 'END'
52 1..0 # SKIP whole script
53 END
55 cat > bail.test << 'END'
56 1..1
57 ok 1
58 Bail out!
59 END
61 cat > badplan.test << 'END'
62 1..2
63 ok 1
64 1..2
65 ok 2
66 END
68 cat > noplan.test << 'END'
69 ok 1
70 END
72 cat > few.test << 'END'
73 1..2
74 ok 1
75 END
77 cat > many.test << 'END'
78 1..1
79 ok 1
80 ok 2
81 END
83 cat > order.test << 'END'
84 1..1
85 ok 5
86 END
88 cat > afterlate.test << 'END'
89 ok 1
90 1..2
91 ok 2
92 END
94 test_color ()
96 # Not a useless use of cat; see above comments "grep-nonprinting"
97 # requirement in 'test-init.sh'.
98 cat stdout | grep "^${grn}PASS${std}: all\.test 1 - foo$"
99 cat stdout | grep "^${lgn}XFAIL${std}: all\.test 2 - bar # TODO td$"
100 cat stdout | grep "^${blu}SKIP${std}: all\.test 3 - baz # SKIP sk$"
101 cat stdout | grep "^${red}FAIL${std}: all\.test 4 - quux$"
102 cat stdout | grep "^${red}XPASS${std}: all\.test 5 - zardoz # TODO$"
103 cat stdout | grep "^${blu}SKIP${std}: skip\.test - whole script$"
104 cat stdout | grep "^${grn}PASS${std}: bail\.test 1$"
105 cat stdout | grep "^${mgn}ERROR${std}: bail\.test - Bail out!$"
106 cat stdout | grep "^${mgn}ERROR${std}: badplan\.test - multiple test plans$"
107 cat stdout | grep "^${mgn}ERROR${std}: noplan\.test - missing test plan$"
108 cat stdout | grep "^${mgn}ERROR${std}: few.test - too few tests run (expected 2, got 1)$"
109 cat stdout | grep "^${mgn}ERROR${std}: many.test - too many tests run (expected 1, got 2)$"
110 cat stdout | grep "^${mgn}ERROR${std}: many.test 2 # UNPLANNED$"
111 cat stdout | grep "^${mgn}ERROR${std}: order.test 5 # OUT-OF-ORDER (expecting 1)$"
112 cat stdout | grep "^${mgn}ERROR${std}: afterlate\.test 2 # AFTER LATE PLAN$"
113 # Diagnostic messages shouldn't be colorized.
114 cat stdout | grep "^# all\.test: Hi! I shouldn't be colorized!$"
118 test_no_color ()
120 # With make implementations that, like Solaris make, in case of errors
121 # print the whole failing recipe on standard output, we should content
122 # ourselves with a laxer check, to avoid false positives.
123 # Keep this in sync with lib/am/check.am:$(am__color_tests).
124 if $FGREP '= Xalways; then' stdout; then
125 # Extra verbose make, resort to laxer checks.
126 # But we also want to check that the testsuite summary is not unduly
127 # colorized.
129 set +e # In case some grepped regex below isn't matched.
130 # Not a useless use of cat; see above comments "grep-nonprinting"
131 # requirement in 'test-init.sh'.
132 cat stdout | grep "TOTAL.*:"
133 cat stdout | grep "PASS.*:"
134 cat stdout | grep "FAIL.*:"
135 cat stdout | grep "SKIP.*:"
136 cat stdout | grep "XFAIL.*:"
137 cat stdout | grep "XPASS.*:"
138 cat stdout | grep "ERROR.*:"
139 cat stdout | grep "^#"
140 cat stdout | grep 'test.*expected'
141 cat stdout | grep 'test.*not run'
142 cat stdout | grep '===='
143 cat stdout | grep '[Ss]ee .*test-suite\.log'
144 cat stdout | grep '[Tt]estsuite summary'
145 ) | grep "$esc" && exit 1
146 : For shells with broken 'set -e'
147 else
148 cat stdout | grep "$esc" && exit 1
149 : For shells with broken 'set -e'
153 # Forced colorization should take place also with non-ANSI terminals;
154 # hence the "TERM=dumb" definition.
155 AM_COLOR_TESTS=always; export AM_COLOR_TESTS
156 run_make -O -e FAIL TERM=dumb check
157 test_color
159 unset AM_COLOR_TESTS
160 run_make -O -e FAIL TERM=ansi check
161 test_no_color