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 "$default_locking" && default_locking
="@default_locking@"
18 test -z "$MULTIBYTE_ENABLED" && MULTIBYTE_ENABLED
="@MULTIBYTE_ENABLED@"
19 test -z "$ICONV_ENABLED" && ICONV_ENABLED
="@ICONV_ENABLED@"
20 export MH_TEST_DIR auxexecdir bindir mandir sysconfdir
21 export MULTIBYTE_ENABLED ICONV_ENABLED
23 test -z "$MH_INST_DIR" && MH_INST_DIR
="${MH_TEST_DIR}/inst"
26 unset MAILDROP MHBUILD MHCONTEXT MHMTSUSERCONF MHN MHSHOW MHSTORE
27 unset MHLDEBUG MHPDEBUG MHWDEBUG PAGER
28 #### Set LC_ALL in individual tests as needed. Unset these so
29 #### that we don't depend on user's settings in other tests.
30 unset LANG LC_ALL LC_CTYPE
32 #### Use a test dir for tmp files when MHTMPDIR applies.
33 MHTMPDIR
=$MH_TEST_DIR/Mail
38 #### Output just the checksum. If the filename needs to appear on
39 #### the same line, the caller needs to add it. This avoids
40 #### differences due to a leading '*' binary file indicator, for
41 #### text files, on some platforms (Cygwin).
42 @MD5SUM@ $
* | @MD5FMT@
| awk '{print $1}'
45 #### Use built-in $((...)) in test suite if shell supports it.
46 #### Borrowed from configure's as_fn_arith. The result is placed
47 #### in global arith_val.
48 #### Detected at run-time instead of by configure to allow testing
49 #### with different shells.
50 if (eval "test \$(( 1 + 1 )) = 2" 2>/dev
/null
); then
51 eval 'arith_eval () { arith_val=$(( $* )); }'
53 arith_eval
() { arith_val
=`expr "$@" || test $? -eq 1`; }
59 echo "$Test $0 SKIP ($WHY)"
63 # portable implementation of 'which' utility
67 #### Don't need to save current IFS because this function is run in
74 if [ -f "$D/$PROG" -a -x "$D/$PROG" ]; then
75 printf '%s\n' "$D/$PROG"
83 if [ -z "`findprog $1`" ]; then
84 test_skip
"missing $1"
88 # Skip test if none of the offered locales are supported.
91 for locale
in "$@"; do
92 if locale
-a | grep -i "$locale" >/dev
/null
; then
97 test_skip
"no suitable locale available"
100 # Some stuff for doing silly progress indicators
107 arith_eval
$LAST - $FIRST; RANGE
=$arith_val
108 arith_eval
$THIS - $FIRST; PROG
=$arith_val
109 # this automatically rounds to nearest integer
110 arith_eval
100 \
* $PROG / $RANGE; PERC
=$arith_val
111 # note \r so next update will overwrite
112 printf '%3d%%\r' $PERC
120 # don't emit anything if stdout is not connected to a tty.
131 check_for_hard_links
() {
134 printf '' > "${MH_TEST_DIR}/$$-1"
135 if link
"${MH_TEST_DIR}/$$-1" "${MH_TEST_DIR}/$$-2" 2>/dev
/null
; then
136 hard_links_supported
=1
138 hard_links_supported
=0
140 rm -f "${MH_TEST_DIR}/$$-1" "${MH_TEST_DIR}/$$-2"
145 #### Filter that squeezes blank lines, partially emulating GNU cat -s,
146 #### but sufficient for our purpose.
147 #### From http://www-rohan.sdsu.edu/doc/sed.html, compiled by Eric Pement.
152 #### Filter that converts non-breakable space U+00A0 to an ASCII space.
154 sed 's/'"`printf '\\302\\240'`"'/ /g'
157 #### check() requires two arguments, each the name of a file to be
159 #### If the contents are same, the second file is removed. And the
160 #### first file is removed unless there's an optional argument with
161 #### a value of 'keep first'.
162 #### If different, global variable "failed" is incremented.
163 #### If there's an optional 'ignore space' argument, spacing differences
164 #### will not be considered signficant, emulating GNU diff -w. It
165 #### is assumed that the first file has already been run through
172 while [ $# -gt 0 ]; do
174 'keep first') keepfirst
=1 ;;
175 'ignore space') ignorespace
=1 ;;
176 *) echo "$0: invalid check() argument \"$1\" in test suite" >&2 ;;
182 if [ "$ignorespace" ]; then
183 #### POSIX diff should support -b.
184 prepare_space
<"$second" | diff -b "$first" - >/dev
/null
&& success
=1
186 cmp -s "$first" "$second" && success
=1
189 if [ "$success" ]; then
190 [ "$keepfirst" ] || rm -f "$first"
194 #### POSIX diff should support -c.
195 diff -c "$first" "$second" || true
197 echo "$0: test failed, outputs are in $first and $second."
198 failed
=`expr ${failed:-0} + 1`
199 #### Set return status of the function.
205 #### Shortcut to enable use of valgrind: set NMH_VALGRIND environment
206 #### variable (to anything) so run_* will use valgrind.
207 if [ "${NMH_VALGRIND}" -a -z "${NMH_TEST_PREFIX}" ]; then
208 #### Need absolute path to valgrind.supp in case the test does a cd.
209 NMH_TEST_PREFIX
="valgrind --quiet --error-exitcode=1 \
210 --suppressions=`cd ${srcdir} && pwd`/test/valgrind.supp"
213 #### Run test under another program by setting NMH_TEST_PREFIX
214 #### environment variable to, e.g., 'valgrind --quiet'.
217 #### Don't run valgrind on shell built-in.
219 *) ${NMH_TEST_PREFIX} "$@" ;;
224 #### run_test() requires two arguments, the first is a program and
225 #### arguments, the second is its expected one-line output string.
226 #### If the actual output does not match that string:
227 #### an error message is printed and global variable "failed" is incremented;
228 #### if there is an optional third argument, it is used in the error message.
232 #### Don't run valgrind on shell built-in.
233 eval\
*) actual_output
=`$1 2>&1` ;;
234 *) actual_output
=`${NMH_TEST_PREFIX} $1 2>&1` ;;
237 if test x
"$actual_output" != x
"$2"; then
238 echo "$0: ${3:-\"$1\"} expected:" 1>&2
240 echo "but instead got:" 1>&2
241 echo " '$actual_output'" 1>&2
242 failed
=`expr ${failed:-0} + 1`
248 MH
="${MH_TEST_DIR}/Mail/.mh_profile"
249 MHMTSCONF
="${MH_INST_DIR}${sysconfdir}/mts.conf"
250 MH_LIB_DIR
="${MH_INST_DIR}${auxexecdir}"
251 export MH MHMTSCONF MH_LIB_DIR
256 if [ -d "${MH_INST_DIR}${bindir}" ]; then
259 (cd "${MH_OBJ_DIR}" &&
260 make DESTDIR
="${MH_INST_DIR}" SETGID_MAIL
= install) ||
263 #### Don't test with sendmail because it would really send the
264 #### mail. If configured to use sendmail, change to smtp instead
265 #### so that we use fakesmtp.
266 #### And set up the maildrop in the test directory so tests don't
267 #### use the user's real maildrop.
268 #### test-slocal needs to look at the original mts.conf, so save it.
269 mv -f "${MHMTSCONF}" "${MHMTSCONF}.old"
270 sed -e 's/mts: *.*/mts: smtp/' \
271 -e "s%mmdfldir: *.*%mmdfldir: ${MH_TEST_DIR}/Mail%" \
272 -e 's%mmdflfil: *.*%mmdflfil: maildrop%' \
273 "${MHMTSCONF}.old" >"${MHMTSCONF}"
276 #### On Solaris, must set PATH after the install!
277 PATH
="${MH_INST_DIR}${bindir}:${PATH}"
280 # clean old test data
281 trap "cd $MH_TEST_DIR; rm -rf '$MH_TEST_DIR/Mail'" 0
283 mkdir -p "$MH_TEST_DIR/Mail" || exit 1
284 cat > "$MH" <<EOF || exit 1
285 Path: ${MH_TEST_DIR}/Mail
286 buildmimeproc: ${MH_INST_DIR}${bindir}/mhbuild
287 fileproc: ${MH_INST_DIR}${bindir}/refile
288 libdir: ${MH_LIB_DIR}
289 mhbuild: -nocontentid
290 mhlproc: ${MH_LIB_DIR}/mhl
292 postproc: ${MH_LIB_DIR}/post
293 showproc: ${MH_LIB_DIR}/mhl
296 for f
in MailAliases components digestcomps distcomps forwcomps mhl.body \
297 mhl.digest mhl.format mhl.forward mhl.headers mhl.reply \
298 mhn.defaults rcvdistcomps replcomps replgroupcomps scan.MMDDYY \
299 scan.YYYYMMDD scan.curses scan.default scan.highlighted scan.mailx \
300 scan.nomime scan.size scan.
time scan.timely scan.unseen
302 cp "${MH_INST_DIR}${sysconfdir}/${f}" "${MH_TEST_DIR}/Mail" || exit 1
305 folder
-create +inbox
> /dev
/null
306 # create 10 basic messages
307 for i
in 1 2 3 4 5 6 7 8 9 10;
309 cat > $MH_TEST_DIR/Mail
/inbox
/$i <<EOF || exit 1
310 From: Test$i <test$i@example.com>
311 To: Some User <user@example.com>
312 Date: Fri, 29 Sep 2006 00:00:00
313 Message-Id: $i@test.nmh
314 Subject: Testing message $i
316 This is message number $i