runtest: pass *all* the given shell options to the test invocation
[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
20 set -e; set -u
21
22 : ${AM_TEST_RUNNER_SHELL='@AM_TEST_RUNNER_SHELL@'}
23 : ${AM_PROVE_CMD='prove'}
24 : ${AM_PROVEFLAGS='--merge --verbose'}
25 : ${srcdir='@srcdir@'}
26
27 error () { echo "$0: $*" >&2; exit 255; }
28
29 # Some shell flags should be passed over to the test scripts.
30 shell_opts=
31 while test $# -gt 0; do
32   case $1 in
33     --help)
34        echo "Usage: $0 [--shell=PATH] [SHELL-OPTIONS] TEST [TEST-OPTIONS]"
35        exit $?
36        ;;
37     --shell)
38        test $# -gt 1 || error "missing argument for option '$1'"
39        AM_TEST_RUNNER_SHELL=$2
40        shift
41        ;;
42     --shell=*)
43        AM_TEST_RUNNER_SHELL=${1#--shell=}
44        ;;
45     -o)
46        test $# -gt 1 || error "missing argument for option '$1'"
47        shell_opts="$shell_opts -o $2"
48        shift
49        ;;
50     -*)
51        # Assume it is an option to pass through to the shell.
52        shell_opts="$shell_opts $1";;
53      *)
54        break;;
55   esac
56   shift
57 done
58
59 test $# -gt 0 || error "missing argument"
60
61 tst=$1; shift
62
63 case $tst in
64   /*) ;;
65    *) if test -f ./$tst; then
66         tst=./$tst
67       # Support for VPATH build.
68       elif test -f $srcdir/$tst; then
69         tst=$srcdir/$tst
70       else
71         error "could not find test '$tst'"
72       fi
73       ;;
74 esac
75
76 case $tst in
77   *.sh)
78     exec $AM_TEST_RUNNER_SHELL $shell_opts "$tst" "$@" ;;
79   *.tap)
80     exec "$AM_PROVE_CMD" $AM_PROVEFLAGS -e \
81          "$AM_TEST_RUNNER_SHELL $shell_opts" "$tst" "$@" ;;
82   *)
83     error "test '$tst' has an unrecognized extension" ;;
84 esac
85
86 error "dead code reached"