color-tests: coloring can be forced on non-ANSI terminals as well
[platform/upstream/automake.git] / t / ax / tap-summary-aux.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 # Auxiliary script for tests on TAP support: checking testsuite summary.
18
19 am_parallel_tests=yes
20 . ./defs || Exit 1
21
22 br='============================================================================'
23
24 case $use_colors in
25   yes|no) ;;
26   *) fatal_ "invalid \$use_colors value '$use_colors'"
27 esac
28
29 fetch_tap_driver
30
31 cat > configure.ac <<END
32 AC_INIT([GNU AutoTAP], [5.12], [bug-automake@gnu.org])
33 AM_INIT_AUTOMAKE([parallel-tests])
34 AC_CONFIG_FILES([Makefile])
35 AC_OUTPUT
36 END
37
38 cat > Makefile.am << 'END'
39 TEST_LOG_DRIVER = $(srcdir)/tap-driver
40 TEST_LOG_COMPILER = cat
41 TESTS = all.test
42 END
43
44 # The following shell variables are influential for this function:
45 #  - expect_failure
46 #  - use_colors
47 do_check ()
48 {
49   case $#,$1 in
50     1,--pass) expect_failure=no;;
51     1,--fail) expect_failure=yes;;
52            *) fatal_ "invalid usage of 'do_check'";;
53   esac
54   shift
55   cat > summary.exp
56   cat all.test
57   st=0
58   if test $use_colors = yes; then
59     # Forced colorization should take place also with non-ANSI terminals;
60     # hence the "TERM=dumb" definition.
61     make_cmd="env TERM=dumb AM_COLOR_TESTS=always $MAKE -e"
62   else
63     make_cmd=$MAKE
64   fi
65   $make_cmd check > stdout || st=$?
66   cat stdout
67   if test $expect_failure = yes; then
68     test $st -gt 0 || Exit 1
69   else
70     test $st -eq 0 || Exit 1
71   fi
72   $PERL "$am_testauxdir"/extract-testsuite-summary.pl stdout >summary.got \
73     || fatal_ "cannot extract testsuite summary"
74   cat summary.exp
75   cat summary.got
76   if test $use_colors = yes; then
77     # Use cmp, not diff, because the files might contain binary data.
78     compare=cmp
79   else
80     compare=diff
81   fi
82   $compare summary.exp summary.got || Exit 1
83 }
84
85 if test $use_colors = yes; then
86   red='\e[0;31m'
87   grn='\e[0;32m'
88   lgn='\e[1;32m'
89   blu='\e[1;34m'
90   mgn='\e[0;35m'
91   brg='\e[1m'
92   std='\e[m'
93   echo AUTOMAKE_OPTIONS = color-tests >> Makefile.am
94 else
95   red= grn= lgn= blu= mgn= brg= std=
96 fi
97
98   success_header="\
99 ${grn}${br}${std}
100 ${grn}Testsuite summary for GNU AutoTAP 5.12${std}
101 ${grn}${br}${std}"
102
103   success_footer=${grn}${br}${std}
104
105   failure_header="\
106 ${red}${br}${std}
107 ${red}Testsuite summary for GNU AutoTAP 5.12${std}
108 ${red}${br}${std}"
109
110   failure_footer="\
111 ${red}${br}${std}
112 ${red}See ./test-suite.log${std}
113 ${red}Please report to bug-automake@gnu.org${std}
114 ${red}${br}${std}"
115
116 $ACLOCAL
117 $AUTOCONF
118 $AUTOMAKE --add-missing
119
120 ./configure
121
122 # 1 pass.
123 { echo 1..1 && echo ok; } > all.test
124 do_check --pass <<END
125 $success_header
126 ${brg}# TOTAL: 1${std}
127 ${grn}# PASS:  1${std}
128 # SKIP:  0
129 # XFAIL: 0
130 # FAIL:  0
131 # XPASS: 0
132 # ERROR: 0
133 $success_footer
134 END
135
136 # 1 skip.
137 { echo 1..1 && echo 'ok # SKIP'; } > all.test
138 do_check --pass <<END
139 $success_header
140 ${brg}# TOTAL: 1${std}
141 # PASS:  0
142 ${blu}# SKIP:  1${std}
143 # XFAIL: 0
144 # FAIL:  0
145 # XPASS: 0
146 # ERROR: 0
147 $success_footer
148 END
149
150 # 1 xfail.
151 { echo 1..1 && echo 'not ok # TODO'; } > all.test
152 do_check --pass <<END
153 $success_header
154 ${brg}# TOTAL: 1${std}
155 # PASS:  0
156 # SKIP:  0
157 ${lgn}# XFAIL: 1${std}
158 # FAIL:  0
159 # XPASS: 0
160 # ERROR: 0
161 $success_footer
162 END
163
164 # 1 fail.
165 { echo 1..1 && echo not ok; } > all.test
166 do_check --fail <<END
167 $failure_header
168 ${brg}# TOTAL: 1${std}
169 # PASS:  0
170 # SKIP:  0
171 # XFAIL: 0
172 ${red}# FAIL:  1${std}
173 # XPASS: 0
174 # ERROR: 0
175 $failure_footer
176 END
177
178 # 1 xpass.
179 { echo 1..1 && echo 'ok # TODO'; } > all.test
180 do_check --fail <<END
181 $failure_header
182 ${brg}# TOTAL: 1${std}
183 # PASS:  0
184 # SKIP:  0
185 # XFAIL: 0
186 # FAIL:  0
187 ${red}# XPASS: 1${std}
188 # ERROR: 0
189 $failure_footer
190 END
191
192 # 1 hard error.
193 { echo 1..1 && echo 'Bail out!'; } > all.test
194 do_check --fail <<END
195 $failure_header
196 ${brg}# TOTAL: 1${std}
197 # PASS:  0
198 # SKIP:  0
199 # XFAIL: 0
200 # FAIL:  0
201 # XPASS: 0
202 ${mgn}# ERROR: 1${std}
203 $failure_footer
204 END
205
206 # 3 non-failing results.
207 cat > all.test <<END
208 1..3
209 ok
210 not ok # TODO
211 ok # SKIP
212 END
213 do_check --pass <<END
214 $success_header
215 ${brg}# TOTAL: 3${std}
216 ${grn}# PASS:  1${std}
217 ${blu}# SKIP:  1${std}
218 ${lgn}# XFAIL: 1${std}
219 # FAIL:  0
220 # XPASS: 0
221 # ERROR: 0
222 $success_footer
223 END
224
225 # 1 pass, 1 skip, 1 fail.
226 cat > all.test <<END
227 1..3
228 ok
229 ok # SKIP
230 not ok
231 END
232 do_check --fail <<END
233 $failure_header
234 ${brg}# TOTAL: 3${std}
235 ${grn}# PASS:  1${std}
236 ${blu}# SKIP:  1${std}
237 # XFAIL: 0
238 ${red}# FAIL:  1${std}
239 # XPASS: 0
240 # ERROR: 0
241 $failure_footer
242 END
243
244 # 1 pass, 1 xfail, 1 xpass.
245 cat > all.test <<END
246 1..3
247 ok
248 ok # TODO
249 not ok # TODO
250 END
251 do_check --fail <<END
252 $failure_header
253 ${brg}# TOTAL: 3${std}
254 ${grn}# PASS:  1${std}
255 # SKIP:  0
256 ${lgn}# XFAIL: 1${std}
257 # FAIL:  0
258 ${red}# XPASS: 1${std}
259 # ERROR: 0
260 $failure_footer
261 END
262
263 # 1 skip, 1 xfail, 1 error.
264 cat > all.test <<END
265 1..3
266 ok # SKIP
267 not ok # TODO
268 Bail out!
269 END
270 do_check --fail <<END
271 $failure_header
272 ${brg}# TOTAL: 3${std}
273 # PASS:  0
274 ${blu}# SKIP:  1${std}
275 ${lgn}# XFAIL: 1${std}
276 # FAIL:  0
277 # XPASS: 0
278 ${mgn}# ERROR: 1${std}
279 $failure_footer
280 END
281
282 # 1 of each kind
283 cat > all.test <<END
284 1..6
285 ok
286 not ok
287 ok # TODO
288 not ok # TODO
289 ok # SKIP
290 Bail out!
291 END
292 do_check --fail <<END
293 $failure_header
294 ${brg}# TOTAL: 6${std}
295 ${grn}# PASS:  1${std}
296 ${blu}# SKIP:  1${std}
297 ${lgn}# XFAIL: 1${std}
298 ${red}# FAIL:  1${std}
299 ${red}# XPASS: 1${std}
300 ${mgn}# ERROR: 1${std}
301 $failure_footer
302 END
303
304 # Prepare some common data for later.
305 for i in 0 1 2 3 4 5 6 7 8 9; do
306   for j in 0 1 2 3 4 5 6 7 8 9; do
307     echo "ok"
308     echo "not ok # TODO"
309     echo "ok # SKIP"
310   done
311 done > tap
312
313 # Lots of non-failures (300 per kind).
314 (cat tap && cat tap && cat tap) > all.test
315 test `wc -l <all.test` -eq 900 || Exit 99 # Sanity check.
316 echo 1..900 >> all.test # Test plan.
317 do_check --pass <<END
318 $success_header
319 ${brg}# TOTAL: 900${std}
320 ${grn}# PASS:  300${std}
321 ${blu}# SKIP:  300${std}
322 ${lgn}# XFAIL: 300${std}
323 # FAIL:  0
324 # XPASS: 0
325 # ERROR: 0
326 $success_footer
327 END
328
329 # 1 failure and lots of non-failures means failure.
330 (cat tap && echo "not ok" && cat tap) > all.test
331 test `wc -l <all.test` -eq 601 || Exit 99 # Sanity check.
332 echo 1..601 >> all.test # Test plan.
333 do_check --fail <<END
334 $failure_header
335 ${brg}# TOTAL: 601${std}
336 ${grn}# PASS:  200${std}
337 ${blu}# SKIP:  200${std}
338 ${lgn}# XFAIL: 200${std}
339 ${red}# FAIL:  1${std}
340 # XPASS: 0
341 # ERROR: 0
342 $failure_footer
343 END
344
345 # 1 error and lots of non-failures means failure.
346 (cat tap && sed 30q tap && echo 'Bail out!') > all.test
347 test `wc -l <all.test` -eq 331 || Exit 99 # Sanity check.
348 echo 1..331 >> all.test # Test plan.
349 do_check --fail <<END
350 $failure_header
351 ${brg}# TOTAL: 331${std}
352 ${grn}# PASS:  110${std}
353 ${blu}# SKIP:  110${std}
354 ${lgn}# XFAIL: 110${std}
355 # FAIL:  0
356 # XPASS: 0
357 ${mgn}# ERROR: 1${std}
358 $failure_footer
359 END
360
361 :