runtest: support option --shell, tell which shell should run the test
[platform/upstream/automake.git] / runtest.in
1 #!@AM_TEST_RUNNER_SHELL@
2 #
3 # Copyright (C) 2012 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # Run an Automake test from the command line.
19 # Usage:
20
21 set -e; set -u
22
23 : ${AM_TEST_RUNNER_SHELL='@AM_TEST_RUNNER_SHELL@'}
24 : ${AM_PROVE_CMD='prove'}
25 : ${AM_PROVEFLAGS='--merge --verbose'}
26 : ${srcdir='@srcdir@'}
27
28 error () { echo "$0: $*" >&2; exit 255; }
29
30 # Some shell flags should be passed over to the test scripts.
31 shell_opts=
32 while test $# -gt 0; do
33   case $1 in
34     --help)
35        echo "Usage: $0 [--shell=PATH] [SHELL-OPTIONS] TEST [TEST-OPTIONS]"
36        exit $?
37        ;;
38     --shell)
39        test $# -gt 1 || error "missing argument for option '$1'"
40        AM_TEST_RUNNER_SHELL=$2
41        shift
42        ;;
43     --shell=*)
44        AM_TEST_RUNNER_SHELL=${1#--shell=}
45        ;;
46     -o)
47        test $# -gt 1 || error "missing argument for option '$1'"
48        shell_opts="-o $2"
49        shift
50        ;;
51     -*)
52        # Assume it is an option to pass through to the shell.
53        shell_opts=$1;;
54      *)
55        break;;
56   esac
57   shift
58 done
59
60 test $# -gt 0 || error "missing argument"
61
62 tst=$1; shift
63
64 case $tst in
65    *.sh) wrapper () { exec "$@"; };;
66   *.tap) wrapper () { exec "$AM_PROVE_CMD" $AM_PROVEFLAGS -e "$@"; };;
67       *) error "test '$tst' has an unrecognized extension";;
68 esac
69
70 case $tst in
71   /*) ;;
72    *) if test -f ./$tst; then
73         tst=./$tst
74       # Support for VPATH build.
75       elif test -f $srcdir/$tst; then
76         tst=$srcdir/$tst
77       else
78         error "could not find test '$tst'"
79       fi
80       ;;
81 esac
82
83 wrapper "$AM_TEST_RUNNER_SHELL" $shell_opts "$tst" "$@"
84 error "dead code reached"