Hash :
f9006f81
Author :
Date :
2012-05-16T16:10:06
self tests: cater for /bin/ksh symlinked to Zsh * t/self-check-reexec.tap: When searching for a suitable non-Bash shells, be sure to reject any shell that is Zsh "in disguise" (as can be found on some Debian systems, where /bin/ksh can be symlinked to /bin/zsh4). This is required because our testsuite does not support older versions of Zsh, and that was causing the test to fail in the setup just described. Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
#! /bin/sh
# Copyright (C) 2011-2012 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Sanity check for the automake testsuite.
# Check that automatic re-execution of test script with the
# configure-time $AM_TEST_RUNNER_SHELL.
am_create_testdir=empty
. ./defs || Exit 1
plan_ 32
unset AM_TESTS_REEXEC BASH_VERSION || :
cwd=`pwd` || fatal_ "cannot get current working directory"
cp "$am_top_builddir"/defs . || fatal_ "fetching 'defs' from top_builddir"
#
# Search for required bash and non-bash shells.
#
for bash_shell in \
"$SHELL" "$AM_TEST_RUNNER_SHELL" bash bash3 bash4 :
do
test "$bash_shell" = : && break
$bash_shell --version || continue
$bash_shell -c 'test -n "$BASH_VERSION"' || continue
break
done
# This might not be optimal, but it's much better than writing wrapper
# scripts acting as "fake" shells.
for non_bash_shell in \
/bin/sh /bin/ksh sh ksh ash dash pdksh "$SHELL" "$AM_TEST_RUNNER_SHELL" :
do
test "$non_bash_shell" = : && break
$non_bash_shell -c 'exit 0' || continue
# Be sure to reject also any shell that is Zsh "in disguise" (as can
# be found on some Debian systems, where /bin/ksh can be symlinked to
# /bin/zsh4). This is required because our testsuite does not support
# older versions of Zsh, and that has caused spurious failures in the
# past.
$non_bash_shell -c 'test -n "$ZSH_VERSION$BASH_VERSION"' && continue
break
done
echo "bash_shell='$bash_shell'"
echo "non_bash_shell='$non_bash_shell'"
# This would denote an internal error.
if test "$bash_shell" = : && test "$non_bash_shell" = :; then
fatal_ "we couldn't find a bash shell nor a non-bash one"
fi
#
# Functions used throughout the test.
#
get_ddata ()
{
case $1 in
""|*/) dsep=;;
*) dsep=/;;
esac
case $1 in
"") dname="no dir";;
/*) dname="absolute dir";;
*) dname="dir '$1'";;
esac
}
get_sh ()
{
case $1 in
bash) sh=$bash_shell;;
non-bash) sh=$non_bash_shell;;
*) fatal_ "get_sh: invalid shell type '$1'";;
esac
}
#
# Check how to default, force or prevent a re-execution.
#
cat > need-bash.sh <<'END'
#!/bin/false
. ./defs
# Ensure that the script gets re-executed with bash. Also ensure that
# non-standard syntax used after the inclusion of './defs' doesn't cause
# non-bash shells to fail.
# Subshell required to prevent some shells (e.g., Solaris 10 /bin/sh)
# from only complaining on stderr but then exiting with exit status 0.
(foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION")
END
sh_var=AM_TEST_RUNNER_SHELL
sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
-e "s|^$sh_var=.*$|$sh_var=bash; export $sh_var|" \
< "$am_top_builddir"/defs-static >defs-static
do_reexec ()
{
command_ok_ "re-exec if AM_TESTS_REEXEC=$1" \
env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
}
dont_reexec ()
{
command_ok_ "don't re-exec if AM_TESTS_REEXEC=$1" \
not env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
}
if test "$bash_shell" = :; then
skip_row_ 10 -r "no bash shell found" AM_TESTS_REEXEC
elif test "$non_bash_shell" = :; then
skip_row_ 10 -r "no non-bash shell found" AM_TESTS_REEXEC
else
command_ok_ "re-exec if AM_TESTS_REEXEC unset" \
$non_bash_shell need-bash.sh
do_reexec ''
do_reexec yes
do_reexec y
do_reexec true
do_reexec 1
dont_reexec no
dont_reexec n
dont_reexec false
dont_reexec 0
fi
#
# Check message about the re-execution. Also check that arguments passed
# to a test script are preserved by a re-exec, even in "corner" cases.
#
cat > dummy.sh <<'END'
#!/bin/sh
. ./defs
:
END
cat > checkargs.sh <<'END'
. ./defs
test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e"
END
chmod a+x dummy.sh checkargs.sh
mkdir sub
cp dummy.sh checkargs.sh defs sub
sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
< "$am_top_builddir"/defs-static > defs-static
sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd/sub'|" \
< "$am_top_builddir"/defs-static > sub/defs-static
check_preserve_args ()
{
dir=$1; shift
get_ddata "$dir"
$sh "${dir}${dsep}checkargs.sh" a '' -e && r='ok' || r='not ok'
result_ "$r" "$sh re-exec preserving args [$dname]"
}
check_reexec_message ()
{
dir=$1; shift
get_ddata "$dir"
$sh "${dir}${dsep}dummy.sh" "$@" \
| grep "^dummy: exec $AM_TEST_RUNNER_SHELL ${dir}${dsep}dummy\\.sh $*\$" \
&& r='ok' || r='not ok'
result_ "$r" "$sh display re-exec message [$dname] [args: $*]"
}
./dummy.sh a b \
| grep "^dummy: exec $AM_TEST_RUNNER_SHELL \\./dummy\\.sh a b$" \
&& r='ok' || r='not ok'
result_ "$r" "direct run display re-exec message [args: a b]"
./checkargs.sh a '' -e && r='ok' || r='not ok'
result_ "$r" "direct re-exec preserving args"
for sh_type in non-bash bash; do
get_sh $sh_type
if test "$sh" = :; then
skip_row_ 5 -r "no $sh_type shell available" "re-exec message"
skip_row_ 5 -r "no $sh_type shell available" "re-exec preserving args"
continue
fi
check_preserve_args ''
check_reexec_message '' a b c
check_preserve_args .
check_reexec_message . a b c
cd sub
check_preserve_args ..
check_reexec_message .. a b c
cd ..
check_preserve_args "$cwd"
check_reexec_message "$cwd" a -b c-
check_preserve_args sub
check_reexec_message sub 1 2 3 4
done
: