2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Sanity check for the automake testsuite.
18 # Check that automatic re-execution of test script with the
19 # configure-time $AM_TEST_RUNNER_SHELL.
21 am_create_testdir=empty
26 unset AM_TESTS_REEXEC BASH_VERSION || :
28 cwd=`pwd` || fatal_ "cannot get current working directory"
29 cp "$am_top_builddir"/defs . || fatal_ "fetching 'defs' from top_builddir"
32 # Search for required bash and non-bash shells.
36 "$SHELL" "$AM_TEST_RUNNER_SHELL" bash bash3 bash4 :
38 test "$bash_shell" = : && break
39 $bash_shell --version || continue
40 $bash_shell -c 'test -n "$BASH_VERSION"' || continue
44 # This might not be optimal, but it's much better than writing wrapper
45 # scripts acting as "fake" shells.
46 for non_bash_shell in \
47 /bin/sh /bin/ksh sh ksh ash dash pdksh "$SHELL" "$AM_TEST_RUNNER_SHELL" :
49 test "$non_bash_shell" = : && break
50 $non_bash_shell -c 'exit 0' || continue
51 # Be sure to reject also any shell that is Zsh "in disguise" (as can
52 # be found on some Debian systems, where /bin/ksh can be symlinked to
53 # /bin/zsh4). This is required because our testsuite does not support
54 # older versions of Zsh, and that has caused spurious failures in the
56 $non_bash_shell -c 'test -n "$ZSH_VERSION$BASH_VERSION"' && continue
60 echo "bash_shell='$bash_shell'"
61 echo "non_bash_shell='$non_bash_shell'"
63 # This would denote an internal error.
64 if test "$bash_shell" = : && test "$non_bash_shell" = :; then
65 fatal_ "we couldn't find a bash shell nor a non-bash one"
69 # Functions used throughout the test.
80 /*) dname="absolute dir";;
88 bash) sh=$bash_shell;;
89 non-bash) sh=$non_bash_shell;;
90 *) fatal_ "get_sh: invalid shell type '$1'";;
95 # Check how to default, force or prevent a re-execution.
98 cat > need-bash.sh <<'END'
101 # Ensure that the script gets re-executed with bash. Also ensure that
102 # non-standard syntax used after the inclusion of './defs' doesn't cause
103 # non-bash shells to fail.
104 # Subshell required to prevent some shells (e.g., Solaris 10 /bin/sh)
105 # from only complaining on stderr but then exiting with exit status 0.
106 (foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION")
109 sh_var=AM_TEST_RUNNER_SHELL
110 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
111 -e "s|^$sh_var=.*$|$sh_var=bash; export $sh_var|" \
112 < "$am_top_builddir"/defs-static >defs-static
116 command_ok_ "re-exec if AM_TESTS_REEXEC=$1" \
117 env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
122 command_ok_ "don't re-exec if AM_TESTS_REEXEC=$1" \
123 not env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
126 if test "$bash_shell" = :; then
127 skip_row_ 10 -r "no bash shell found" AM_TESTS_REEXEC
128 elif test "$non_bash_shell" = :; then
129 skip_row_ 10 -r "no non-bash shell found" AM_TESTS_REEXEC
131 command_ok_ "re-exec if AM_TESTS_REEXEC unset" \
132 $non_bash_shell need-bash.sh
145 # Check message about the re-execution. Also check that arguments passed
146 # to a test script are preserved by a re-exec, even in "corner" cases.
149 cat > dummy.sh <<'END'
155 cat > checkargs.sh <<'END'
157 test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e"
160 chmod a+x dummy.sh checkargs.sh
163 cp dummy.sh checkargs.sh defs sub
164 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
165 < "$am_top_builddir"/defs-static > defs-static
166 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd/sub'|" \
167 < "$am_top_builddir"/defs-static > sub/defs-static
169 check_preserve_args ()
173 $sh "${dir}${dsep}checkargs.sh" a '' -e && r='ok' || r='not ok'
174 result_ "$r" "$sh re-exec preserving args [$dname]"
177 check_reexec_message ()
181 $sh "${dir}${dsep}dummy.sh" "$@" \
182 | grep "^dummy: exec $AM_TEST_RUNNER_SHELL ${dir}${dsep}dummy\\.sh $*\$" \
183 && r='ok' || r='not ok'
184 result_ "$r" "$sh display re-exec message [$dname] [args: $*]"
188 | grep "^dummy: exec $AM_TEST_RUNNER_SHELL \\./dummy\\.sh a b$" \
189 && r='ok' || r='not ok'
190 result_ "$r" "direct run display re-exec message [args: a b]"
192 ./checkargs.sh a '' -e && r='ok' || r='not ok'
193 result_ "$r" "direct re-exec preserving args"
195 for sh_type in non-bash bash; do
197 if test "$sh" = :; then
198 skip_row_ 5 -r "no $sh_type shell available" "re-exec message"
199 skip_row_ 5 -r "no $sh_type shell available" "re-exec preserving args"
202 check_preserve_args ''
203 check_reexec_message '' a b c
204 check_preserve_args .
205 check_reexec_message . a b c
207 check_preserve_args ..
208 check_reexec_message .. a b c
210 check_preserve_args "$cwd"
211 check_reexec_message "$cwd" a -b c-
212 check_preserve_args sub
213 check_reexec_message sub 1 2 3 4