Replace non-portable Awk code in dejagnu auxiliary launcher
[dejagnu.git] / runtest
blob807a6ae86e60f67d57dfb652b24282be46b5ae7b
1 #!/bin/sh
3 # Copyright (C) 1992-2016, 2021 Free Software Foundation, Inc.
5 # This file is part of DejaGnu.
7 # DejaGnu is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # DejaGnu is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with DejaGnu; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21 # This script was written by Rob Savoye. The script finds the proper
22 # expect shell and then starts DejaGnu.
24 # shellcheck disable=SC2003
25 # The shellcheck tool complains about use of expr and recommends using
26 # newer shell features instead. Solaris 10 /bin/sh does not support the
27 # newer features, so we must use expr in this script.
29 # shellcheck disable=SC2006
30 # The shellcheck tool complains about the old style backtick command
31 # substitution. Solaris 10 /bin/sh does not support the new style $()
32 # command substitution and the usage of command substitution in this script
33 # is simple enough to work. Most notably, nesting backtick command
34 # substitution is tricky, but we do not do that.
36 # Get the execution path to this script and the current directory.
38 mypath=${0-.}
39 if expr "$mypath" : '.*/.*' > /dev/null
40 then
42 else
43 IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
44 for dir in $PATH
46 test -z "$dir" && dir=.
47 if test -x "$dir/$mypath"
48 then
49 mypath="$dir/$mypath"
50 break
52 done
53 IFS="$save_ifs"
55 execpath=`echo "$mypath" | sed -e 's@/[^/]*$@@'`
57 # Get the name by which runtest was invoked and extract the config
58 # triplet.
60 runtest=`echo "$mypath" | sed -e 's@^.*/@@'`
61 target=`echo "$runtest" | sed -e 's/-runtest$//'`
62 if [ "$target" != runtest ] ; then
63 target="--target ${target}"
64 else
65 target=""
68 # Find the right expect binary to use. If a variable EXPECT exists, it
69 # takes precedence over all other tests. Otherwise look for a freshly
70 # built one, and then use one in the path.
72 if [ -n "$EXPECT" ] ; then
73 expectbin="$EXPECT"
74 else
75 if [ -x "$execpath/expect" ] ; then
76 expectbin="$execpath/expect"
77 else
78 expectbin=expect
82 # Just to be safe ..
84 if [ -z "$expectbin" ]; then
85 echo "ERROR: No expect shell found"
86 exit 1
89 # This wrapper script will set up run-time library search PATHs.
91 if [ -x "$expectbin-bld.sh" ]; then
92 expectbin="${CONFIG_SHELL-/bin/sh} $expectbin-bld.sh"
95 # Extract a few options from the option list.
97 verbose=0
98 debug=""
99 for a in "$@" ; do
100 case $a in
101 -v|--v|-verb*|--verb*) verbose=`expr $verbose + 1` ;;
102 -D0|--D0) debug="-D 0" ;;
103 -D1|--D1) debug="-D 1" ;;
104 esac
105 done
107 if expr "$verbose" \> 0 > /dev/null ; then
108 echo Expect binary is "$expectbin"
111 # Find runtest.exp. First we look in its installed location,
112 # otherwise start if from the source tree.
114 # runtest.exp is found in @datadir@ (set by configure), but $execpath
115 # is @bindir@. We're assuming that:
117 # @datadir@ == @bindir@/../share
118 # or
119 # @datadir@ == @bindir@/../../share
121 # .. which is a very weak assumption
123 bindir1up_check=`echo "$execpath" | sed -e 's@/[^/]*$@/share/dejagnu@'`
124 bindir2up_check=`echo "$execpath" | sed -e 's@/[^/]*/[^/]*$@/share/dejagnu@'`
126 for i in \
127 "${bindir1up_check}" "${bindir2up_check}" "$execpath" \
128 /usr/share/dejagnu \
129 /usr/local/share/dejagnu ; do
130 if expr "$verbose" \> 1 > /dev/null ; then
131 echo Looking for "$i"/runtest.exp.
133 if [ -f "$i/runtest.exp" ] ; then
134 runpath="$i"
135 if expr "$verbose" \> 0 > /dev/null ; then
136 echo Using "$i"/runtest.exp as main test driver
138 break
140 done
142 # Check for an environment variable.
144 if [ -n "$DEJAGNULIBS" ] ; then
145 runpath="$DEJAGNULIBS"
146 if expr "$verbose" \> 0 > /dev/null ; then
147 echo Using "$DEJAGNULIBS"/runtest.exp as main test driver
150 if [ -z "$runpath" ] ; then
151 echo "ERROR: runtest.exp does not exist"
152 exit 1
155 if command -v "$expectbin" > /dev/null ; then :; else
156 echo "ERROR: unable to find expect in the PATH"
157 exit 1
160 # The `debug' and `target' variables are _intended_ to contain zero or two
161 # words each. Word splitting is desired here.
162 # shellcheck disable=SC2086
163 exec "$expectbin" $debug -- "$runpath"/runtest.exp $target ${1+"$@"}