1 # Common helper routines for test shell scripts -- intended to be sourced by them
5 #### The following exported variables are set by "make check". Ensure
6 #### that they are set here so that individual tests can be run
7 #### outside of make. Requires that MH_OBJ_DIR be set on entry.
8 test -z "$MH_TEST_DIR" && MH_TEST_DIR="$MH_OBJ_DIR/test/testdir"
9 test -z "$prefix" && prefix=@prefix@
10 test -z "$datarootdir" && datarootdir=@datarootdir@
11 test -z "$exec_prefix" && exec_prefix=@exec_prefix@
12 test -z "$auxexecdir" && auxexecdir="@libdir@"
13 test -z "$bindir" && bindir="@bindir@"
14 test -z "$mandir" && mandir="@mandir@"
15 test -z "$sysconfdir" && sysconfdir="@sysconfdir@"
16 test -z "$pagerpath" && pagerpath="@pagerpath@"
17 export MH_TEST_DIR auxexecdir bindir mandir sysconfdir pagerpath
19 test -z "$MH_INST_DIR" && MH_INST_DIR=${MH_TEST_DIR}/inst
25 #### Output just the checksum. If the filename needs to appear on
26 #### the same line, the caller needs to add it. This avoids
27 #### differences due to a leading '*' binary file indicator, for
28 #### text files, on some platforms (Cygwin).
29 @MD5SUM@ $* | @MD5FMT@ | cut -d ' ' -f 1
35 echo "$Test $0 SKIP ($WHY)"
39 # portable implementation of 'which' utility
50 if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
51 printf '%s\n' "$D/$PROG"
60 if [ -z "$(findprog $1)" ]; then
61 test_skip "missing $1"
65 # Some stuff for doing silly progress indicators
71 RANGE="$(($LAST - $FIRST))"
72 PROG="$(($THIS - $FIRST))"
73 # this automatically rounds to nearest integer
74 PERC="$(((100 * $PROG) / $RANGE))"
75 # note \r so next update will overwrite
76 printf "%3d%%\r" $PERC
84 #### check() requires two arguments, each the name of a file to be
86 #### If the same, the second file is removed. And the first file is
87 #### removed unless the optional third argument has a value of
89 #### If different, global variable "failed" is incremented.
91 #### POSIX diff should support -c.
92 if diff -c "$1" "$2"; then
93 test $# -lt 3 -o "$3" != 'keep first' && rm -f "$1"
96 echo "$0: test failed, outputs are in $1 and $2."
97 failed=`expr ${failed:-0} + 1`
101 #### run_test() requires two arguments, the first is a program and
102 #### arguments, the second is its expected one-line output string.
103 #### If the actual output does not match that string:
104 #### an error message is printed and global variable "failed" is incremented;
105 #### if there is an optional third argument, it is used in the error message.
107 #### Invert exit status to prevent triggering immediate exit due to set -e.
108 ! actual_output="`$1 2>&1`"
109 if test x"$actual_output" != x"$2"; then
110 echo "$0: ${3:-\"$1\"} expected:" 1>&2
112 echo "but instead got:" 1>&2
113 echo " '$actual_output'" 1>&2
114 failed=`expr ${failed:-0} + 1`
120 export MH=${MH_TEST_DIR}/Mail/.mh_profile
121 export MHMTSCONF=${MH_INST_DIR}${sysconfdir}/mts.conf
122 export PATH=${MH_INST_DIR}${bindir}:${PATH}
123 export MH_LIB_DIR=${MH_INST_DIR}${auxexecdir}
128 if [ ! -d ${MH_INST_DIR}${bindir} ]; then
129 (cd ${MH_OBJ_DIR} && make DESTDIR=${MH_INST_DIR} install) || exit 1
132 # clean old test data
133 trap "rm -rf $MH_TEST_DIR/Mail; exit \$status" 0
135 mkdir $MH_TEST_DIR/Mail || exit 1
136 cat > $MH <<EOF || exit 1
137 Path: ${MH_TEST_DIR}/Mail
138 mhlproc: ${MH_LIB_DIR}/mhl
139 showproc: ${MH_LIB_DIR}/mhl
140 postproc: ${MH_LIB_DIR}/post
141 fileproc: ${MH_INST_DIR}${bindir}/refile
144 for f in MailAliases components digestcomps distcomps forwcomps mhl.body \
145 mhl.digest mhl.format mhl.forward mhl.headers mhl.reply \
146 mhn.defaults rcvdistcomps replcomps replgroupcomps scan.MMDDYY \
147 scan.YYYYMMDD scan.default scan.mailx scan.nomime scan.size \
148 scan.time scan.timely scan.unseen
150 cp ${MH_INST_DIR}${sysconfdir}/${f} ${MH_TEST_DIR}/Mail || exit 1
153 folder -create +inbox > /dev/null
154 # create 10 basic messages
155 for i in 1 2 3 4 5 6 7 8 9 10;
157 cat > $MH_TEST_DIR/Mail/inbox/$i <<EOF || exit 1
158 From: Test$i <test$i@example.com>
159 To: Some User <user@example.com>
160 Date: Fri, 29 Sep 2006 00:00:00
161 Subject: Testing message $i
163 This is message number $i