Merge branch 'maint'
[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 # Add an extra newline at the end so that the aliases defined by 'defs'
39 # can take effect.  Yes, this is truly required.
40 init="stderr_fileno_=2; unset am_explicit_skips; . ./defs${nl}"
41
42 # Required so that the code in defs doesn't go crazy trying to creating a
43 # temporary directory in the absolute dir of $AM_TEST_RUNNER_SHELL.
44 dummy_test_script=t/$me.sh
45
46 for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do
47   for exit_cmd in "exit $st" "sh -c 'exit $st'"; do
48     $AM_TEST_RUNNER_SHELL -c "$init $exit_cmd; :" "$dummy_test_script"
49     command_ok_ "$exit_cmd" test $? -eq $st
50   done
51 done
52
53 for sig in 1 2 13 15; do
54   if is_blocked_signal $sig; then
55     skip_ -r "signal $sig seems blocked"
56     continue
57   fi
58   if test $sig -eq 2; then
59     # Some Korn shells might otherwise get a spurious SIGINT when one is
60     # sent to the child $AM_TEST_RUNNER_SHELL.  For more details, see:
61     # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
62     trap : 2
63   fi
64   $AM_TEST_RUNNER_SHELL -c "$init kill -$sig \$\$; :" "$dummy_test_script"
65   rc=$?
66   if test $sig -eq 2; then
67     # Reset default SIGINT handler as portably as possible.
68     trap 2 || trap - 2
69   fi
70   command_ok_ "kill -$sig" test $rc -eq 99
71   unset rc
72 done
73
74 : Non-existent program.
75 # Solaris 10 /bin/sh erroneously exit with success right away when the
76 # following three conditions are met at the same time:
77 #   1. the 'errexit' flag is active,
78 #   2. an exit trap is installed, and
79 #   3. a non-existing command is issued.
80 # Note that the non-existent command is issued as the last command to
81 # the shell in the next line; this is deliberate.
82 # FIXME: remove this workaround once we have a better configure-time
83 # determination of '$AM_TEST_RUNNER_SHELL'.
84 if $AM_TEST_RUNNER_SHELL -c 'set -e; trap "exit \$?" 0; non-existent-program'; then
85   maybe_todo=TODO reason="known Solaris /bin/sh bug"
86 else
87   maybe_todo="" reason=""
88 fi
89 $AM_TEST_RUNNER_SHELL -c "$init non-existent-prog; :" "$dummy_test_script"
90 command_ok_ "command not found" -D "$maybe_todo" -r "$reason" \
91             -- test $? -gt 0
92
93 : Non-executable command.
94 test -f Makefile && test ! -x Makefile || \
95   framowork_failure_ "no proper Makefile in the current directory"
96 $AM_TEST_RUNNER_SHELL -c "$init ./Makefile; :" "$dummy_test_script"
97 command_ok_ "permission denied" test $? -gt 0
98
99 : Syntax errors in the test code.
100 $AM_TEST_RUNNER_SHELL -c "$init if :; then" "$dummy_test_script"
101 command_ok_ "syntax error 1" test $? -gt 0
102 $AM_TEST_RUNNER_SHELL -c "$init true ( true )" "$dummy_test_script"
103 command_ok_ "syntax error 2" test $? -gt 0
104
105 :