runtest.in 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!@AM_TEST_RUNNER_SHELL@
  2. # @configure_input@
  3. #
  4. # Copyright (C) 2012-2017 Free Software Foundation, Inc.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. # Run an Automake test from the command line.
  19. set -e; set -u
  20. : ${AM_TEST_RUNNER_SHELL='@AM_TEST_RUNNER_SHELL@'}
  21. : ${AM_PROVE_CMD='prove'}
  22. : ${AM_PROVEFLAGS='--merge --verbose'}
  23. : ${srcdir='@srcdir@'}
  24. : ${abs_srcdir='@abs_srcdir@'}
  25. : ${abs_builddir='@abs_builddir@'}
  26. : ${PATH_SEPARATOR='@PATH_SEPARATOR@'}
  27. # For sourcing of extra "shell libraries" by our test scripts. As per
  28. # POSIX, sourcing a file with '.' will cause it to be looked up in $PATH
  29. # in case it is given with a relative name containing no slashes.
  30. if test "$srcdir" != .; then
  31. PATH=$abs_srcdir/t/ax$PATH_SEPARATOR$PATH
  32. fi
  33. PATH=$abs_builddir/t/ax$PATH_SEPARATOR$PATH
  34. export PATH
  35. # For use by the testsuite framework. The Automake test harness
  36. # define this, so we better do the same.
  37. export srcdir
  38. # Some testsuite-influential variables should be overridable from the
  39. # test scripts, but not from the environment.
  40. # Keep this in sync with the 'Makefile.am:AM_TESTS_ENVIRONMENT'.
  41. for v in \
  42. required \
  43. am_test_protocol \
  44. am_serial_tests \
  45. am_test_prefer_config_shell \
  46. am_original_AUTOMAKE \
  47. am_original_ACLOCAL \
  48. am_test_lib_sourced \
  49. test_lib_sourced \
  50. ; do
  51. eval "$v= && unset $v" || exit 1
  52. done
  53. unset v
  54. xecho () { printf '%s\n' "$*"; }
  55. error () { echo "$0: $*" >&2; exit 255; }
  56. # Some shell flags should be passed over to the test scripts.
  57. shell_opts=
  58. while test $# -gt 0; do
  59. case $1 in
  60. --help)
  61. xecho "Usage: $0 [--shell=PATH] [-k] [SHELL-OPTIONS]" \
  62. "[VAR=VALUE ...] TEST [TEST-OPTIONS]"
  63. exit $?
  64. ;;
  65. --shell)
  66. test $# -gt 1 || error "missing argument for option '$1'"
  67. AM_TEST_RUNNER_SHELL=$2
  68. shift
  69. ;;
  70. --shell=*)
  71. AM_TEST_RUNNER_SHELL=${1#--shell=}
  72. ;;
  73. -o)
  74. test $# -gt 1 || error "missing argument for option '$1'"
  75. shell_opts="$shell_opts -o $2"
  76. shift
  77. ;;
  78. -k|--keep-testdir|--keep-testdirs)
  79. keep_testdirs=yes; export keep_testdirs;;
  80. -*)
  81. # Assume it is an option to pass through to the shell.
  82. shell_opts="$shell_opts $1";;
  83. *=*)
  84. var=${1%%=*} val=${1#*=}
  85. xecho "$var" | LC_ALL=C grep '^[a-zA-Z_][a-zA-Z0-9_]*$' >/dev/null \
  86. || error "'$var': invalid variable name"
  87. eval "$var=\$val && export $var" || exit 1
  88. ;;
  89. *)
  90. break;;
  91. esac
  92. shift
  93. done
  94. test $# -gt 0 || error "missing argument"
  95. tst=$1; shift
  96. case $tst in
  97. /*) ;;
  98. *) if test -f ./$tst; then
  99. tst=./$tst
  100. # Support for VPATH build.
  101. elif test -f $srcdir/$tst; then
  102. tst=$srcdir/$tst
  103. else
  104. error "could not find test '$tst'"
  105. fi
  106. ;;
  107. esac
  108. case $tst in
  109. *.sh)
  110. exec $AM_TEST_RUNNER_SHELL $shell_opts "$tst" ${1+"$@"} ;;
  111. *.tap)
  112. exec "$AM_PROVE_CMD" $AM_PROVEFLAGS -e \
  113. "$AM_TEST_RUNNER_SHELL $shell_opts" "$tst" ${1+"$@"} ;;
  114. *)
  115. error "test '$tst' has an unrecognized extension" ;;
  116. esac
  117. error "dead code reached"