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 test -z "$MULTIBYTE_ENABLED" && MULTIBYTE_ENABLED="@MULTIBYTE_ENABLED@"
18 export MH_TEST_DIR auxexecdir bindir mandir sysconfdir pagerpath
19 export MULTIBYTE_ENABLED
21 test -z "$MH_INST_DIR" && MH_INST_DIR="${MH_TEST_DIR}/inst"
24 unset MHBUILD MHCONTEXT MHMTSUSERCONF MHN MHSHOW MHSTORE MHTMPDIR
25 unset MHLDEBUG MHPDEBUG MHWDEBUG MM_CHARSET
29 #### Output just the checksum. If the filename needs to appear on
30 #### the same line, the caller needs to add it. This avoids
31 #### differences due to a leading '*' binary file indicator, for
32 #### text files, on some platforms (Cygwin).
33 @MD5SUM@ $* | @MD5FMT@ | cut -d ' ' -f 1
36 #### Use built-in $((...)) in test suite if shell supports it.
37 #### Borrowed from configure's as_fn_arith. The result is placed
38 #### in global arith_val.
39 #### Detected at run-time instead of by configure to allow testing
40 #### with different shells.
41 if (eval "test \$(( 1 + 1 )) = 2" 2>/dev/null); then
42 eval 'arith_eval () { arith_val=$(( $* )); }'
44 arith_eval () { arith_val=`expr "$@" || test $? -eq 1`; }
50 echo "$Test $0 SKIP ($WHY)"
54 # portable implementation of 'which' utility
65 if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
66 printf '%s\n' "$D/$PROG"
75 if [ -z "`findprog $1`" ]; then
76 test_skip "missing $1"
80 # Some stuff for doing silly progress indicators
86 arith_eval $LAST - $FIRST; RANGE=$arith_val
87 arith_eval $THIS - $FIRST; PROG=$arith_val
88 # this automatically rounds to nearest integer
89 arith_eval 100 \* $PROG / $RANGE; PERC=$arith_val
90 # note \r so next update will overwrite
91 printf "%3d%%\r" $PERC
99 #### check() requires two arguments, each the name of a file to be
101 #### If the same, the second file is removed. And the first file is
102 #### removed unless the optional third argument has a value of
104 #### If different, global variable "failed" is incremented.
106 #### POSIX diff should support -c.
107 if diff -c "$1" "$2"; then
108 test $# -lt 3 -o "$3" != 'keep first' && rm -f "$1"
111 echo "$0: test failed, outputs are in $1 and $2."
112 failed=`expr ${failed:-0} + 1`
116 #### run_test() requires two arguments, the first is a program and
117 #### arguments, the second is its expected one-line output string.
118 #### If the actual output does not match that string:
119 #### an error message is printed and global variable "failed" is incremented;
120 #### if there is an optional third argument, it is used in the error message.
123 actual_output=`$1 2>&1`
125 if test x"$actual_output" != x"$2"; then
126 echo "$0: ${3:-\"$1\"} expected:" 1>&2
128 echo "but instead got:" 1>&2
129 echo " '$actual_output'" 1>&2
130 failed=`expr ${failed:-0} + 1`
136 MH="${MH_TEST_DIR}/Mail/.mh_profile"
137 MHMTSCONF="${MH_INST_DIR}${sysconfdir}/mts.conf"
138 PATH="${MH_INST_DIR}${bindir}:${PATH}"
139 MH_LIB_DIR="${MH_INST_DIR}${auxexecdir}"
140 export MH MHMTSCONF MH_LIB_DIR PATH
145 if [ -d "${MH_INST_DIR}${bindir}" ]; then
148 (cd "${MH_OBJ_DIR}" &&
149 make DESTDIR="${MH_INST_DIR}" SETGID_MAIL= install) ||
152 #### Don't test with sendmail because it would really send the
153 #### mail. If configured to use sendmail, change to smtp instead
154 #### so that we use fakesmtp.
155 sed -e 's/mts: *.*/mts: smtp/' "${MHMTSCONF}" >"${MHMTSCONF}.new"
156 mv -f "${MHMTSCONF}.new" "${MHMTSCONF}"
159 # clean old test data
160 trap "rm -rf '$MH_TEST_DIR/Mail'" 0
162 mkdir "$MH_TEST_DIR/Mail" || exit 1
163 cat > "$MH" <<EOF || exit 1
164 Path: ${MH_TEST_DIR}/Mail
165 buildmimeproc: ${MH_INST_DIR}${bindir}/mhbuild
166 fileproc: ${MH_INST_DIR}${bindir}/refile
167 libdir: ${MH_LIB_DIR}
168 mhbuild: -nocontentid
169 mhlproc: ${MH_LIB_DIR}/mhl
171 postproc: ${MH_LIB_DIR}/post
172 showproc: ${MH_LIB_DIR}/mhl
175 for f in MailAliases components digestcomps distcomps forwcomps mhl.body \
176 mhl.digest mhl.format mhl.forward mhl.headers mhl.reply \
177 mhn.defaults rcvdistcomps replcomps replgroupcomps scan.MMDDYY \
178 scan.YYYYMMDD scan.default scan.mailx scan.nomime scan.size \
179 scan.time scan.timely scan.unseen
181 cp "${MH_INST_DIR}${sysconfdir}/${f}" "${MH_TEST_DIR}/Mail" || exit 1
184 folder -create +inbox > /dev/null
185 # create 10 basic messages
186 for i in 1 2 3 4 5 6 7 8 9 10;
188 cat > $MH_TEST_DIR/Mail/inbox/$i <<EOF || exit 1
189 From: Test$i <test$i@example.com>
190 To: Some User <user@example.com>
191 Date: Fri, 29 Sep 2006 00:00:00
192 Subject: Testing message $i
194 This is message number $i