From: Stefano Lattarini Date: Tue, 7 Jun 2011 14:36:40 +0000 (+0200) Subject: testsuite: use 'fatal_' and 'framework_failure_' for hard errors X-Git-Tag: ng-0.5a~89^2~193 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2154d14b618540a8e32f745f0f29ab924de91b2;p=thirdparty%2Fautomake.git testsuite: use 'fatal_' and 'framework_failure_' for hard errors * tests/defs (require_xsi): Use `fatal_', not `framework_failure', to report an invalid usage. * tests/remake-gnulib-remove-header.test: Prefer using `fatal_' with a proper error message over a direct call to `Exit 99'. * tests/pr8365-remake-timing.test: Likewise. * tests/cygnus-imply-foreign.test: Likewise. * tests/missing6.test: Likewise. * tests/cond8.test: Likewise. * tests/cond33.test: Likewise. * tests/python-virtualenv.test: Prefer using `framework_failure_' with a proper error message over a direct call to `Exit 99'. * tests/instspc-tests.sh: Prefer using `framework_failure_' and `fatal_' over direct calls to `Exit 99'. (fatal_): Define this (which is a simplified version of the one in `tests/defs') for early uses (i.e., before `tests/defs' gets sourced). * tests/depmode-tests.sh: Likewise. Also, simplify the 'get_depmodes' function and calls to it accordingly. --- diff --git a/ChangeLog b/ChangeLog index 40c0d6597..a7f9a4aa0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2011-06-08 Stefano Lattarini + + testsuite: use 'fatal_' and 'framework_failure_' for hard errors + * tests/defs (require_xsi): Use `fatal_', not `framework_failure', + to report an invalid usage. + * tests/remake-gnulib-remove-header.test: Prefer using `fatal_' + with a proper error message over a direct call to `Exit 99'. + * tests/pr8365-remake-timing.test: Likewise. + * tests/cygnus-imply-foreign.test: Likewise. + * tests/missing6.test: Likewise. + * tests/cond8.test: Likewise. + * tests/cond33.test: Likewise. + * tests/python-virtualenv.test: Prefer using `framework_failure_' + with a proper error message over a direct call to `Exit 99'. + * tests/instspc-tests.sh: Prefer using `framework_failure_' and + `fatal_' over direct calls to `Exit 99'. + (fatal_): Define this (which is a simplified version of the one + in `tests/defs') for early uses (i.e., before `tests/defs' + gets sourced). + * tests/depmode-tests.sh: Likewise. Also, simplify the + 'get_depmodes' function and calls to it accordingly. + 2011-06-08 Stefano Lattarini self tests: check new 'fatal_' function diff --git a/tests/cond33.test b/tests/cond33.test index 126a4c198..149795d49 100755 --- a/tests/cond33.test +++ b/tests/cond33.test @@ -47,7 +47,7 @@ $ACLOCAL $AUTOCONF $AUTOMAKE -cwd=`pwd` || Exit 99 +cwd=`pwd` || fatal_ "cannot get current directory" mkdir nowhere chmod a-w nowhere diff --git a/tests/cond8.test b/tests/cond8.test index 3fe7b5c9e..07bf2d0d2 100755 --- a/tests/cond8.test +++ b/tests/cond8.test @@ -59,7 +59,7 @@ END cp x.c y.c -instdir=`pwd`/_inst || Exit 99 +instdir=`pwd`/_inst || fatal_ "cannot get current directory" # Skip the rest of the test in case of e.g. missing C compiler. ./configure --prefix="$instdir" x=yes || Exit $? diff --git a/tests/cygnus-imply-foreign.test b/tests/cygnus-imply-foreign.test index 9a20f21e0..1a8d7d3ba 100755 --- a/tests/cygnus-imply-foreign.test +++ b/tests/cygnus-imply-foreign.test @@ -51,7 +51,8 @@ mv -f Makefile.sav Makefile.am # Try again, this time enabling cygnus mode from configure.in. cp configure.in configure.sav sed 's/^AM_INIT_AUTOMAKE$/&([gnits cygnus])/' configure.sav >configure.in -cmp configure.in configure.sav && Exit 99 # sanity check +cmp configure.in configure.sav && fatal_ 'failed to edit configure.in' + $ACLOCAL --force $AUTOMAKE -Werror mv -f configure.sav configure.in diff --git a/tests/defs b/tests/defs index b65989a9b..df62751ef 100644 --- a/tests/defs +++ b/tests/defs @@ -306,7 +306,7 @@ get_shell_script () # Skip the test if the given shell fails to support common XSI constructs. require_xsi () { - test $# -eq 1 || framework_failure_ "require_xsi needs exactly one arg" + test $# -eq 1 || fatal_ "require_xsi needs exactly one argument" echo "$me: trying some XSI constructs with $1" $1 -c "$xsi_shell_code" || skip_ "$1 lacks XSI features" } diff --git a/tests/depmod-tests.sh b/tests/depmod-tests.sh index 36b57190f..a21f6182f 100755 --- a/tests/depmod-tests.sh +++ b/tests/depmod-tests.sh @@ -62,10 +62,14 @@ fi set -e +# We need this early. It will be overridden when we source ./defs below, +# which will offer a more proper implementation. +fatal_ () { echo "$0: $*" >&2; exit 99; } + case $# in - 0) echo "$0: missing argument" >&2; exit 99;; + 0) fatal_ "missing argument";; 1) ;; - *) echo "$0: too many arguments" >&2; exit 99;; + *) fatal_ "too many arguments";; esac case $1 in @@ -77,8 +81,7 @@ case $1 in depmode=`expr /"$1" : '.*/depcomp-\(.*\)\.depmod'` ;; *) - echo "$0: invalid argument '$1'" >&2 - exit 99 + fatal_ "invalid argument '$1'" ;; esac @@ -136,7 +139,7 @@ END : > success } -# Usage: get_depmodes DEPCOMP-FILE PROGRAM-NAME +# Usage: get_depmodes DEPCOMP-FILE get_depmodes () { # Keep this in sync with the contents of depend.m4. @@ -144,10 +147,8 @@ get_depmodes () | grep -v '^none$'` \ && : Turn newlines and tabs into spaces, and strip extra whitespace. \ && all_depmodes=`echo $all_depmodes` \ - && test -n "$all_depmodes" || { - echo "$2: failed to extract list of valid depmodes from '$1'" >&2 - exit 99 - } + && test -n "$all_depmodes" \ + || fatal_ "can't extract list of valid depmodes from '$1'" } if test x"$action" = x"generate-makefile"; then @@ -182,8 +183,9 @@ set -e # the files we need. So remove the other files created by ./defs. And # check we really are in a temporary `*.dir' directory in the build tree, # since the last thing we want is to remove some random user files! -test -f ../defs-static && test -f ../defs || Exit 99 -case `pwd` in *.dir);; *) Exit 99;; esac +test -f ../defs-static && test -f ../defs \ + && case `pwd` in *.dir) :;; *) false;; esac \ + || fatal_ "running from the wrong directory" rm -f * if test x"$action" = x"generate-data"; then @@ -194,18 +196,17 @@ if test x"$action" = x"generate-data"; then Exit 0 fi -get_depmodes "$top_testsrcdir/lib/depcomp" "$me" +get_depmodes "$top_testsrcdir/lib/depcomp" case " $all_depmodes " in *" $depmode "*) ;; - *) echo "$me: invalid depmode '$depmode'" >&2; exit 99;; + *) fatal_ "invalid depmode '$depmode'";; esac ### If we are still here, we have to run a test ... -test -f ../depmod-data.dir/success || { - echo "$me: setup by depmod-data.test failed" >&2 - Exit 99 -} +if test ! -f ../depmod-data.dir/success; then + framework_failure_ "depmod-data.test failure" +fi ../depmod-data.dir/configure am_cv_CC_dependencies_compiler_type=$depmode diff --git a/tests/instspc-tests.sh b/tests/instspc-tests.sh index c57efb792..9c6c96863 100755 --- a/tests/instspc-tests.sh +++ b/tests/instspc-tests.sh @@ -44,11 +44,15 @@ else fi set -e + +# We need this early. It will be overridden when we source ./defs below, +# which will offer a more proper implementation. +fatal_ () { echo "$0: $*" >&2; exit 99; } case $# in - 0) echo "$0: missing argument" >&2; exit 99;; + 0) fatal_ "missing argument";; 1) ;; - *) echo "$0: too many arguments" >&2; exit 99;; + *) fatal_ "too many arguments";; esac case $1 in @@ -64,8 +68,7 @@ case $1 in instspc_test_name=`expr /"$1" : '.*/install-\(.*\)\.instspc'` ;; *) - echo "$0: invalid argument '$1'" >&2 - exit 99 + fatal_ "invalid argument '$1'" ;; esac @@ -75,7 +78,8 @@ define_problematic_string () { tst=$1 shift - eval "instspc__$tst=\$1" || exit 99 + eval "instspc__$tst=\$1" \ + || fatal_ "define_problematic_string: bad argument: '$tst'" shift instspc_names_list="$instspc_names_list $tst" # Some of the "problematic" characters cannot be used in the name of @@ -284,8 +288,9 @@ set -e # the files we need. So remove the other files created by ./defs. And # check we really are in a temporary `*.dir' directory in the build tree, # since the last thing we want is to remove some random user files! -test -f ../defs-static && test -f ../defs || Exit 99 -case `pwd` in *.dir);; *) Exit 99;; esac +test -f ../defs-static && test -f ../defs \ + && case `pwd` in *.dir) :;; *) false;; esac \ + || fatal_ "running from the wrong directory" rm -f * if test x"$instspc_action" = x"generate-data"; then @@ -298,16 +303,13 @@ fi ### If we are still here, we have to run a test ... -eval "instspc_test_string=\${instspc__$instspc_test_name}" || Exit 99 -if test x"$instspc_test_string" = x; then - echo "$me: invalid test name: '$instspc_test_name'" >&2 - Exit 99 -fi +eval "instspc_test_string=\${instspc__$instspc_test_name}" \ + && test x"$instspc_test_string" != x \ + || fatal_ "invalid test name: '$instspc_test_name'" -test -f ../instspc-data.dir/success || { - echo "$me: setup by instspc-data.test failed" >&2 - Exit 99 -} +if test ! -f ../instspc-data.dir/success; then + framework_failure_ "instspc-data.test failure" +fi # Skip if this system doesn't support these characters in file names. mkdir "./$instspc_test_string" || Exit 77 @@ -323,8 +325,7 @@ case $instspc_action in relbuilddir=.. ;; *) - echo "$me: internal error: invalid action '$instspc_action'" - Exit 99 + fatal_ "invalid action '$instspc_action'" ;; esac diff --git a/tests/missing6.test b/tests/missing6.test index 2e257f157..b6f156238 100755 --- a/tests/missing6.test +++ b/tests/missing6.test @@ -38,7 +38,7 @@ $AUTOMAKE $MAKE sed 's/^dnl!! //' < configure.ac > configure.tmp -cmp configure.ac configure.tmp && Exit 99 # sanity check +cmp configure.ac configure.tmp && fatal_ 'failed to edit configure.ac' mv -f configure.tmp configure.ac $MAKE 2>stderr || { cat stderr >&2; Exit 1; } diff --git a/tests/pr8365-remake-timing.test b/tests/pr8365-remake-timing.test index 5dbebc630..f549bf146 100755 --- a/tests/pr8365-remake-timing.test +++ b/tests/pr8365-remake-timing.test @@ -42,7 +42,8 @@ $AUTOCONF ./configure $MAKE Makefile -$EGREP 'FOOBAR|zardoz' Makefile && Exit 99 # Sanity check. +# Sanity check. +$EGREP 'FOOBAR|zardoz' Makefile && fatal_ 'unexpected AC_SUBST in Makefile' echo 'AC_SUBST([FOOBAR])' >> configure.in diff --git a/tests/python-virtualenv.test b/tests/python-virtualenv.test index c36c2b770..5ddd8fb72 100755 --- a/tests/python-virtualenv.test +++ b/tests/python-virtualenv.test @@ -30,7 +30,9 @@ virtualenv --verbose virtenv && test -f virtenv/bin/activate \ # Activate the virtualenv. . ./virtenv/bin/activate # Sanity check. -test -n "$VIRTUAL_ENV" || Exit 99 +if test -z "$VIRTUAL_ENV"; then + framework_failure_ "can't activate python virtual environment" +fi cwd=`pwd` py_version=`python -c 'import sys; print("%u.%u" % tuple(sys.version_info[:2]))'` diff --git a/tests/remake-gnulib-remove-header.test b/tests/remake-gnulib-remove-header.test index de5a2fa1b..9e9b4e2d8 100755 --- a/tests/remake-gnulib-remove-header.test +++ b/tests/remake-gnulib-remove-header.test @@ -108,7 +108,7 @@ for vpath in : false; do $sleep sed -e 's/^\( *override_stdio\)=.*$/\1=false/' $srcdir/macros.m4 > t - diff $srcdir/macros.m4 t && Exit 99 # sanity check + diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4" mv -f t $srcdir/macros.m4 using_gmake || $MAKE Makefile @@ -120,7 +120,7 @@ for vpath in : false; do $sleep sed -e 's/^\( *override_stdio\)=.*$/\1=:/' $srcdir/macros.m4 > t - diff $srcdir/macros.m4 t && Exit 99 # sanity check + diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4" mv -f t $srcdir/macros.m4 using_gmake || $MAKE Makefile