From: Stefano Lattarini Date: Wed, 1 Jun 2011 14:33:07 +0000 (+0200) Subject: tests: fix spurious failures in self tests X-Git-Tag: ng-0.5a~89^2~214 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=851e77acaa6a24bd9a50b5c4dc3923228c265c6c;p=thirdparty%2Fautomake.git tests: fix spurious failures in self tests Our ad-hoc usage of `tests/defs' in the testsuite's self tests stopped working properly when we made the test scripts re-execute themselves with the configure-time $SHELL. Fix this. Fixes a bug introduced by commit 'v1.11-874-g1321be7'. * tests/defs: Only check that we can find the client test script when we must re-execute it. * tests/self-check-cleanup.test: Export `AM_TESTS_REEXEC' to "no" before running the self tests. * tests/self-check-dir.test: Likewise. * tests/self-check-explicit-skips.test: Likewise. * tests/self-check-me.test: Likewise. * tests/self-check-sanity.test: Likewise. * tests/self-check-reexec.test: New test. * tests/Makefile.am (TESTS): Update. --- diff --git a/ChangeLog b/ChangeLog index 64c8892fa..7100f28cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-06-01 Stefano Lattarini + + tests: fix spurious failures in self tests + Our ad-hoc usage of `tests/defs' in the testsuite's self tests + stopped working properly when we made the test scripts re-execute + themselves with the configure-time $SHELL. Fix this. + Fixes a bug introduced by commit 'v1.11-874-g1321be7'. + * tests/defs: Only check that we can find the client test script + when we must re-execute it. + * tests/self-check-cleanup.test: Export `AM_TESTS_REEXEC' to "no" + before running the self tests. + * tests/self-check-dir.test: Likewise. + * tests/self-check-explicit-skips.test: Likewise. + * tests/self-check-me.test: Likewise. + * tests/self-check-sanity.test: Likewise. + * tests/self-check-reexec.test: New test. + * tests/Makefile.am (TESTS): Update. + 2011-06-01 Stefano Lattarini tests: prefer ulimit over timeout in test on a memory-hogging bug diff --git a/tests/Makefile.am b/tests/Makefile.am index a7958d78b..0bb993aa9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -848,6 +848,7 @@ self-check-exit.test \ self-check-explicit-skips.test \ self-check-is_newest.test \ self-check-me.test \ +self-check-reexec.test \ self-check-report.test \ self-check-sanity.test \ self-check-unindent.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 4279eea88..875b06ed9 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1136,6 +1136,7 @@ self-check-exit.test \ self-check-explicit-skips.test \ self-check-is_newest.test \ self-check-me.test \ +self-check-reexec.test \ self-check-report.test \ self-check-sanity.test \ self-check-unindent.test \ diff --git a/tests/defs b/tests/defs index 5494625b0..1f3210c5f 100644 --- a/tests/defs +++ b/tests/defs @@ -76,12 +76,6 @@ test -f "$testbuilddir/defs-static" || { exit 99 } -# Ensure we can find ourselves. -test -f "$0" || { - echo "$me: unable to find myself: $0" >&2 - exit 1 -} - ## ------------------------------------ ## ## Ensure we run with a proper shell. ## @@ -93,6 +87,11 @@ case ${AM_TESTS_REEXEC-yes} in n|no|false|0) ;; *) + # Ensure we can find ourselves. + if test ! -f "$0"; then + echo "$me: unable to find myself: $0" >&2 + exit 99 + fi AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC # Cannot simply do `opts=$-', since the content of $- is not # portable among different shells. So try to propagate only diff --git a/tests/self-check-cleanup.test b/tests/self-check-cleanup.test index 17859e9f3..f9a865895 100755 --- a/tests/self-check-cleanup.test +++ b/tests/self-check-cleanup.test @@ -30,6 +30,8 @@ sed "s|^testbuilddir=.*|testbuilddir='`pwd`'|" ../defs-static >defs-static diff ../defs-static defs-static && Exit 99 cp ../defs . +AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC + have_symlinks=false ln -s defs foo && have_symlinks=: export have_symlinks # Is used also by spawned shells. diff --git a/tests/self-check-dir.test b/tests/self-check-dir.test index ba9fd292d..0b4dd4ef3 100755 --- a/tests/self-check-dir.test +++ b/tests/self-check-dir.test @@ -22,6 +22,8 @@ set -ex +AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC + this=S_dir outcome=: pwd diff --git a/tests/self-check-explicit-skips.test b/tests/self-check-explicit-skips.test index 15bf2d9bc..d24e0ef1a 100755 --- a/tests/self-check-explicit-skips.test +++ b/tests/self-check-explicit-skips.test @@ -30,6 +30,7 @@ cp ../defs . set +e unset am_explicit_skips stderr_fileno_ +AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC $SHELL -c '. ./defs; (exit 77); exit 77' dummy.test test $? -eq 77 || Exit 1 diff --git a/tests/self-check-me.test b/tests/self-check-me.test index 141857fdc..8fd2bc09a 100755 --- a/tests/self-check-me.test +++ b/tests/self-check-me.test @@ -21,6 +21,8 @@ set -ex +AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC + $SHELL -c '. ./defs && echo me=$me' foo-bar-.test | grep '^me=foo-bar-$' $SHELL -c '. ./defs && echo me=$me' _foo__bar.test | grep '^me=_foo__bar$' $SHELL -c '. ./defs && echo me=$me' 012.test | grep '^me=012$' diff --git a/tests/self-check-reexec.test b/tests/self-check-reexec.test new file mode 100755 index 000000000..a35c143d5 --- /dev/null +++ b/tests/self-check-reexec.test @@ -0,0 +1,116 @@ +#! /bin/sh +# Copyright (C) 2011 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 $SHELL. + +. ./defs || Exit 1 + +# This is not optimal, but it's much better than writing wrapper +# scripts acting as "fake" shells. +sh -c ': ${.sh.version}' \ + && skip_ "sh is a Korn Shell" +ksh -c 'test -n "${.sh.version}"' || \ + skip_ "ksh is not a fully-fledged Korn Shell" + +cwd=`pwd` || Exit 99 + +cp ../defs . +unset AM_TESTS_REEXEC || : + +# +# Check how to default, force or prevent a re-execution. +# + +cat > run-with-ksh.test <<'END' +#!/bin/false +. ./defs +# Subshell required to prevent some shells (e.g., older bash) from +# only complaining on stderr but then exiting with exit status 0. +(test -n "${.sh.version}" && echo ${.sh.version}) +END + +sed -e "s|^testbuilddir=.*|testbuilddir='$cwd'|" \ + -e 's|^SHELL=.*$|SHELL=ksh; export SHELL|' \ + < ../defs-static >defs-static + +sh -x run-with-ksh.test + +AM_TESTS_REEXEC='' sh run-with-ksh.test +AM_TESTS_REEXEC=yes sh run-with-ksh.test +AM_TESTS_REEXEC=y sh run-with-ksh.test +AM_TESTS_REEXEC=true sh run-with-ksh.test +AM_TESTS_REEXEC=1 sh run-with-ksh.test +AM_TESTS_REEXEC=no sh run-with-ksh.test && Exit 1 +AM_TESTS_REEXEC=n sh run-with-ksh.test && Exit 1 +AM_TESTS_REEXEC=false sh run-with-ksh.test && Exit 1 +AM_TESTS_REEXEC=0 sh run-with-ksh.test && Exit 1 + +# +# Check message about the re-execution. +# + +cat > dummy.test <<'END' +#!/bin/sh +. ./defs +: +END +chmod a+x dummy.test + +mkdir sub +cp dummy.test defs sub +sed -e "s|^testbuilddir=.*|testbuilddir='$cwd'|" \ + < ../defs-static > defs-static +sed -e "s|^testbuilddir=.*|testbuilddir='$cwd/sub'|" \ + < ../defs-static > sub/defs-static + +./dummy.test a b | grep "^dummy: exec $SHELL \\./dummy\\.test a b$" + +for am_sh in sh ksh; do + $am_sh dummy.test a b c \ + | grep "^dummy: exec $SHELL dummy\\.test a b c$" + $am_sh ./dummy.test a b c \ + | grep "^dummy: exec $SHELL \\./dummy\\.test a b c$" + cd sub + $am_sh ../dummy.test a b \ + | grep "dummy: exec $SHELL \\.\\./dummy\\.test a b$" + cd .. + $am_sh "$cwd/dummy.test" a -b c- \ + | grep "^dummy: exec $SHELL $cwd/dummy\\.test a -b c-$" + $am_sh sub/dummy.test 1 2 3 4 \ + | grep "^dummy: exec $SHELL sub/dummy\\.test 1 2 3 4$" +done + +# +# Check that arguments passed to a test script are preserved by a re-exec. +# + +cat > checkargs.test <<'END' +. ./defs +test $# -eq 3 && test x"$1" = x'a' && test x"$2" = x && test x"$3" = x"-e" +END + +$SHELL checkargs.test a '' -e +$SHELL ./checkargs.test a '' -e +$SHELL "$cwd/checkargs.test" a '' -e +cd sub +$SHELL ../checkargs.test a '' -e +cd .. +cp checkargs.test sub +$SHELL sub/checkargs.test a '' -e + +: diff --git a/tests/self-check-sanity.test b/tests/self-check-sanity.test index d35432f69..3e60a6883 100755 --- a/tests/self-check-sanity.test +++ b/tests/self-check-sanity.test @@ -27,6 +27,8 @@ show_stderr () sed 's/^/ | /' stderr >&2 } +AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC + if $SHELL -c '. ../defs' dummy.test 2>stderr; then show_stderr Exit 1