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