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
32 #### Use built-in $((...)) in test suite if shell supports it.
33 #### Borrowed from configure's as_fn_arith. The result is placed
34 #### in global arith_val.
35 #### Detected at run-time instead of by configure to allow testing
36 #### with different shells.
37 if (eval "test \$(( 1 + 1 )) = 2" 2>/dev/null); then
38 eval 'arith_eval () { arith_val=$(( $* )); }'
40 arith_eval () { arith_val=`expr "$@" || test $? -eq 1`; }
46 echo "$Test $0 SKIP ($WHY)"
50 # portable implementation of 'which' utility
61 if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
62 printf '%s\n' "$D/$PROG"
71 if [ -z `findprog $1` ]; then
72 test_skip "missing $1"
76 # Some stuff for doing silly progress indicators
82 arith_eval $LAST - $FIRST; RANGE=$arith_val
83 arith_eval $THIS - $FIRST; PROG=$arith_val
84 # this automatically rounds to nearest integer
85 arith_eval 100 \* $PROG / $RANGE; PERC=$arith_val
86 # note \r so next update will overwrite
87 printf "%3d%%\r" $PERC
95 #### check() requires two arguments, each the name of a file to be
97 #### If the same, the second file is removed. And the first file is
98 #### removed unless the optional third argument has a value of
100 #### If different, global variable "failed" is incremented.
102 #### POSIX diff should support -c.
103 if diff -c "$1" "$2"; then
104 test $# -lt 3 -o "$3" != 'keep first' && rm -f "$1"
107 echo "$0: test failed, outputs are in $1 and $2."
108 failed=`expr ${failed:-0} + 1`
112 #### run_test() requires two arguments, the first is a program and
113 #### arguments, the second is its expected one-line output string.
114 #### If the actual output does not match that string:
115 #### an error message is printed and global variable "failed" is incremented;
116 #### if there is an optional third argument, it is used in the error message.
119 actual_output=`$1 2>&1`
121 if test x"$actual_output" != x"$2"; then
122 echo "$0: ${3:-\"$1\"} expected:" 1>&2
124 echo "but instead got:" 1>&2
125 echo " '$actual_output'" 1>&2
126 failed=`expr ${failed:-0} + 1`
132 MH=${MH_TEST_DIR}/Mail/.mh_profile
133 MHMTSCONF=${MH_INST_DIR}${sysconfdir}/mts.conf
134 PATH=${MH_INST_DIR}${bindir}:${PATH}
135 MH_LIB_DIR=${MH_INST_DIR}${auxexecdir}
136 export MH MHMTSCONF MH_LIB_DIR
141 if [ -d ${MH_INST_DIR}${bindir} ]; then
144 (cd ${MH_OBJ_DIR} && make DESTDIR=${MH_INST_DIR} install) || exit 1
147 # clean old test data
148 trap "rm -rf $MH_TEST_DIR/Mail; exit \$status" 0
150 mkdir $MH_TEST_DIR/Mail || exit 1
151 cat > $MH <<EOF || exit 1
152 Path: ${MH_TEST_DIR}/Mail
153 mhlproc: ${MH_LIB_DIR}/mhl
154 showproc: ${MH_LIB_DIR}/mhl
155 postproc: ${MH_LIB_DIR}/post
156 fileproc: ${MH_INST_DIR}${bindir}/refile
159 for f in MailAliases components digestcomps distcomps forwcomps mhl.body \
160 mhl.digest mhl.format mhl.forward mhl.headers mhl.reply \
161 mhn.defaults rcvdistcomps replcomps replgroupcomps scan.MMDDYY \
162 scan.YYYYMMDD scan.default scan.mailx scan.nomime scan.size \
163 scan.time scan.timely scan.unseen
165 cp ${MH_INST_DIR}${sysconfdir}/${f} ${MH_TEST_DIR}/Mail || exit 1
168 folder -create +inbox > /dev/null
169 # create 10 basic messages
170 for i in 1 2 3 4 5 6 7 8 9 10;
172 cat > $MH_TEST_DIR/Mail/inbox/$i <<EOF || exit 1
173 From: Test$i <test$i@example.com>
174 To: Some User <user@example.com>
175 Date: Fri, 29 Sep 2006 00:00:00
176 Subject: Testing message $i
178 This is message number $i