Make $? compatible with set -e in system tests

Ensure handling of return code from previous command doesn't cause the
script to halt if that code is non-zero when running with `set -e`.
This commit is contained in:
Tom Krizek
2023-06-09 10:57:34 +02:00
parent 1436025e20
commit 837c190d9e
19 changed files with 89 additions and 99 deletions

View File

@@ -16,7 +16,8 @@
status=0
checkout() {
case $? in
rc=$1
case $rc in
0) : ok ;;
*) echo_i "failed"
status=$((status + 1))
@@ -36,12 +37,12 @@ algo=1 flags=0 iters=12 salt="aabbccdd"
while read name hash
do
echo_i "checking $NSEC3HASH $name"
out=`$NSEC3HASH $salt $algo $iters $name`
checkout
{ out=`$NSEC3HASH $salt $algo $iters $name`; rc=$?; } || true
checkout $rc
echo_i "checking $NSEC3HASH -r $name"
out=`$NSEC3HASH -r $algo $flags $iters $salt $name`
checkout
{ out=`$NSEC3HASH -r $algo $flags $iters $salt $name`; rc=$?; } || true
checkout $rc
done <<EOF
*.w.example R53BQ7CC2UVMUBFU5OCMM6PERS9TK9EN
@@ -60,45 +61,47 @@ EOF
# test empty salt
checkempty() {
hash=CK0POJMG874LJREF7EFN8430QVIT8BSM checkout &&
hash=- checkout
rc=$1
hash=CK0POJMG874LJREF7EFN8430QVIT8BSM checkout $rc &&
hash=- checkout $rc
}
name=com algo=1 flags=1 iters=0
echo_i "checking $NSEC3HASH '' $name"
out=`$NSEC3HASH '' $algo $iters $name`
checkempty
{ out=`$NSEC3HASH '' $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH - $name"
out=`$NSEC3HASH - $algo $iters $name`
checkempty
{ out=`$NSEC3HASH - $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -- '' $name"
out=`$NSEC3HASH -- '' $algo $iters $name`
checkempty
{ out=`$NSEC3HASH -- '' $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -- - $name"
out=`$NSEC3HASH -- - $algo $iters $name`
checkempty
{ out=`$NSEC3HASH -- - $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -r '' $name"
out=`$NSEC3HASH -r $algo $flags $iters '' $name`
checkempty
{ out=`$NSEC3HASH -r $algo $flags $iters '' $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -r - $name"
out=`$NSEC3HASH -r $algo $flags $iters - $name`
checkempty
{ out=`$NSEC3HASH -r $algo $flags $iters - $name`; rc=$?; } || true
checkempty $rc
checkfail() {
case $? in
rc=$1
case $rc in
0) echo_i "failed to fail"
status=$((status + 1))
return 1 ;;
esac
}
echo_i "checking $NSEC3HASH missing args"
out=`$NSEC3HASH 00 1 0 2>&1`
checkfail
{ out=`$NSEC3HASH 00 1 0 2>&1`; rc=$?; } || true
checkfail $rc
echo_i "checking $NSEC3HASH extra args"
out=`$NSEC3HASH 00 1 0 two names 2>&1`
checkfail
{ out=`$NSEC3HASH 00 1 0 two names 2>&1`; rc=$?; } || true
checkfail $rc
echo_i "checking $NSEC3HASH bad option"
out=`$NSEC3HASH -? 2>&1`
checkfail
{ out=`$NSEC3HASH -? 2>&1`; rc=$?; } || true
checkfail $rc
echo_i "exit status: $status"
[ $status -eq 0 ] || exit 1