self-check-exit.tap 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 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. # Sanity check for the automake testsuite.
  17. # Check that, in case of failing commands, the correct exit status is
  18. # passed to the exit trap installed by the 'test-init.sh' script.
  19. # Also check that the 'errexit' shell flag is active.
  20. am_create_testdir=no
  21. . test-init.sh
  22. plan_ 32
  23. # This test becomes more cumbersome if we keep the 'errexit' shell flag
  24. # set. And removing it is no big deal, as this test is a TAP-based one,
  25. # so that false positives remain very unlikely.
  26. set +e
  27. # It's especially important that the 'unset' is done before sourcing
  28. # test-init.sh, i.e., when 'set -e' is not active yet, for the benefit
  29. # of shells (like Bash 2.05 and Solaris 10 /bin/ksh) that returns a
  30. # non-zero status when unsetting an already-unset variable.
  31. # Add an extra newline at the end so that the aliases defined by
  32. # test-init.sh can take effect. Yes, this is truly required.
  33. init="stderr_fileno_=2; unset am_explicit_skips;. test-init.sh${nl}"
  34. # Required so that the code in test-init.sh doesn't go crazy trying to creating a
  35. # temporary directory in the absolute dir of $AM_TEST_RUNNER_SHELL.
  36. dummy_test_script=t/$me.sh
  37. for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do
  38. for exit_cmd in "exit $st" "sh -c 'exit $st'"; do
  39. $AM_TEST_RUNNER_SHELL -c "$init $exit_cmd; :" "$dummy_test_script"
  40. command_ok_ "$exit_cmd" test $? -eq $st
  41. done
  42. done
  43. for sig in 1 2 13 15; do
  44. if is_blocked_signal $sig; then
  45. skip_ -r "signal $sig seems blocked"
  46. continue
  47. fi
  48. if test $sig -eq 2; then
  49. # Some Korn shells might otherwise get a spurious SIGINT when one is
  50. # sent to the child $AM_TEST_RUNNER_SHELL. For more details, see:
  51. # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
  52. trap : 2
  53. fi
  54. $AM_TEST_RUNNER_SHELL -c "$init kill -$sig \$\$; :" "$dummy_test_script"
  55. rc=$?
  56. if test $sig -eq 2; then
  57. # Reset default SIGINT handler as portably as possible.
  58. trap 2 || trap - 2
  59. fi
  60. command_ok_ "kill -$sig" test $rc -eq 99
  61. unset rc
  62. done
  63. : Non-existent program.
  64. $AM_TEST_RUNNER_SHELL -c "$init non-existent-prog; :" "$dummy_test_script"
  65. command_ok_ "command not found" -- test $? -gt 0
  66. : Non-executable command.
  67. test -f Makefile && test ! -x Makefile || \
  68. framowork_failure_ "no proper Makefile in the current directory"
  69. $AM_TEST_RUNNER_SHELL -c "$init ./Makefile; :" "$dummy_test_script"
  70. command_ok_ "permission denied" test $? -gt 0
  71. :