X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=test%2Fcommon.sh;h=7f09867ea9e744df8ae592c0234e6206391cd932;hp=5d46c8c2662fdd169d0151c49c2dee0f3b805111;hb=92009746ef66e8a9a9dc6643845e839e0debaf18;hpb=1b97b10a0b0455edff975e23e2783c0c0b4b60d4 diff --git a/test/common.sh b/test/common.sh index 5d46c8c..7f09867 100644 --- a/test/common.sh +++ b/test/common.sh @@ -1,52 +1,54 @@ -# 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 () +require_prog() { - if [ -z "$(findprog $1)" ]; then - test_skip "missing $1" - fi + if [ -z "$(findprog $1)" ]; then + test_skip "missing $1" + fi } # Some stuff for doing silly progress indicators -progress_update () +progress_update() { - THIS="$1" - FIRST="$2" - LAST="$3" - RANGE="$(($LAST - $FIRST))" - PROG="$(($THIS - $FIRST))" - # this automatically rounds to nearest integer - PERC="$(((100 * $PROG) / $RANGE))" - # note \r so next update will overwrite - printf "%3d%%\r" $PERC + 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 } -progress_done () +progress_done() { - printf "100%%\n" + printf "100%%\n" }