From: Stefano Lattarini Date: Sun, 14 Aug 2011 13:18:31 +0000 (+0200) Subject: self tests: some minor refactoring X-Git-Tag: ng-0.5a~89^2~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08ddfe12f5bb387c4b1adc9e0950cada3ef0cbe0;p=thirdparty%2Fautomake.git self tests: some minor refactoring * tests/self-check-exit.tap: Disable the `errexit' shell flag; this allow to remove some boilerplate idioms and to make some code slightly less cumbersome. * tests/self-check-me.tap: Likewise. --- diff --git a/ChangeLog b/ChangeLog index b22e736b6..fc233edc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-08-14 Stefano Lattarini + + self tests: some minor refactoring + * tests/self-check-exit.tap: Disable the `errexit' shell flag; + this allow to remove some boilerplate idioms and to make some + code slightly less cumbersome. + * tests/self-check-me.tap: Likewise. + 2011-08-14 Stefano Lattarini maintcheck: look for TAP-based tests without TAP plan diff --git a/tests/self-check-exit.tap b/tests/self-check-exit.tap index fc3fdca59..6f35e0874 100755 --- a/tests/self-check-exit.tap +++ b/tests/self-check-exit.tap @@ -24,14 +24,19 @@ am_create_testdir=no plan_ 34 +# This test becomes more cumbersome if we keep the `errexit' shell flag +# set. And removing it is no big deal, as this test is a TAP-based one, +# so that false positives remain very unlikely. +set +e + AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC init='. ./defs; stderr_fileno_=2; unset am_explicit_skips' for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do for exit_cmd in "Exit $st" "sh -c 'exit $st'"; do - rc=0; $SHELL -c "$init; $exit_cmd; :" || rc=$? - command_ok_ "$exit_cmd" test $rc -eq $st + $SHELL -c "$init; $exit_cmd; :" + command_ok_ "$exit_cmd" test $? -eq $st done done @@ -41,7 +46,8 @@ for sig in 1 2 13 15; do # signal when one is sent to the child $SHELL. trap : 2 fi - rc=0; $SHELL -c "$init; kill -$sig \$\$; :" || rc=$? + $SHELL -c "$init; kill -$sig \$\$; :" + rc=$? if test $sig -eq 2; then # Reset default SIGINT handler as portably as possible. trap 2 || trap - 2 @@ -58,7 +64,7 @@ for sig in 1 2 13 15; do # signal shall be reported as greater than 128". command_ok_ "kill -$sig" test $rc -gt 128 fi - + unset rc done : Non-existent program. @@ -74,20 +80,20 @@ if $SHELL -c 'set -e; trap "exit \$?" 0; non-existent-program'; then else maybe_todo="" reason="" fi -rc=0; $SHELL -c "$init; non-existent-program; :" || rc=$? +$SHELL -c "$init; non-existent-program; :" command_ok_ "command not found" -D "$maybe_todo" -r "$reason" \ - -- test $rc -gt 0 + -- test $? -gt 0 : Non-executable command. test -f Makefile && test ! -x Makefile || \ framowork_failure_ "no proper Makefile in the current directory" -rc=0; $SHELL -c "$init; ./Makefile; :" || rc=$? -command_ok_ "permission denied" test $rc -gt 0 +$SHELL -c "$init; ./Makefile; :" +command_ok_ "permission denied" test $? -gt 0 : Syntax errors in the test code. -rc=0; $SHELL -c "$init; if :; then" || rc=$? -command_ok_ "syntax error 1" test $rc -gt 0 -rc=0; $SHELL -c "$init; fi" || rc=$? -command_ok_ "syntax error 2" test $rc -gt 0 +$SHELL -c "$init; if :; then" +command_ok_ "syntax error 1" test $? -gt 0 +$SHELL -c "$init; fi" +command_ok_ "syntax error 2" test $? -gt 0 : diff --git a/tests/self-check-me.tap b/tests/self-check-me.tap index 503a1d078..d7f61d6cf 100755 --- a/tests/self-check-me.tap +++ b/tests/self-check-me.tap @@ -24,17 +24,16 @@ am_create_testdir=no plan_ 9 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC + +# This test becomes cumbersome if we keep the `errexit' shell flag set. +# And removing it is no big deal, as this test is a TAP-based one, so +# that false positives remain very unlikely. set +e do_check () { - if $SHELL -c '. ./defs && echo me=$me' "$1" | grep "^me=$2$"; then - r='ok' - else - r='not ok' - fi - result_ "$r" "me=$1" - unset r + $SHELL -c '. ./defs && echo me=$me' "$1" | grep "^me=$2$" + command_ok_ "me=$1" test $? -eq 0 } do_check foo-bar-.test 'foo-bar-' @@ -45,31 +44,26 @@ do_check a.b.c.test 'a\.b\.c' # If we override $me, ./defs should not modify it. -if s=`$SHELL -c 'me=foo.test && . ./defs && echo me=$me' bad.test`; then - r='ok' -else - r='not ok' -fi -result_ "$r" "override of \$me before ./defs causes no error" +s=`$SHELL -c 'me=foo.test && . ./defs && echo me=$me' bad.test` +command_ok_ "override of \$me before ./defs causes no error" \ + test $? -eq 0 r='ok' -if printf '%s\n' "$s" | grep '^me=foo\.test$'; then :; else r='not ok'; fi -if printf '%s\n' "$s" | grep 'me=bad'; then r='not ok'; else :; fi +printf '%s\n' "$s" | grep '^me=foo\.test$' || r='not ok' +printf '%s\n' "$s" | grep 'me=bad' && r='not ok' result_ "$r" "override of \$me before defs is honored" +unset r # Overriding $me after sourcing ./defs-static should work. - -if s=`$SHELL -c '. ./defs-static && me=zardoz && - . ./defs && echo me=$me' bad.test`; then - r='ok' -else - r='not ok' -fi -result_ "$r" "override of \$me after defs-static causes no error" +s=`$SHELL -c '. ./defs-static && me=zardoz && + . ./defs && echo me=$me' bad.test` +command_ok_ "override of \$me after ./defs-static causes no error" \ + test $? -eq 0 r='ok' -if printf '%s\n' "$s" | grep '^me=zardoz$'; then :; else r='not ok'; fi -if printf '%s\n' "$s" | grep 'me=bad'; then r='not ok'; else :; fi +printf '%s\n' "$s" | grep '^me=zardoz$' || r='not ok' +printf '%s\n' "$s" | grep 'me=bad' && r='not ok' result_ "$r" "override of \$me after ./defs-static is honored" +unset r :