X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=test%2Fcommon.sh;fp=test%2Fcommon.sh;h=1c675e20f6118c04c07c35cb0fb4e8c5b0754d32;hp=0000000000000000000000000000000000000000;hb=dba2e3c8f09a64ebf3c07323f1cb5fb2fa611d12;hpb=5b32b30305e864c22241dc1740a79fda9c269db7 diff --git a/test/common.sh b/test/common.sh new file mode 100644 index 0000000..1c675e2 --- /dev/null +++ b/test/common.sh @@ -0,0 +1,33 @@ +# Common helper routines for test shell scripts -- intended to be sourced by them +test_skip () +{ + 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" +} + +require_prog () +{ + if [ -z "$(findprog $1)" ]; then + test_skip "missing $1" + fi +}