maint: it seems APIVERSION only changes for minor/major releases.
[automake.git] / t / ax / runtest.in
blobb3a6b37432d0ef55bd733c5be46d3c4c54f74a55
1 #!@AM_TEST_RUNNER_SHELL@
2 # @configure_input@
4 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
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.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 # Run an Automake test from the command line.
21 set -e; set -u
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@'}
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
37 PATH=$abs_builddir/t/ax$PATH_SEPARATOR$PATH
38 export PATH
40 # For use by the testsuite framework.  The Automake test harness
41 # define this, so we better do the same.
42 export srcdir
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   ACLOCAL \
49   AUTOCONF \
50   AUTOHEADER \
51   AUTOMAKE \
52   AUTOUPDATE \
53   required \
54   am_test_protocol \
55   am_serial_tests \
56   am_test_prefer_config_shell \
57   am_original_AUTOMAKE \
58   am_original_ACLOCAL \
59   am_test_lib_sourced \
60   test_lib_sourced \
61 ; do
62   eval "$v= && unset $v" || exit 1
63 done
64 unset v
66 xecho () { printf '%s\n' "$*"; }
67 error () { echo "$0: $*" >&2; exit 255; }
69 # Some shell flags should be passed over to the test scripts.
70 shell_opts=
71 while test $# -gt 0; do
72   case $1 in
73     --help)
74        xecho "Usage: $0 [--shell=PATH] [-k] [SHELL-OPTIONS]" \
75              "[VAR=VALUE ...] TEST [TEST-OPTIONS]"
76        exit $?
77        ;;
78     --shell)
79        test $# -gt 1 || error "missing argument for option '$1'"
80        AM_TEST_RUNNER_SHELL=$2
81        shift
82        ;;
83     --shell=*)
84        AM_TEST_RUNNER_SHELL=${1#--shell=}
85        ;;
86     -o)
87        test $# -gt 1 || error "missing argument for option '$1'"
88        shell_opts="$shell_opts -o $2"
89        shift
90        ;;
91     -k|--keep-testdir|--keep-testdirs)
92        keep_testdirs=yes; export keep_testdirs;;
93     -*)
94        # Assume it is an option to pass through to the shell.
95        shell_opts="$shell_opts $1";;
96     *=*)
97        var=${1%%=*} val=${1#*=}
98        xecho "$var" | LC_ALL=C grep '^[a-zA-Z_][a-zA-Z0-9_]*$' >/dev/null \
99          || error "'$var': invalid variable name"
100        eval "$var=\$val && export $var" || exit 1
101        ;;
102      *)
103        break;;
104   esac
105   shift
106 done
108 test $# -gt 0 || error "missing argument"
110 tst=$1; shift
112 case $tst in
113   /*) ;;
114    *) if test -f ./$tst; then
115         tst=./$tst
116       # Support for VPATH build.
117       elif test -f $srcdir/$tst; then
118         tst=$srcdir/$tst
119       else
120         error "could not find test '$tst'"
121       fi
122       ;;
123 esac
125 case $tst in
126   *.sh)
127     exec $AM_TEST_RUNNER_SHELL $shell_opts "$tst" ${1+"$@"} ;;
128   *.tap)
129     exec "$AM_PROVE_CMD" $AM_PROVEFLAGS -e \
130          "$AM_TEST_RUNNER_SHELL $shell_opts" "$tst" ${1+"$@"} ;;
131   *)
132     error "test '$tst' has an unrecognized extension" ;;
133 esac
135 error "dead code reached"