X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=test%2Fcommon.sh;h=0fd3afb9ed3c3f4ae94148c279f3a82c92f6315e;hb=cf1205b5cbea2f0cd6ea710ec16c637df85b647c;hp=1c675e20f6118c04c07c35cb0fb4e8c5b0754d32;hpb=dba2e3c8f09a64ebf3c07323f1cb5fb2fa611d12;p=mmh diff --git a/test/common.sh b/test/common.sh index 1c675e2..0fd3afb 100644 --- a/test/common.sh +++ b/test/common.sh @@ -1,33 +1,56 @@ -# Common helper routines for test shell scripts -- intended to be sourced by them -test_skip () +# Common helper routines for test shell scripts +# -- intended to be sourced by them + +test_skip() { - WHY="$1" - echo "$Test $0 SKIP ($WHY)" - exit 120 + WHY="$1" + echo "Test $0 SKIP ($WHY)" + exit 120 } # portable implementation of 'which' utility findprog() { - FOUND= - PROG="$1" - IFS_SAVE="$IFS" - IFS=: - for D in $PATH; do - if [ -z "$D" ]; then - D=. - fi - if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then - printf '%s\n' "$D/$PROG" - break - fi - done - IFS="$IFS_SAVE" + FOUND= + PROG="$1" + IFS_SAVE="$IFS" + IFS=: + for D in $PATH; do + if [ -z "$D" ]; then + D=. + fi + if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then + printf '%s\n' "$D/$PROG" + break + fi + done + IFS="$IFS_SAVE" +} + +require_prog() +{ + if [ -z "$(findprog $1)" ]; then + test_skip "missing $1" + fi +} + +# Some stuff for doing silly progress indicators +progress_update() +{ + test -t 1 || return 0 # supress progress meter if non-interactive + THIS="$1" + FIRST="$2" + LAST="$3" + RANGE="$(expr $LAST - $FIRST ||:)" + PROG="$(expr $THIS - $FIRST ||:)" + # this automatically rounds to nearest integer + PERC="$(expr 100 \* $PROG / $RANGE ||:)" + # note \r so next update will overwrite + printf "%3d%%\r" $PERC } -require_prog () +progress_done() { - if [ -z "$(findprog $1)" ]; then - test_skip "missing $1" - fi + test -t 1 || return 0 # supress progress meter if non-interactive + printf "100%%\n" }