From 15d00e0dcf59f6f5a6921165949bb1ebc296a7a0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 28 Nov 2021 18:06:00 -0600 Subject: [PATCH] Teach test suite to combine VERBOSE options, ala VERBOSE=allquiet --- scripts/runtest.sh | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/scripts/runtest.sh b/scripts/runtest.sh index f1475f21..5a647677 100644 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -8,10 +8,11 @@ # The following environment variables enable optional behavior in "testing": # DEBUG - Show every command run by test script. -# VERBOSE - "all" continue after failed test -# "fail" show diff and stop at first failed test +# VERBOSE - "all" continue after failed test +# "fail" show diff and stop at first failed test # "nopass" don't show successful tests -# "quiet" like all but just print FAIL (no diff -u). +# "quiet" don't show diff -u for failures +# "spam" show passing test command lines # # The "testcmd" function takes five arguments: # $1) Description to display when running command @@ -68,9 +69,14 @@ optional() SKIP=1 } +verbose_has() +{ + [ "${VERBOSE/$1/}" != "$VERBOSE" ] +} + skipnot() { - if [ "$VERBOSE" == quiet ] + if verbose_has quiet then eval "$@" 2>/dev/null else @@ -105,7 +111,7 @@ wrong_args() # Announce success do_pass() { - [ "$VERBOSE" != "nopass" ] && printf "%s\n" "$SHOWPASS: $NAME" + ! verbose_has nopass && printf "%s\n" "$SHOWPASS: $NAME" } # The testing function @@ -121,7 +127,7 @@ testing() if [ -n "$SKIP" -o -n "$SKIP_HOST" -a -n "$TEST_HOST" -o -n "$SKIPNEXT" ] then - [ "$VERBOSE" != quiet ] && printf "%s\n" "$SHOWSKIP: $NAME" + verbose_has quiet && printf "%s\n" "$SHOWSKIP: $NAME" unset SKIPNEXT return 0 fi @@ -140,16 +146,16 @@ testing() FAILCOUNT=$(($FAILCOUNT+1)) printf "%s\n" "$SHOWFAIL: $NAME" else - [ "$VERBOSE" != "nopass" ] && printf "%s\n" "$SHOWPASS: $NAME" + ! verbose_has nopass && printf "%s\n" "$SHOWPASS: $NAME" fi - if [ "$VERBOSE" != quiet ] && [ -n "$DIFF" -o "$VERBOSE" == spam ] + if ! verbose_has quiet && { [ -n "$DIFF" ] || verbose_has spam; } then [ ! -z "$4" ] && printf "%s\n" "echo -ne \"$4\" > input" printf "%s\n" "echo -ne '$5' |$EVAL $2" [ -n "$DIFF" ] && printf "%s\n" "$DIFF" fi - [ -n "$DIFF" -a "$VERBOSE" != all ] && exit 1 + [ -n "$DIFF" ] && ! verbose_has all && exit 1 rm -f input expected actual [ -n "$DEBUG" ] && set +x @@ -176,7 +182,7 @@ do_fail() echo "Expected '$CASE'" echo "Got '$A'" fi - [ "$VERBOSE" != all ] && [ "$VERBOSE" != quiet ] && exit 1 + ! verbose_has all && exit 1 } # txpect NAME COMMAND [I/O/E/Xstring]... @@ -208,7 +214,7 @@ txpect() do VERBOSITY="$VERBOSITY"$'\n'"$1" LEN=$((${#1}-1)) CASE="$1" A= B= - [ "$VERBOSE" == spam ] && echo "txpect $CASE" + verbose_has spam && echo "txpect $CASE" case ${1::1} in # send input to child @@ -222,7 +228,7 @@ txpect() [ "${1:$B:1}" == 'E' ] && O=$ERR read -t2 $LARG A <&$O X=$? - [ "$VERBOSE" == spam ] && echo "txgot $X '$A'" + verbose_has spam && echo "txgot $X '$A'" VERBOSITY="$VERBOSITY"$'\n'"$A" if [ $LEN -eq 0 ] then @@ -263,7 +269,7 @@ txpect() then do_pass else - [ "$VERBOSE" != quiet ] && echo "$VERBOSITY" >&2 + ! verbose_has quiet && echo "$VERBOSITY" >&2 fi } -- 2.39.2