tests: rename 'tests/' => 't/', '*.test' => '*.sh'
[platform/upstream/automake.git] / t / self-check-exit.tap
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 # Sanity check for the automake testsuite.
18 # Check that, in case of failing commands, the correct exit status is
19 # passed to the exit trap installed by the './defs' script.
20 # Also check that the 'errexit' shell flag is active.
21
22 am_create_testdir=no
23 . ./defs || Exit 99
24
25 plan_ 34
26
27 # This test becomes more cumbersome if we keep the 'errexit' shell flag
28 # set.  And removing it is no big deal, as this test is a TAP-based one,
29 # so that false positives remain very unlikely.
30 set +e
31
32 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
33
34 # It's especially important that the 'unset' is done before sourcing
35 # ./defs, i.e., when 'set -e' is not active yet, for the benefit of shells
36 # (like Bash 2.05 and Solaris 10 /bin/ksh) that returns a non-zero status
37 # when unsetting an already-unset variable.
38 init='stderr_fileno_=2; unset am_explicit_skips; . ./defs'
39
40 for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do
41   for exit_cmd in "Exit $st" "sh -c 'exit $st'"; do
42     $SHELL -c  "$init; $exit_cmd; :"
43     command_ok_ "$exit_cmd" test $? -eq $st
44   done
45 done
46
47 for sig in 1 2 13 15; do
48   if is_blocked_signal $sig; then
49     skip_ -r "signal $sig seems blocked"
50     continue
51   fi
52   if test $sig -eq 2; then
53     # Some Korn shells might otherwise get a spurious SIGINT signal when
54     # one is sent to the child $SHELL.  For more details, see:
55     # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
56     trap : 2
57   fi
58   $SHELL -c  "$init; kill -$sig \$\$; :"
59   rc=$?
60   if test $sig -eq 2; then
61     # Reset default SIGINT handler as portably as possible.
62     trap 2 || trap - 2
63   fi
64   if test x"$sh_errexit_works" = x"yes"; then
65     # The exit trap should turn into an hard errors any failure
66     # caused by signals.
67     command_ok_ "kill -$sig" test $rc -eq 99
68   else
69     # The exit trap is not installed, so that the shell should exit
70     # with status 128+n when receiving signal number n.  But don't
71     # be too strict in the check, as POSIX only says that "The exit
72     # status of a command that terminated because it received a
73     # signal shall be reported as greater than 128".
74     command_ok_ "kill -$sig" test $rc -gt 128
75   fi
76   unset rc
77 done
78
79 : Non-existent program.
80 # Solaris 10 /bin/sh erroneously exit with success right away when the
81 # following three conditions are met at the same time:
82 #   1. the 'errexit' flag is active,
83 #   2. an exit trap is installed, and
84 #   3. a non-existing command is issued.
85 # Note that the non-existent command is issued as the last command to
86 # the shell in the next line; this is deliberate.
87 if $SHELL -c 'set -e; trap "exit \$?" 0; non-existent-program'; then
88   maybe_todo=TODO reason="known Solaris /bin/sh bug"
89 else
90   maybe_todo="" reason=""
91 fi
92 $SHELL -c  "$init; non-existent-program; :"
93 command_ok_ "command not found" -D "$maybe_todo" -r "$reason" \
94             -- test $? -gt 0
95
96 : Non-executable command.
97 test -f Makefile && test ! -x Makefile || \
98   framowork_failure_ "no proper Makefile in the current directory"
99 $SHELL -c  "$init; ./Makefile; :"
100 command_ok_ "permission denied" test $? -gt 0
101
102 : Syntax errors in the test code.
103 $SHELL -c  "$init; if :; then"
104 command_ok_ "syntax error 1" test $? -gt 0
105 $SHELL -c  "$init; fi"
106 command_ok_ "syntax error 2" test $? -gt 0
107
108 :