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 || :
31 cp "$am_top_builddir"/t/ax/test-init.sh ${1-.}/t/ax \
32 || fatal_ "fetching 't/ax/test-init.sh' from top_builddir"
35 cwd=$(pwd) || fatal_ "getting current working directory"
37 cp "$am_top_builddir"/defs . || fatal_ "fetching 'defs' from top_builddir"
40 # Search for required bash and non-bash shells.
44 "$SHELL" "$AM_TEST_RUNNER_SHELL" bash bash3 bash4 :
46 test "$bash_shell" = : && break
47 $bash_shell --version || continue
48 $bash_shell -c 'test -n "$BASH_VERSION"' || continue
52 # This might not be optimal, but it's much better than writing wrapper
53 # scripts acting as "fake" shells.
54 for non_bash_shell in \
55 /bin/sh /bin/ksh sh ksh ash dash pdksh "$SHELL" "$AM_TEST_RUNNER_SHELL" :
57 test "$non_bash_shell" = : && break
58 $non_bash_shell -c 'exit 0' || continue
59 # Be sure to reject also any shell that is Zsh "in disguise" (as can
60 # be found on some Debian systems, where /bin/ksh can be symlinked to
61 # /bin/zsh4). This is required because our testsuite does not support
62 # older versions of Zsh, and that has caused spurious failures in the
64 $non_bash_shell -c 'test -n "$ZSH_VERSION$BASH_VERSION"' && continue
68 echo "bash_shell='$bash_shell'"
69 echo "non_bash_shell='$non_bash_shell'"
71 # This would denote an internal error.
72 if test "$bash_shell" = : && test "$non_bash_shell" = :; then
73 fatal_ "we couldn't find a bash shell nor a non-bash one"
77 # Functions used throughout the test.
88 /*) dname="absolute dir";;
96 bash) sh=$bash_shell;;
97 non-bash) sh=$non_bash_shell;;
98 *) fatal_ "get_sh: invalid shell type '$1'";;
103 # Check how to default, force or prevent a re-execution.
106 cat > need-bash.sh <<'END'
109 # Ensure that the script gets re-executed with bash. Also ensure that
110 # non-standard syntax used after the inclusion of './defs' doesn't cause
111 # non-bash shells to fail.
112 # Subshell required to prevent some shells (e.g., Solaris 10 /bin/sh)
113 # from only complaining on stderr but then exiting with exit status 0.
114 (foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION")
117 sh_var=AM_TEST_RUNNER_SHELL
118 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
119 -e "s|^$sh_var=.*$|$sh_var=bash; export $sh_var|" \
120 < "$am_top_builddir"/defs-static >defs-static
124 command_ok_ "re-exec if AM_TESTS_REEXEC=$1" \
125 env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
130 command_ok_ "don't re-exec if AM_TESTS_REEXEC=$1" \
131 not env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
134 if test "$bash_shell" = :; then
135 skip_row_ 10 -r "no bash shell found" AM_TESTS_REEXEC
136 elif test "$non_bash_shell" = :; then
137 skip_row_ 10 -r "no non-bash shell found" AM_TESTS_REEXEC
139 command_ok_ "re-exec if AM_TESTS_REEXEC unset" \
140 $non_bash_shell need-bash.sh
153 # Check message about the re-execution. Also check that arguments passed
154 # to a test script are preserved by a re-exec, even in "corner" cases.
157 cat > dummy.sh <<'END'
163 cat > checkargs.sh <<'END'
165 test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e"
168 chmod a+x dummy.sh checkargs.sh
171 cp dummy.sh checkargs.sh defs sub
172 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
173 < "$am_top_builddir"/defs-static > defs-static
174 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd/sub'|" \
175 < "$am_top_builddir"/defs-static > sub/defs-static
178 check_preserve_args ()
182 $sh "${dir}${dsep}checkargs.sh" a '' -e && r='ok' || r='not ok'
183 result_ "$r" "$sh re-exec preserving args [$dname]"
186 check_reexec_message ()
190 $sh "${dir}${dsep}dummy.sh" "$@" \
191 | grep "^exec $AM_TEST_RUNNER_SHELL ${dir}${dsep}dummy\\.sh $*\$" \
192 && r='ok' || r='not ok'
193 result_ "$r" "$sh display re-exec message [$dname] [args: $*]"
197 | grep "^exec $AM_TEST_RUNNER_SHELL \\./dummy\\.sh a b$" \
198 && r='ok' || r='not ok'
199 result_ "$r" "direct run display re-exec message [args: a b]"
201 ./checkargs.sh a '' -e && r='ok' || r='not ok'
202 result_ "$r" "direct re-exec preserving args"
204 for sh_type in non-bash bash; do
206 if test "$sh" = :; then
207 skip_row_ 5 -r "no $sh_type shell available" "re-exec message"
208 skip_row_ 5 -r "no $sh_type shell available" "re-exec preserving args"
211 check_preserve_args ''
212 check_reexec_message '' a b c
213 check_preserve_args .
214 check_reexec_message . a b c
216 check_preserve_args ..
217 check_reexec_message .. a b c
219 check_preserve_args "$cwd"
220 check_reexec_message "$cwd" a -b c-
221 check_preserve_args sub
222 check_reexec_message sub 1 2 3 4