tests: expose automake bug#14560
[platform/upstream/automake.git] / runtest.in
1 #!@AM_TEST_RUNNER_SHELL@
2 #
3 # Copyright (C) 2012-2013 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 : ${abs_srcdir='@abs_srcdir@'}
27 : ${abs_builddir='@abs_builddir@'}
28 : ${PATH_SEPARATOR='@PATH_SEPARATOR@'}
29
30 # For sourcing of extra "shell libraries" by our test scripts.  As per
31 # POSIX, sourcing a file with '.' will cause it to be looked up in $PATH
32 # in case it is given with a relative name containing no slashes.
33 if test "$srcdir" != .; then
34   PATH=$abs_srcdir/t/ax$PATH_SEPARATOR$PATH
35 fi
36 PATH=$abs_builddir/t/ax$PATH_SEPARATOR$PATH
37 export PATH
38
39 # For use by the testsuite framework.  The Automake test harness
40 # define this, so we better do the same.
41 export srcdir
42
43 # Some testsuite-influential variables should be overridable from the
44 # test scripts, but not from the environment.
45 # Keep this in sync with the 'Makefile.am:AM_TESTS_ENVIRONMENT'.
46 for v in \
47   required \
48   am_test_protocol \
49   am_serial_tests \
50   am_test_prefer_config_shell \
51   am_original_AUTOMAKE \
52   am_original_ACLOCAL \
53   am_test_lib_sourced \
54   test_lib_sourced \
55 ; do
56   eval "$v= && unset $v" || exit 1
57 done
58 unset v
59
60 error () { echo "$0: $*" >&2; exit 255; }
61
62 # Some shell flags should be passed over to the test scripts.
63 shell_opts=
64 while test $# -gt 0; do
65   case $1 in
66     --help)
67        echo "Usage: $0 [--shell=PATH] [SHELL-OPTIONS] TEST [TEST-OPTIONS]"
68        exit $?
69        ;;
70     --shell)
71        test $# -gt 1 || error "missing argument for option '$1'"
72        AM_TEST_RUNNER_SHELL=$2
73        shift
74        ;;
75     --shell=*)
76        AM_TEST_RUNNER_SHELL=${1#--shell=}
77        ;;
78     -o)
79        test $# -gt 1 || error "missing argument for option '$1'"
80        shell_opts="$shell_opts -o $2"
81        shift
82        ;;
83     -*)
84        # Assume it is an option to pass through to the shell.
85        shell_opts="$shell_opts $1";;
86      *)
87        break;;
88   esac
89   shift
90 done
91
92 test $# -gt 0 || error "missing argument"
93
94 tst=$1; shift
95
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
109 case $tst in
110   *.sh)
111     exec $AM_TEST_RUNNER_SHELL $shell_opts "$tst" ${1+"$@"} ;;
112   *.tap)
113     exec "$AM_PROVE_CMD" $AM_PROVEFLAGS -e \
114          "$AM_TEST_RUNNER_SHELL $shell_opts" "$tst" ${1+"$@"} ;;
115   *)
116     error "test '$tst' has an unrecognized extension" ;;
117 esac
118
119 error "dead code reached"