+2011-08-14 Stefano Lattarini <stefano.lattarini@gmail.com>
+
+ 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 <stefano.lattarini@gmail.com>
maintcheck: look for TAP-based tests without TAP plan
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
# 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
# signal shall be reported as greater than 128".
command_ok_ "kill -$sig" test $rc -gt 128
fi
-
+ unset rc
done
: Non-existent program.
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
:
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-'
# 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
: