tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / tap-signal.tap
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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 #  - a test script terminated by a signal causes an hard error
19
20 . test-init.sh
21
22 fetch_tap_driver
23
24 plan_ 10
25
26 cat >> configure.ac <<END
27 AC_OUTPUT
28 END
29
30 cat > Makefile.am << END
31 TEST_LOG_DRIVER = \$(srcdir)/tap-driver
32 TEST_LOG_COMPILER = $PERL -w
33 ## Will be updated later.
34 TESTS =
35 END
36
37 all_signals='1 2 3 9 13 15'
38 blocked_signals=''
39 for sig in $all_signals; do
40   # Ignore blocked signals
41   if is_blocked_signal $sig; then
42     blocked_signals="$blocked_signals $sig"
43     continue
44   fi
45   # Write the dummy test scripts in perl, not as shell scripts, to work
46   # around unportabilities in the handling of signals (in fact, even
47   # with bash, the older script were unable to properly deliver a SIGQUIT
48   # to themselves consistently).  The shebang is dummy here, as we prefer
49   # to rely on the definition of TEST_LOG_COMPILER instead.
50   unindent > signal-$sig.test <<END
51     #! /usr/bin/env perl
52     # We need autoflush to avoid losing output, which could cause spurious
53     # "no test plan seen" in the TAP driver.
54     BEGIN { $| = 1 }
55     use warnings FATAL => "all";
56     print "1..1\\n";
57     print "ok 1\\n";
58     kill $sig, \$\$;
59     print "Bail out! \$0 not killed?\\n";
60 END
61   echo TESTS += signal-$sig.test >> Makefile.am
62 done
63 results_count=$(ls *.test | wc -l | tr -d "$tab$sp")
64
65 chmod a+x *.test
66
67 $ACLOCAL
68 $AUTOCONF
69 $AUTOMAKE
70
71 ./configure
72
73 system=$(uname -s -r || echo unknown) # Needed later.
74
75 signal_caught ()
76 {
77   numeric=$1
78   case $numeric in
79      1) symbolic=HUP;;
80      2) symbolic=INT;;
81      3) symbolic=QUIT;;
82      9) symbolic=KILL;;
83     13) symbolic=PIPE;;
84     15) symbolic=TERM;;
85      *) fatal_ "unexpected signal number '$numeric'"
86   esac
87   # Sending a SIGQUIT on Cygwin 1.5 can cause a segmentation fault
88   # instead (sometimes).  Don't let this older bug pollute the results
89   # of our testsuite.
90   case $numeric,$system in
91     3,CYGWIN*\ 1.5.*) sig_re="((SIG)?($symbolic|SEGV)|$numeric|11)";;
92     *) sig_re="((SIG)?$symbolic|$numeric)";;
93   esac
94   wbound_re="($|[^a-zA-Z0-9_-])"
95   pfx_re="^ERROR: signal-$numeric\\.test"
96   case $am_tap_implementation in
97     # Dummy escape to please maintainer-check.
98     per\l) rx="$pfx_re - terminated by signal $sig_re$";;
99     shell) rx="$pfx_re .*terminated by signal $sig_re$wbound_re";;
100     *) fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'";;
101   esac
102   desc="TAP driver catch test termination by signal SIG$symbolic"
103   case " $blocked_signals " in
104     *" $numeric "*) skip_ -r "SIG$symbolic is blocked" "$desc" ;;
105     *) command_ok_ "$desc" env LC_ALL=C $EGREP "$rx" stdout ;;
106   esac
107 }
108
109 command_ok_ '"make check" fails' eval '
110   (
111     run_make -e IGNORE -O check
112     # Extra "echo" and silencing of xtraces required to avoid possible
113     # garbled output with NetBSD make, which would miss some final
114     # newlines in the expected places and thus mess up our TAP output.
115     set +x; echo
116     test $am_make_rc -gt 0
117   )
118 '
119 cat stdout # For debugging.
120
121 command_ok_ "count of test results" count_test_results \
122   total=$(($results_count * 2)) \
123   pass=$results_count error=$results_count \
124   fail=0 xpass=0 xfail=0 skip=0
125
126 for sig in $all_signals; do
127   signal_caught $sig
128 done
129
130 echo 'TEST_LOG_DRIVER_FLAGS = --ignore-exit' >> Makefile
131
132 command_ok_ '"make check" passes [--ignore-exit]' run_make -O check
133
134 command_ok_ "count of test results [--ignore-exit]" count_test_results \
135   total=$results_count pass=$results_count \
136   fail=0 xpass=0 xfail=0 skip=0 error=0
137
138 :