tests init: don't automatically re-execute tests with a POSIX shell
[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 # It's especially important that the 'unset' is done before sourcing
33 # ./defs, i.e., when 'set -e' is not active yet, for the benefit of shells
34 # (like Bash 2.05 and Solaris 10 /bin/ksh) that returns a non-zero status
35 # when unsetting an already-unset variable.
36 # Add an extra newline at the end so that the aliases defined by 'defs'
37 # can take effect.  Yes, this is truly required.
38 init="stderr_fileno_=2; unset am_explicit_skips; . ./defs${nl}"
39
40 # Required so that the code in defs doesn't go crazy trying to creating a
41 # temporary directory in the absolute dir of $AM_TEST_RUNNER_SHELL.
42 dummy_test_script=t/$me.sh
43
44 for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do
45   for exit_cmd in "exit $st" "sh -c 'exit $st'"; do
46     $AM_TEST_RUNNER_SHELL -c "$init $exit_cmd; :" "$dummy_test_script"
47     command_ok_ "$exit_cmd" test $? -eq $st
48   done
49 done
50
51 for sig in 1 2 13 15; do
52   if is_blocked_signal $sig; then
53     skip_ -r "signal $sig seems blocked"
54     continue
55   fi
56   if test $sig -eq 2; then
57     # Some Korn shells might otherwise get a spurious SIGINT when one is
58     # sent to the child $AM_TEST_RUNNER_SHELL.  For more details, see:
59     # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
60     trap : 2
61   fi
62   $AM_TEST_RUNNER_SHELL -c "$init kill -$sig \$\$; :" "$dummy_test_script"
63   rc=$?
64   if test $sig -eq 2; then
65     # Reset default SIGINT handler as portably as possible.
66     trap 2 || trap - 2
67   fi
68   command_ok_ "kill -$sig" test $rc -eq 99
69   unset rc
70 done
71
72 : Non-existent program.
73 $AM_TEST_RUNNER_SHELL -c "$init non-existent-prog; :" "$dummy_test_script"
74 command_ok_ "command not found" -- test $? -gt 0
75
76 : Non-executable command.
77 test -f Makefile && test ! -x Makefile || \
78   framowork_failure_ "no proper Makefile in the current directory"
79 $AM_TEST_RUNNER_SHELL -c "$init ./Makefile; :" "$dummy_test_script"
80 command_ok_ "permission denied" test $? -gt 0
81
82 : Syntax errors in the test code.
83 $AM_TEST_RUNNER_SHELL -c "$init if :; then" "$dummy_test_script"
84 command_ok_ "syntax error 1" test $? -gt 0
85 $AM_TEST_RUNNER_SHELL -c "$init true ( true )" "$dummy_test_script"
86 command_ok_ "syntax error 2" test $? -gt 0
87
88 :