Make the test suite work on systems other than Linux. Still needs work.
[mmh] / test / common.sh.in
1 # Common helper routines for test shell scripts -- intended to be sourced by them
2
3 output_md5()
4 {
5   @MD5SUM@ $* | @MD5FMT@
6 }
7
8 test_skip ()
9 {
10   WHY="$1"
11   echo "$Test $0 SKIP ($WHY)"
12   exit 120
13 }
14
15 # portable implementation of 'which' utility
16 findprog()
17 {
18   FOUND=
19   PROG="$1"
20   IFS_SAVE="$IFS"
21   IFS=:
22   for D in $PATH; do
23     if [ -z "$D" ]; then
24       D=.
25     fi
26     if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
27       printf '%s\n' "$D/$PROG"
28       break
29     fi
30   done
31   IFS="$IFS_SAVE"
32 }
33
34 require_prog ()
35 {
36   if [ -z "$(findprog $1)" ]; then
37     test_skip "missing $1"
38   fi
39 }
40
41 # Some stuff for doing silly progress indicators
42 progress_update ()
43 {
44   THIS="$1"
45   FIRST="$2"
46   LAST="$3"
47   RANGE="$(($LAST - $FIRST))"
48   PROG="$(($THIS - $FIRST))"
49   # this automatically rounds to nearest integer
50   PERC="$(((100 * $PROG) / $RANGE))"
51   # note \r so next update will overwrite
52   printf "%3d%%\r" $PERC
53 }
54
55 progress_done ()
56 {
57   printf "100%%\n"
58 }