#! /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 . # Sanity check for the automake testsuite. # Check that automatic re-execution of test script with the # configure-time $AM_TEST_RUNNER_SHELL. am_create_testdir=empty . ./defs || exit 1 plan_ 32 unset AM_TESTS_REEXEC BASH_VERSION || : cwd=$(pwd) || fatal_ "getting current working directory" cp "$am_top_builddir"/defs . || fatal_ "fetching 'defs' from top_builddir" # # Search for required bash and non-bash shells. # for bash_shell in \ "$SHELL" "$AM_TEST_RUNNER_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 sh ksh ash dash pdksh "$SHELL" "$AM_TEST_RUNNER_SHELL" : do test "$non_bash_shell" = : && break $non_bash_shell -c 'exit 0' || continue # Be sure to reject also any shell that is Zsh "in disguise" (as can # be found on some Debian systems, where /bin/ksh can be symlinked to # /bin/zsh4). This is required because our testsuite does not support # older versions of Zsh, and that has caused spurious failures in the # past. $non_bash_shell -c 'test -n "$ZSH_VERSION$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 sh_var=AM_TEST_RUNNER_SHELL sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \ -e "s|^$sh_var=.*$|$sh_var=bash; export $sh_var|" \ < "$am_top_builddir"/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|^am_top_builddir=.*|am_top_builddir='$cwd'|" \ < "$am_top_builddir"/defs-static > defs-static sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd/sub'|" \ < "$am_top_builddir"/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 "^exec $AM_TEST_RUNNER_SHELL ${dir}${dsep}dummy\\.sh $*\$" \ && r='ok' || r='not ok' result_ "$r" "$sh display re-exec message [$dname] [args: $*]" } ./dummy.sh a b \ | grep "^exec $AM_TEST_RUNNER_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 :