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 "$supported_locks" && supported_locks
="@supported_locks@"
17 test -z "$MULTIBYTE_ENABLED" && MULTIBYTE_ENABLED
="@MULTIBYTE_ENABLED@"
18 test -z "$ICONV_ENABLED" && ICONV_ENABLED
="@ICONV_ENABLED@"
19 export MH_TEST_DIR auxexecdir bindir mandir sysconfdir
20 export MULTIBYTE_ENABLED ICONV_ENABLED
22 test -z "$MH_INST_DIR" && MH_INST_DIR
="${MH_TEST_DIR}/inst"
25 unset MHBUILD MHCONTEXT MHMTSUSERCONF MHN MHSHOW MHSTORE
26 unset MHLDEBUG MHPDEBUG MHWDEBUG MM_CHARSET PAGER
28 #### Use a test dir for tmp files when MHTMPDIR applies.
29 MHTMPDIR
=$MH_TEST_DIR/Mail
34 #### Output just the checksum. If the filename needs to appear on
35 #### the same line, the caller needs to add it. This avoids
36 #### differences due to a leading '*' binary file indicator, for
37 #### text files, on some platforms (Cygwin).
38 @MD5SUM@ $
* | @MD5FMT@
| awk '{print $1}'
41 #### Use built-in $((...)) in test suite if shell supports it.
42 #### Borrowed from configure's as_fn_arith. The result is placed
43 #### in global arith_val.
44 #### Detected at run-time instead of by configure to allow testing
45 #### with different shells.
46 if (eval "test \$(( 1 + 1 )) = 2" 2>/dev
/null
); then
47 eval 'arith_eval () { arith_val=$(( $* )); }'
49 arith_eval
() { arith_val
=`expr "$@" || test $? -eq 1`; }
55 echo "$Test $0 SKIP ($WHY)"
59 # portable implementation of 'which' utility
63 #### Don't need to save current IFS because this function is run in
70 if [ -f "$D/$PROG" -a -x "$D/$PROG" ]; then
71 printf '%s\n' "$D/$PROG"
79 if [ -z "`findprog $1`" ]; then
80 test_skip
"missing $1"
84 # Some stuff for doing silly progress indicators
91 arith_eval
$LAST - $FIRST; RANGE
=$arith_val
92 arith_eval
$THIS - $FIRST; PROG
=$arith_val
93 # this automatically rounds to nearest integer
94 arith_eval
100 \
* $PROG / $RANGE; PERC
=$arith_val
95 # note \r so next update will overwrite
96 printf '%3d%%\r' $PERC
104 # don't emit anything if stdout is not connected to a tty.
115 check_for_hard_links
() {
118 printf '' > "${MH_TEST_DIR}/$$-1"
119 if link
"${MH_TEST_DIR}/$$-1" "${MH_TEST_DIR}/$$-2" 2>/dev
/null
; then
120 hard_links_supported
=1
122 hard_links_supported
=0
124 rm -f "${MH_TEST_DIR}/$$-1" "${MH_TEST_DIR}/$$-2"
129 #### Filter that squeezes blank lines, partially emulating GNU cat -s,
130 #### but sufficient for our purpose.
131 #### From http://www-rohan.sdsu.edu/doc/sed.html, compiled by Eric Pement.
136 #### Filter that converts non-breakable space U+00A0 to an ASCII space.
138 sed 's/'"`printf '\\302\\240'`"'/ /g'
141 #### check() requires two arguments, each the name of a file to be
143 #### If the contents are same, the second file is removed. And the
144 #### first file is removed unless there's an optional argument with
145 #### a value of 'keep first'.
146 #### If different, global variable "failed" is incremented.
147 #### If there's an optional 'ignore space' argument, spacing differences
148 #### will not be considered signficant, emulating GNU diff -w. It
149 #### is assumed that the first file has already been run through
156 while [ $# -gt 0 ]; do
158 'keep first') keepfirst
=1 ;;
159 'ignore space') ignorespace
=1 ;;
160 *) echo "$0: invalid check() argument \"$1\" in test suite" >&2 ;;
166 if [ "$ignorespace" ]; then
167 #### POSIX diff should support -b.
168 prepare_space
<"$second" | diff -b "$first" - >/dev
/null
&& success
=1
170 cmp -s "$first" "$second" && success
=1
173 if [ "$success" ]; then
174 [ "$keepfirst" ] || rm -f "$first"
178 #### POSIX diff should support -c.
179 diff -c "$first" "$second" || true
181 echo "$0: test failed, outputs are in $first and $second."
182 failed
=`expr ${failed:-0} + 1`
183 #### Set return status of the function.
189 #### Shortcut to enable use of valgrind: set NMH_VALGRIND environment
190 #### variable (to anything) so run_* will use valgrind.
191 if [ "${NMH_VALGRIND}" -a -z "${NMH_TEST_PREFIX}" ]; then
192 NMH_TEST_PREFIX
="valgrind --quiet --error-exitcode=1 \
193 --suppressions=$MH_OBJ_DIR/test/valgrind.supp"
196 #### Run test under another program by setting NMH_TEST_PREFIX
197 #### environment variable to, e.g., 'valgrind --quiet'.
200 #### Don't run valgrind on shell built-in.
202 *) ${NMH_TEST_PREFIX} "$@" ;;
207 #### run_test() requires two arguments, the first is a program and
208 #### arguments, the second is its expected one-line output string.
209 #### If the actual output does not match that string:
210 #### an error message is printed and global variable "failed" is incremented;
211 #### if there is an optional third argument, it is used in the error message.
215 #### Don't run valgrind on shell built-in.
216 eval\
*) actual_output
=`$1 2>&1` ;;
217 *) actual_output
=`${NMH_TEST_PREFIX} $1 2>&1` ;;
220 if test x
"$actual_output" != x
"$2"; then
221 echo "$0: ${3:-\"$1\"} expected:" 1>&2
223 echo "but instead got:" 1>&2
224 echo " '$actual_output'" 1>&2
225 failed
=`expr ${failed:-0} + 1`
231 MH
="${MH_TEST_DIR}/Mail/.mh_profile"
232 MHMTSCONF
="${MH_INST_DIR}${sysconfdir}/mts.conf"
233 MH_LIB_DIR
="${MH_INST_DIR}${auxexecdir}"
234 export MH MHMTSCONF MH_LIB_DIR
239 if [ -d "${MH_INST_DIR}${bindir}" ]; then
242 (cd "${MH_OBJ_DIR}" &&
243 make DESTDIR
="${MH_INST_DIR}" SETGID_MAIL
= install) ||
246 #### Don't test with sendmail because it would really send the
247 #### mail. If configured to use sendmail, change to smtp instead
248 #### so that we use fakesmtp.
249 #### And set up the maildrop in the test directory so tests don't
250 #### use the user's real maildrop.
251 #### test-slocal needs to look at the original mts.conf, so save it.
252 mv -f "${MHMTSCONF}" "${MHMTSCONF}.old"
253 sed -e 's/mts: *.*/mts: smtp/' \
254 -e "s%mmdfldir: *.*%mmdfldir: ${MH_TEST_DIR}/Mail%" \
255 -e 's%mmdflfil: *.*%mmdflfil: maildrop%' \
256 "${MHMTSCONF}.old" >"${MHMTSCONF}"
259 #### On Solaris, must set PATH after the install!
260 PATH
="${MH_INST_DIR}${bindir}:${PATH}"
263 # clean old test data
264 trap "rm -rf '$MH_TEST_DIR/Mail'" 0
266 mkdir -p "$MH_TEST_DIR/Mail" || exit 1
267 cat > "$MH" <<EOF || exit 1
268 Path: ${MH_TEST_DIR}/Mail
269 buildmimeproc: ${MH_INST_DIR}${bindir}/mhbuild
270 fileproc: ${MH_INST_DIR}${bindir}/refile
271 libdir: ${MH_LIB_DIR}
272 mhbuild: -nocontentid
273 mhlproc: ${MH_LIB_DIR}/mhl
275 postproc: ${MH_LIB_DIR}/post
276 showproc: ${MH_LIB_DIR}/mhl
279 for f
in MailAliases components digestcomps distcomps forwcomps mhl.body \
280 mhl.digest mhl.format mhl.forward mhl.headers mhl.reply \
281 mhn.defaults rcvdistcomps replcomps replgroupcomps scan.MMDDYY \
282 scan.YYYYMMDD scan.default scan.highlighted scan.mailx scan.nomime \
283 scan.size scan.
time scan.timely scan.unseen
285 cp "${MH_INST_DIR}${sysconfdir}/${f}" "${MH_TEST_DIR}/Mail" || exit 1
288 folder
-create +inbox
> /dev
/null
289 # create 10 basic messages
290 for i
in 1 2 3 4 5 6 7 8 9 10;
292 cat > $MH_TEST_DIR/Mail
/inbox
/$i <<EOF || exit 1
293 From: Test$i <test$i@example.com>
294 To: Some User <user@example.com>
295 Date: Fri, 29 Sep 2006 00:00:00
296 Message-Id: $i@test.nmh
297 Subject: Testing message $i
299 This is message number $i