test/common.sh: new file for common utility functions for the test scripts.
[mmh] / test / common.sh
diff --git a/test/common.sh b/test/common.sh
new file mode 100644 (file)
index 0000000..1c675e2
--- /dev/null
@@ -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
+}