tests: automatic re-execution works for non-POSIX shells too
[platform/upstream/automake.git] / defs
1 # -*- shell-script -*-
2 #
3 # Copyright (C) 1996-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 # *** IMPORTANT NOTE ***
19 # This file should execute correctly with any system's /bin/sh (which
20 # might be just a Bourne shell, non POSIX-conforming, like on Solaris
21 # up to version 11 at least).
22
23 # Ensure we are running from the right directory.
24 for f in defs-static t/ax/test-init.sh; do
25   if test ! -f ./$f; then
26    echo "$0: ./$f: not found in current directory" >&2
27    exit 99
28   fi
29 done
30
31 # Source the shell static setup and variable definitions.
32 . ./defs-static
33 test $? -eq 0 || exit 99
34
35 # Make sure we run with the shell detected at configure time or forced
36 # by the user (unless the user forbids it).  That is assumed to be a
37 # proper POSIX shell.
38 case ${AM_TESTS_REEXEC-yes} in
39   n|no|false|0)
40     ;;
41   *)
42     # Ensure we can find ourselves.
43     if test ! -f "$0"; then
44       echo "$0: unable to find myself" >&2
45       exit 99
46     fi
47     AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
48     # Cannot simply do "opts=$-", since the content of $- is not
49     # portable among different shells.  So try to propagate only
50     # the portable and interesting options.
51     case $- in
52       *x*v*|*v*x) opts=-vx;;
53       *v*) opts=-v;;
54       *x*) opts=-x;;
55       *) opts=;;
56     esac
57     echo exec $AM_TEST_RUNNER_SHELL $opts "$0" "$*"
58     exec $AM_TEST_RUNNER_SHELL $opts "$0" ${1+"$@"}
59     # This should be dead code, unless some strange error happened. 
60     echo "$0: failed to re-execute with $AM_TEST_RUNNER_SHELL" >&2
61     exit 99
62     ;;
63 esac
64
65 # Source the actual test initialization and setup code, and return
66 # control to the test script that is sourcing us.
67 . "$am_testauxdir/test-init.sh"