Merge branch 'micro' into maint
[platform/upstream/automake.git] / t / ax / runtest.in
1 #!@AM_TEST_RUNNER_SHELL@
2 # @configure_input@
3 #
4 # Copyright (C) 2012-2013 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
19 # Run an Automake test from the command line.
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 : ${abs_srcdir='@abs_srcdir@'}
28 : ${abs_builddir='@abs_builddir@'}
29 : ${PATH_SEPARATOR='@PATH_SEPARATOR@'}
30
31 # For sourcing of extra "shell libraries" by our test scripts.  As per
32 # POSIX, sourcing a file with '.' will cause it to be looked up in $PATH
33 # in case it is given with a relative name containing no slashes.
34 if test "$srcdir" != .; then
35   PATH=$abs_srcdir/t/ax$PATH_SEPARATOR$PATH
36 fi
37 PATH=$abs_builddir/t/ax$PATH_SEPARATOR$PATH
38 export PATH
39
40 # For use by the testsuite framework.  The Automake test harness
41 # define this, so we better do the same.
42 export srcdir
43
44 # Some testsuite-influential variables should be overridable from the
45 # test scripts, but not from the environment.
46 # Keep this in sync with the 'Makefile.am:AM_TESTS_ENVIRONMENT'.
47 for v in \
48   required \
49   am_test_protocol \
50   am_serial_tests \
51   am_test_prefer_config_shell \
52   am_original_AUTOMAKE \
53   am_original_ACLOCAL \
54   am_test_lib_sourced \
55   test_lib_sourced \
56 ; do
57   eval "$v= && unset $v" || exit 1
58 done
59 unset v
60
61 xecho () { printf '%s\n' "$*"; }
62 error () { echo "$0: $*" >&2; exit 255; }
63
64 # Some shell flags should be passed over to the test scripts.
65 shell_opts=
66 while test $# -gt 0; do
67   case $1 in
68     --help)
69        xecho "Usage: $0 [--shell=PATH] [-k] [SHELL-OPTIONS]" \
70              "[VAR=VALUE ...] TEST [TEST-OPTIONS]"
71        exit $?
72        ;;
73     --shell)
74        test $# -gt 1 || error "missing argument for option '$1'"
75        AM_TEST_RUNNER_SHELL=$2
76        shift
77        ;;
78     --shell=*)
79        AM_TEST_RUNNER_SHELL=${1#--shell=}
80        ;;
81     -o)
82        test $# -gt 1 || error "missing argument for option '$1'"
83        shell_opts="$shell_opts -o $2"
84        shift
85        ;;
86     -k|--keep-testdir|--keep-testdirs)
87        keep_testdirs=yes; export keep_testdirs;;
88     -*)
89        # Assume it is an option to pass through to the shell.
90        shell_opts="$shell_opts $1";;
91     *=*)
92        var=${1%%=*} val=${1#*=}
93        xecho "$var" | LC_ALL=C grep '^[a-zA-Z_][a-zA-Z0-9_]*$' >/dev/null \
94          || error "'$var': invalid variable name"
95        eval "$var=\$val && export $var" || exit 1
96        ;;
97      *)
98        break;;
99   esac
100   shift
101 done
102
103 test $# -gt 0 || error "missing argument"
104
105 tst=$1; shift
106
107 case $tst in
108   /*) ;;
109    *) if test -f ./$tst; then
110         tst=./$tst
111       # Support for VPATH build.
112       elif test -f $srcdir/$tst; then
113         tst=$srcdir/$tst
114       else
115         error "could not find test '$tst'"
116       fi
117       ;;
118 esac
119
120 case $tst in
121   *.sh)
122     exec $AM_TEST_RUNNER_SHELL $shell_opts "$tst" ${1+"$@"} ;;
123   *.tap)
124     exec "$AM_PROVE_CMD" $AM_PROVEFLAGS -e \
125          "$AM_TEST_RUNNER_SHELL $shell_opts" "$tst" ${1+"$@"} ;;
126   *)
127     error "test '$tst' has an unrecognized extension" ;;
128 esac
129
130 error "dead code reached"