]> diplodocus.org Git - nmh/blob - test/common.sh
1c675e20f6118c04c07c35cb0fb4e8c5b0754d32
[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 }