automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[FYI 6/6] {testsuite-work} self tests: some minor refactoring


From: Stefano Lattarini
Subject: [FYI 6/6] {testsuite-work} self tests: some minor refactoring
Date: Sun, 14 Aug 2011 16:37:58 +0200

* 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.
---
 ChangeLog                 |    8 ++++++++
 tests/self-check-exit.tap |   30 ++++++++++++++++++------------
 tests/self-check-me.tap   |   44 +++++++++++++++++++-------------------------
 3 files changed, 45 insertions(+), 37 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b22e736..fc233ed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2011-08-14  Stefano Lattarini  <address@hidden>
 
+       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  <address@hidden>
+
        maintcheck: look for TAP-based tests without TAP plan
        * Makefile.am (sc_tests_tap_plan): New maintainer check.
        (syntax_check_rules): Add it.
diff --git a/tests/self-check-exit.tap b/tests/self-check-exit.tap
index fc3fdca..6f35e08 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 503a1d0..d7f61d6 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
 
 :
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]