]> diplodocus.org Git - nmh/blob - test/common.sh
Sigh. I put the documentation about the -tls switch in the long description,
[nmh] / test / common.sh
1 # Common helper routines for test shell scripts -- intended to be sourced by them
2 test_skip ()
3 {
4 WHY="$1"
5 echo "$Test $0 SKIP ($WHY)"
6 exit 120
7 }
8
9 # portable implementation of 'which' utility
10 findprog()
11 {
12 FOUND=
13 PROG="$1"
14 IFS_SAVE="$IFS"
15 IFS=:
16 for D in $PATH; do
17 if [ -z "$D" ]; then
18 D=.
19 fi
20 if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
21 printf '%s\n' "$D/$PROG"
22 break
23 fi
24 done
25 IFS="$IFS_SAVE"
26 }
27
28 require_prog ()
29 {
30 if [ -z "$(findprog $1)" ]; then
31 test_skip "missing $1"
32 fi
33 }
34
35 # Some stuff for doing silly progress indicators
36 progress_update ()
37 {
38 THIS="$1"
39 FIRST="$2"
40 LAST="$3"
41 RANGE="$(($LAST - $FIRST))"
42 PROG="$(($THIS - $FIRST))"
43 # this automatically rounds to nearest integer
44 PERC="$(((100 * $PROG) / $RANGE))"
45 # note \r so next update will overwrite
46 printf "%3d%%\r" $PERC
47 }
48
49 progress_done ()
50 {
51 printf "100%%\n"
52 }