Switch to using the "inst" version of mhl for tests.
[mmh] / test / common.sh.in
1 # Common helper routines for test shell scripts -- intended to be sourced by them
2 # @configure_input@
3
4 output_md5()
5 {
6   @MD5SUM@ $* | @MD5FMT@
7 }
8
9 test_skip ()
10 {
11   WHY="$1"
12   echo "$Test $0 SKIP ($WHY)"
13   exit 77
14 }
15
16 # portable implementation of 'which' utility
17 findprog()
18 {
19   FOUND=
20   PROG="$1"
21   IFS_SAVE="$IFS"
22   IFS=:
23   for D in $PATH; do
24     if [ -z "$D" ]; then
25       D=.
26     fi
27     if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
28       printf '%s\n' "$D/$PROG"
29       break
30     fi
31   done
32   IFS="$IFS_SAVE"
33 }
34
35 require_prog ()
36 {
37   if [ -z "$(findprog $1)" ]; then
38     test_skip "missing $1"
39   fi
40 }
41
42 # Some stuff for doing silly progress indicators
43 progress_update ()
44 {
45   THIS="$1"
46   FIRST="$2"
47   LAST="$3"
48   RANGE="$(($LAST - $FIRST))"
49   PROG="$(($THIS - $FIRST))"
50   # this automatically rounds to nearest integer
51   PERC="$(((100 * $PROG) / $RANGE))"
52   # note \r so next update will overwrite
53   printf "%3d%%\r" $PERC
54 }
55
56 progress_done ()
57 {
58   printf "100%%\n"
59 }
60
61 setup_test ()
62 {
63   export MH=${MH_TEST_DIR}/Mail/.mh_profile
64   export MH_INST_DIR=${MH_TEST_DIR}/inst
65   export MHMTSCONF=${MH_INST_DIR}${sysconfdir}/mts.conf
66   export PATH=${MH_INST_DIR}${bindir}:${PATH}
67
68   if [ -z "${srcdir}" ]; then
69     echo "srcdir not set; aborting"
70     exit 1
71   fi
72
73   #
74   # Only do this once
75   #
76
77   if [ ! -d ${MH_INST_DIR}${bindir} ]; then
78     (cd ${MH_OBJ_DIR} && make DESTDIR=${MH_INST_DIR} install) || exit 1
79   fi
80
81   # clean old test data
82   trap "rm -rf $MH_TEST_DIR/Mail; exit \$status" 0
83   # setup test data
84   mkdir $MH_TEST_DIR/Mail || exit 1
85   cat > $MH <<EOF || exit 1
86 Path: ${MH_TEST_DIR}/Mail
87 mhlproc: ${MH_INST_DIR}${auxexecdir}/mhl
88 EOF
89
90   for f in MailAliases components digestcomps distcomps forwcomps mhl.body \
91            mhl.digest mhl.format mhl.forward mhl.headers mhl.reply \
92            rcvdistcomps replcomps replgroupcomps scan.MMDDYY \
93            scan.YYYYMMDD scan.default scan.mailx scan.nomime scan.size \
94            scan.time scan.timely scan.unseen
95   do
96     cp ${srcdir}/etc/${f} ${MH_TEST_DIR}/Mail || exit 1
97   done
98
99   for f in mhn.defaults mts.conf
100   do
101     cp ${MH_OBJ_DIR}/etc/${f} ${MH_TEST_DIR}/Mail || exit 1
102   done
103
104   folder -create +inbox > /dev/null
105   # create 10 basic messages
106   for i in 1 2 3 4 5 6 7 8 9 10;
107   do
108     cat > $MH_TEST_DIR/Mail/inbox/$i <<EOF || exit 1
109 From: Test$i <test$i@example.com>
110 To: Some User <user@example.com>
111 Date: Fri, 29 Sep 2006 00:00:00
112 Subject: Testing message $i
113
114 This is message number $i
115 EOF
116   done
117 }