summaryrefslogtreecommitdiff
path: root/t/self-check-reexec.tap
diff options
context:
space:
mode:
authorStefano Lattarini <stefano.lattarini@gmail.com>2012-04-06 13:12:25 +0200
committerStefano Lattarini <stefano.lattarini@gmail.com>2012-04-06 21:29:30 +0200
commit8a5096d150cf9803b8963768b7366cd68edcce03 (patch)
treea49c0e54876b8b9877d7ca2df386377e7b6037d1 /t/self-check-reexec.tap
parentf8e822bbc197f01fc722aa6def7cddb4182e3c66 (diff)
downloadautomake-8a5096d150cf9803b8963768b7366cd68edcce03.tar.gz
tests: rename 'tests/' => 't/', '*.test' => '*.sh'
When we (soon) convert the Automake testsuite to a non-recursive make setup, we'll have to fix the entries of $(TESTS) to be prepended with the subdirectory they are in; this will increase the length of $(TESTS), and thus increase the possibility of exceeding the command-line length limits on some systems (most notably, MinGW/MSYS). See automake bug#7868 for more information. Thus we rename the 'tests/' subdirectory to 't/', and each 'x.test' script in there to 'x.sh'; this way, the $(TESTS) entry 'foo.test' will become 't/foo.sh', which have the same number of characters. * tests/: Rename ... * t/: ... to this. * t/*.test: Rename ... * t/*.sh: ... to this. * t/.gitignore: Removed as obsolete. * t/defs: Adjust. * t/gen-testsuite-part: Likewise. * t/list-of-tests.mk: Likewise. * t/ccnoco.sh: Likewise. * t/ccnoco3.sh: Likewise. * t/self-check-cleanup.tap: Likewise. * t/self-check-dir.tap: Likewise. * t/self-check-me.tap: Likewise. * t/self-check-reexec.tap: Likewise. * README: Likewise. * bootstrap: Likewise * configure.ac: Likewise. * Makefile.am: Likewise. * .gitignore: Likewise. * syntax-check.mk: Likewise. Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Diffstat (limited to 't/self-check-reexec.tap')
-rwxr-xr-xt/self-check-reexec.tap205
1 files changed, 205 insertions, 0 deletions
diff --git a/t/self-check-reexec.tap b/t/self-check-reexec.tap
new file mode 100755
index 000000000..48e5cfb2e
--- /dev/null
+++ b/t/self-check-reexec.tap
@@ -0,0 +1,205 @@
+#! /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 $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 ../defs .
+
+#
+# Search for required bash and non-bash shells.
+#
+
+for bash_shell in "$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 "$SHELL" sh ksh ash dash pdksh :; do
+ test "$non_bash_shell" = : && break
+ $non_bash_shell -c 'exit 0' || continue
+ $non_bash_shell -c 'test -n "$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
+
+sed -e "s|^testbuilddir=.*|testbuilddir='$cwd'|" \
+ -e 's|^SHELL=.*$|SHELL=bash; export SHELL|' \
+ < ../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|^testbuilddir=.*|testbuilddir='$cwd'|" \
+ < ../defs-static > defs-static
+sed -e "s|^testbuilddir=.*|testbuilddir='$cwd/sub'|" \
+ < ../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 $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 $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
+
+: