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 $non_bash_shell -c 'test -n "$BASH_VERSION"' && continue
55 echo "bash_shell='$bash_shell'"
56 echo "non_bash_shell='$non_bash_shell'"
58 # This would denote an internal error.
59 if test "$bash_shell" = : && test "$non_bash_shell" = :; then
60 fatal_ "we couldn't find a bash shell nor a non-bash one"
64 # Functions used throughout the test.
75 /*) dname="absolute dir";;
83 bash) sh=$bash_shell;;
84 non-bash) sh=$non_bash_shell;;
85 *) fatal_ "get_sh: invalid shell type '$1'";;
90 # Check how to default, force or prevent a re-execution.
93 cat > need-bash.sh <<'END'
96 # Ensure that the script gets re-executed with bash. Also ensure that
97 # non-standard syntax used after the inclusion of './defs' doesn't cause
98 # non-bash shells to fail.
99 # Subshell required to prevent some shells (e.g., Solaris 10 /bin/sh)
100 # from only complaining on stderr but then exiting with exit status 0.
101 (foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION")
104 sh_var=AM_TEST_RUNNER_SHELL
105 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
106 -e "s|^$sh_var=.*$|$sh_var=bash; export $sh_var|" \
107 < "$am_top_builddir"/defs-static >defs-static
111 command_ok_ "re-exec if AM_TESTS_REEXEC=$1" \
112 env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
117 command_ok_ "don't re-exec if AM_TESTS_REEXEC=$1" \
118 not env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
121 if test "$bash_shell" = :; then
122 skip_row_ 10 -r "no bash shell found" AM_TESTS_REEXEC
123 elif test "$non_bash_shell" = :; then
124 skip_row_ 10 -r "no non-bash shell found" AM_TESTS_REEXEC
126 command_ok_ "re-exec if AM_TESTS_REEXEC unset" \
127 $non_bash_shell need-bash.sh
140 # Check message about the re-execution. Also check that arguments passed
141 # to a test script are preserved by a re-exec, even in "corner" cases.
144 cat > dummy.sh <<'END'
150 cat > checkargs.sh <<'END'
152 test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e"
155 chmod a+x dummy.sh checkargs.sh
158 cp dummy.sh checkargs.sh defs sub
159 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
160 < "$am_top_builddir"/defs-static > defs-static
161 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd/sub'|" \
162 < "$am_top_builddir"/defs-static > sub/defs-static
164 check_preserve_args ()
168 $sh "${dir}${dsep}checkargs.sh" a '' -e && r='ok' || r='not ok'
169 result_ "$r" "$sh re-exec preserving args [$dname]"
172 check_reexec_message ()
176 $sh "${dir}${dsep}dummy.sh" "$@" \
177 | grep "^dummy: exec $AM_TEST_RUNNER_SHELL ${dir}${dsep}dummy\\.sh $*\$" \
178 && r='ok' || r='not ok'
179 result_ "$r" "$sh display re-exec message [$dname] [args: $*]"
183 | grep "^dummy: exec $AM_TEST_RUNNER_SHELL \\./dummy\\.sh a b$" \
184 && r='ok' || r='not ok'
185 result_ "$r" "direct run display re-exec message [args: a b]"
187 ./checkargs.sh a '' -e && r='ok' || r='not ok'
188 result_ "$r" "direct re-exec preserving args"
190 for sh_type in non-bash bash; do
192 if test "$sh" = :; then
193 skip_row_ 5 -r "no $sh_type shell available" "re-exec message"
194 skip_row_ 5 -r "no $sh_type shell available" "re-exec preserving args"
197 check_preserve_args ''
198 check_reexec_message '' a b c
199 check_preserve_args .
200 check_reexec_message . a b c
202 check_preserve_args ..
203 check_reexec_message .. a b c
205 check_preserve_args "$cwd"
206 check_reexec_message "$cwd" a -b c-
207 check_preserve_args sub
208 check_reexec_message sub 1 2 3 4