color-tests: coloring can be forced on non-ANSI terminals as well
[platform/upstream/automake.git] / t / ax / testsuite-summary-checks.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 # Check the testsuite summary with the parallel-tests harness.  This
18 # script is meant to be sourced by other test script, so that it can
19 # be used to check different scenarios (colorized and non-colorized
20 # testsuite output, packages with and without bug-report addresses,
21 # testsuites in subdirectories, ...)
22
23 am_parallel_tests=yes
24 . ./defs || Exit 1
25
26 case $use_colors in
27   yes)
28     AM_COLOR_TESTS=always; export AM_COLOR_TESTS
29     # Forced colorization should take place also with non-ANSI
30     # terminals; hence this setting.
31     TERM=dumb; export TERM
32     am_opts='parallel-tests color-tests'
33     ;;
34   no)
35     am_opts='parallel-tests'
36     ;;
37   *)
38     fatal_ "invalid use_colors='$use_colors'";;
39 esac
40
41 cat > configure.ac <<END
42 AC_INIT([GNU AutoFoo], [7.1], [bug-automake@gnu.org])
43 AM_INIT_AUTOMAKE([$am_opts])
44 AC_CONFIG_FILES([Makefile])
45 AC_OUTPUT
46 END
47
48 cat > Makefile.am <<'END'
49 TEST_EXTENSIONS = .t
50 T_LOG_COMPILER = $(SHELL) $(srcdir)/log-compiler
51 ## Will be defined at runtime.
52 TESTS =
53 $(TESTS):
54 END
55
56 cat > log-compiler <<'END'
57 #!/bin/sh
58 case "$1" in
59   pass*|*/pass*|xpass*|*/xpass*) exit 0;;
60   fail*|*/fail*|xfail*|*/xfail*) exit 1;;
61   skip*|*/skip*) exit 77;;
62   error*|/error*) exit 99;;
63   copy*|*/copy*) cat "$1";;
64   *) exit 99;;
65 esac
66 END
67
68 # Quite complexish, but allow the tests in client scripts to be written
69 # in a "data-driven fashion".
70 do_check ()
71 {
72   cat > summary.exp
73   expect_failure=false
74   xfail_tests=''
75   tests="TESTS='$*'"
76   for t in $*; do
77     case $t in fail*|xpass*|error*) expect_failure=:;; esac
78     case $t in xfail*|xpass*) xfail_tests="$xfail_tests $t";; esac
79   done
80   test -z "$xfail_tests" || xfail_tests="XFAIL_TESTS='$xfail_tests'"
81   st=0
82   eval "env $tests $xfail_tests \$MAKE -e check > stdout || st=\$?"
83   cat stdout
84   if $expect_failure; then
85     test $st -gt 0 || Exit 1
86   else
87     test $st -eq 0 || Exit 1
88   fi
89   $PERL "$am_testauxdir"/extract-testsuite-summary.pl stdout >summary.got \
90    || fatal_ "cannot extract testsuite summary"
91   cat summary.exp
92   cat summary.got
93   if test $use_colors = yes; then
94     # Use cmp, not diff, because the files might contain binary data.
95     compare=cmp
96   else
97     compare=diff
98   fi
99   $compare summary.exp summary.got || Exit 1
100 }
101
102 br='============================================================================'
103
104 $ACLOCAL
105 $AUTOCONF
106 $AUTOMAKE --add-missing
107
108 :