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 $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.
35 for bash_shell in "$SHELL" bash bash3 bash4 :; do
36 test "$bash_shell" = : && break
37 $bash_shell --version || continue
38 $bash_shell -c 'test -n "$BASH_VERSION"' || continue
42 # This might not be optimal, but it's much better than writing wrapper
43 # scripts acting as "fake" shells.
44 for non_bash_shell in /bin/sh /bin/ksh "$SHELL" sh ksh ash dash pdksh :; do
45 test "$non_bash_shell" = : && break
46 $non_bash_shell -c 'exit 0' || continue
47 $non_bash_shell -c 'test -n "$BASH_VERSION"' && continue
51 echo "bash_shell='$bash_shell'"
52 echo "non_bash_shell='$non_bash_shell'"
54 # This would denote an internal error.
55 if test "$bash_shell" = : && test "$non_bash_shell" = :; then
56 fatal_ "we couldn't find a bash shell nor a non-bash one"
60 # Functions used throughout the test.
71 /*) dname="absolute dir";;
79 bash) sh=$bash_shell;;
80 non-bash) sh=$non_bash_shell;;
81 *) fatal_ "get_sh: invalid shell type '$1'";;
86 # Check how to default, force or prevent a re-execution.
89 cat > need-bash.sh <<'END'
92 # Ensure that the script gets re-executed with bash. Also ensure that
93 # non-standard syntax used after the inclusion of './defs' doesn't cause
94 # non-bash shells to fail.
95 # Subshell required to prevent some shells (e.g., Solaris 10 /bin/sh)
96 # from only complaining on stderr but then exiting with exit status 0.
97 (foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION")
100 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
101 -e 's|^SHELL=.*$|SHELL=bash; export SHELL|' \
102 < "$am_top_builddir"/defs-static >defs-static
106 command_ok_ "re-exec if AM_TESTS_REEXEC=$1" \
107 env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
112 command_ok_ "don't re-exec if AM_TESTS_REEXEC=$1" \
113 not env AM_TESTS_REEXEC="$1" $non_bash_shell need-bash.sh
116 if test "$bash_shell" = :; then
117 skip_row_ 10 -r "no bash shell found" AM_TESTS_REEXEC
118 elif test "$non_bash_shell" = :; then
119 skip_row_ 10 -r "no non-bash shell found" AM_TESTS_REEXEC
121 command_ok_ "re-exec if AM_TESTS_REEXEC unset" \
122 $non_bash_shell need-bash.sh
135 # Check message about the re-execution. Also check that arguments passed
136 # to a test script are preserved by a re-exec, even in "corner" cases.
139 cat > dummy.sh <<'END'
145 cat > checkargs.sh <<'END'
147 test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e"
150 chmod a+x dummy.sh checkargs.sh
153 cp dummy.sh checkargs.sh defs sub
154 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
155 < "$am_top_builddir"/defs-static > defs-static
156 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd/sub'|" \
157 < "$am_top_builddir"/defs-static > sub/defs-static
159 check_preserve_args ()
163 $sh "${dir}${dsep}checkargs.sh" a '' -e && r='ok' || r='not ok'
164 result_ "$r" "$sh re-exec preserving args [$dname]"
167 check_reexec_message ()
171 $sh "${dir}${dsep}dummy.sh" "$@" \
172 | grep "^dummy: exec $SHELL ${dir}${dsep}dummy\\.sh $*\$" \
173 && r='ok' || r='not ok'
174 result_ "$r" "$sh display re-exec message [$dname] [args: $*]"
177 ./dummy.sh a b | grep "^dummy: exec $SHELL \\./dummy\\.sh a b$" \
178 && r='ok' || r='not ok'
179 result_ "$r" "direct run display re-exec message [args: a b]"
181 ./checkargs.sh a '' -e && r='ok' || r='not ok'
182 result_ "$r" "direct re-exec preserving args"
184 for sh_type in non-bash bash; do
186 if test "$sh" = :; then
187 skip_row_ 5 -r "no $sh_type shell available" "re-exec message"
188 skip_row_ 5 -r "no $sh_type shell available" "re-exec preserving args"
191 check_preserve_args ''
192 check_reexec_message '' a b c
193 check_preserve_args .
194 check_reexec_message . a b c
196 check_preserve_args ..
197 check_reexec_message .. a b c
199 check_preserve_args "$cwd"
200 check_reexec_message "$cwd" a -b c-
201 check_preserve_args sub
202 check_reexec_message sub 1 2 3 4