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 "$MULTIBYTE_ENABLED" && MULTIBYTE_ENABLED
="@MULTIBYTE_ENABLED@"
17 test -z "$ICONV_ENABLED" && ICONV_ENABLED
="@ICONV_ENABLED@"
18 export MH_TEST_DIR auxexecdir bindir mandir sysconfdir
19 export MULTIBYTE_ENABLED ICONV_ENABLED
21 test -z "$MH_INST_DIR" && MH_INST_DIR
="${MH_TEST_DIR}/inst"
24 unset MHBUILD MHCONTEXT MHMTSUSERCONF MHN MHSHOW MHSTORE
25 unset MHLDEBUG MHPDEBUG MHWDEBUG MM_CHARSET PAGER
27 #### Use a test dir for tmp files when MHTMPDIR applies.
28 MHTMPDIR
=$MH_TEST_DIR/Mail
33 #### Output just the checksum. If the filename needs to appear on
34 #### the same line, the caller needs to add it. This avoids
35 #### differences due to a leading '*' binary file indicator, for
36 #### text files, on some platforms (Cygwin).
37 @MD5SUM@ $
* | @MD5FMT@
| cut
-d ' ' -f 1
40 #### Use built-in $((...)) in test suite if shell supports it.
41 #### Borrowed from configure's as_fn_arith. The result is placed
42 #### in global arith_val.
43 #### Detected at run-time instead of by configure to allow testing
44 #### with different shells.
45 if (eval "test \$(( 1 + 1 )) = 2" 2>/dev
/null
); then
46 eval 'arith_eval () { arith_val=$(( $* )); }'
48 arith_eval
() { arith_val
=`expr "$@" || test $? -eq 1`; }
54 echo "$Test $0 SKIP ($WHY)"
58 # portable implementation of 'which' utility
62 #### Don't need to save current IFS because this function is run in
69 if [ -f "$D/$PROG" -a -x "$D/$PROG" ]; then
70 printf '%s\n' "$D/$PROG"
78 if [ -z "`findprog $1`" ]; then
79 test_skip
"missing $1"
83 # Some stuff for doing silly progress indicators
90 arith_eval
$LAST - $FIRST; RANGE
=$arith_val
91 arith_eval
$THIS - $FIRST; PROG
=$arith_val
92 # this automatically rounds to nearest integer
93 arith_eval
100 \
* $PROG / $RANGE; PERC
=$arith_val
94 # note \r so next update will overwrite
95 printf '%3d%%\r' $PERC
103 # don't emit anything if stdout is not connected to a tty.
114 check_for_hard_links
() {
117 printf '' > "${MH_TEST_DIR}/$$-1"
118 if link
"${MH_TEST_DIR}/$$-1" "${MH_TEST_DIR}/$$-2" 2>/dev
/null
; then
119 hard_links_supported
=1
121 hard_links_supported
=0
123 rm -f "${MH_TEST_DIR}/$$-1" "${MH_TEST_DIR}/$$-2"
128 #### check() requires two arguments, each the name of a file to be
130 #### If the same, the second file is removed. And the first file is
131 #### removed unless the optional third argument has a value of
133 #### If different, global variable "failed" is incremented.
135 #### POSIX diff should support -c.
136 if cmp -s "$1" "$2"; then
137 test $# -lt 3 -o "$3" != 'keep first' && rm -f "$1"
141 diff -c "$1" "$2" || true
143 echo "$0: test failed, outputs are in $1 and $2."
144 failed
=`expr ${failed:-0} + 1`
148 #### run_test() requires two arguments, the first is a program and
149 #### arguments, the second is its expected one-line output string.
150 #### If the actual output does not match that string:
151 #### an error message is printed and global variable "failed" is incremented;
152 #### if there is an optional third argument, it is used in the error message.
155 actual_output
=`$1 2>&1`
157 if test x
"$actual_output" != x
"$2"; then
158 echo "$0: ${3:-\"$1\"} expected:" 1>&2
160 echo "but instead got:" 1>&2
161 echo " '$actual_output'" 1>&2
162 failed
=`expr ${failed:-0} + 1`
168 MH
="${MH_TEST_DIR}/Mail/.mh_profile"
169 MHMTSCONF
="${MH_INST_DIR}${sysconfdir}/mts.conf"
170 MH_LIB_DIR
="${MH_INST_DIR}${auxexecdir}"
171 export MH MHMTSCONF MH_LIB_DIR
176 if [ -d "${MH_INST_DIR}${bindir}" ]; then
179 (cd "${MH_OBJ_DIR}" &&
180 make DESTDIR
="${MH_INST_DIR}" SETGID_MAIL
= install) ||
183 #### Don't test with sendmail because it would really send the
184 #### mail. If configured to use sendmail, change to smtp instead
185 #### so that we use fakesmtp.
186 #### And set up the maildrop in the test directory so tests don't
187 #### use the user's real maildrop.
188 #### test-slocal needs to look at the original mts.conf, so save it.
189 mv -f "${MHMTSCONF}" "${MHMTSCONF}.old"
190 sed -e 's/mts: *.*/mts: smtp/' \
191 -e "s%mmdfldir: *.*%mmdfldir: ${MH_TEST_DIR}/Mail%" \
192 -e 's%mmdflfil: *.*%mmdflfil: maildrop%' \
193 "${MHMTSCONF}.old" >"${MHMTSCONF}"
196 #### On Solaris, must set PATH after the install!
197 PATH
="${MH_INST_DIR}${bindir}:${PATH}"
200 # clean old test data
201 trap "rm -rf '$MH_TEST_DIR/Mail'" 0
203 mkdir -p "$MH_TEST_DIR/Mail" || exit 1
204 cat > "$MH" <<EOF || exit 1
205 Path: ${MH_TEST_DIR}/Mail
206 buildmimeproc: ${MH_INST_DIR}${bindir}/mhbuild
207 fileproc: ${MH_INST_DIR}${bindir}/refile
208 libdir: ${MH_LIB_DIR}
209 mhbuild: -nocontentid
210 mhlproc: ${MH_LIB_DIR}/mhl
212 postproc: ${MH_LIB_DIR}/post
213 showproc: ${MH_LIB_DIR}/mhl
216 for f
in MailAliases components digestcomps distcomps forwcomps mhl.body \
217 mhl.digest mhl.format mhl.forward mhl.headers mhl.reply \
218 mhn.defaults rcvdistcomps replcomps replgroupcomps scan.MMDDYY \
219 scan.YYYYMMDD scan.default scan.highlighted scan.mailx scan.nomime \
220 scan.size scan.
time scan.timely scan.unseen
222 cp "${MH_INST_DIR}${sysconfdir}/${f}" "${MH_TEST_DIR}/Mail" || exit 1
225 folder
-create +inbox
> /dev
/null
226 # create 10 basic messages
227 for i
in 1 2 3 4 5 6 7 8 9 10;
229 cat > $MH_TEST_DIR/Mail
/inbox
/$i <<EOF || exit 1
230 From: Test$i <test$i@example.com>
231 To: Some User <user@example.com>
232 Date: Fri, 29 Sep 2006 00:00:00
233 Message-Id: $i@test.nmh
234 Subject: Testing message $i
236 This is message number $i