#!/bin/sh
-export MH=`cat test-temp-dir`/mh_profile
+set -e
+
+export MH_TEST_COMMON="$PWD/common.sh"
+
+if [ ! -f test-temp-dir ]; then
+ echo "test-temp-dir not found: running setup-test"
+ ./setup-test
+fi
+
export MH_TEST_DIR=`cat test-temp-dir`
-export PATH=$MH_TEST_DIR/bin:$PATH
-/bin/sh $1
+if [ ! -f "$MH_TEST_DIR/build/Makefile" ]; then
+ echo "temporary directory missing or broken: running setup-test"
+ ./setup-test
+ export MH_TEST_DIR=`cat test-temp-dir`
+fi
+
+unset MMHP MMHC
+export PATH="$MH_TEST_DIR/bin:$PATH"
+export MMH="$MH_TEST_DIR/.mmh"
+MAILDIR="$MH_TEST_DIR/Mail"
+
+# clean old test data
+rm -rf "$MAILDIR" "$MMH"
+
+# setup mmh
+mkdir "$MAILDIR" "$MMH"
+cat >"$MMH/profile" <<-!
+ Path: $MAILDIR
+ Inbox: +inbox
+!
+folder -create `mhparam inbox` >/dev/null
+folder -create `mhparam trashfolder` >/dev/null
+folder -create `mhparam draftfolder` >/dev/null
+
+# create 10 basic messages
+for i in 1 2 3 4 5 6 7 8 9 10;
+do
+ cat >"$MAILDIR/inbox/$i" <<-!
+ From: Test$i <test$i@example.com>
+ To: Some User <user@example.com>
+ Date: Fri, 29 Sep 2006 00:00:00
+ Subject: Testing message $i
+
+ This is message number $i
+ !
+done
+folder +inbox >/dev/null
+# now run the test
+set +e
+export SHELL="${SHELL:-/bin/sh}"
+/bin/sh "$1"
return_value=$?
+set -e
if [ $return_value -eq 0 ] ; then
- echo Test $1 PASS
+ printf "Test %-60s\tPASS\n" "$1"
+ exit 0
+elif [ $return_value -eq 120 ]; then
+ # indicates test was skipped (eg needed program not found)
+ # test itself should have printed a message about this,
+ # so print nothing here.
+ printf "Test %-60s\tSKIP\n" "$1"
+ exit 2
else
- echo Test $1 FAIL
+ printf "Test %-60s\tFAIL\n" "$1"
+ exit 1
fi