Rework in the test framework; updated and new tests
[mmh] / test / tests / rcv / test-rcvdist
diff --git a/test/tests/rcv/test-rcvdist b/test/tests/rcv/test-rcvdist
new file mode 100755 (executable)
index 0000000..8d05bc8
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/sh
+######################################################
+#
+# Test rcvdist
+#
+######################################################
+
+. "$MH_TEST_COMMON"
+
+
+
+# check -help
+runandcheck "rcvdist -help" <<!
+Usage: rcvdist [switches] [switches for spost] address ...
+  switches are:
+  -form formfile
+  -Version
+  -help
+!
+
+
+# check -version
+case `rcvdist -V` in
+  rcvdist\ --*) ;;
+  *           ) printf '%s: rcvdist -v generated unexpected output\n' "$0" >&2
+                failed=`expr ${failed:-0} + 1`;;
+esac
+
+# check unknown switch
+runandcheck "rcvdist -nonexistent" <<!
+rcvdist: usage: rcvdist [switches] [switches for spost] address ...
+!
+
+# check with no switches
+runandcheck "rcvdist" <<!
+rcvdist: usage: rcvdist [switches] [switches for spost] address ...
+!
+
+
+exit
+### FIXME: port the following tests to mmh
+
+
+#### Use sendmail/pipe below to override default mts.
+mts_fakesendmail="${MHMTSCONF}-fakesendmail"
+sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
+printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
+MHMTSCONF="$mts_fakesendmail"
+
+# arguments: rcvdist switches
+test_rcvdist ()
+{
+  run_prog $rcvdist "$@"
+
+  # fakesendmail drops the message and any cc's into this mbox.
+  mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
+  inc -silent -file "$mbox"
+  rm -f "$mbox" "$mbox.map"
+
+  # It's hard to calculate the exact Date: header post is going to
+  # use, so we'll just use sed to remove the actual date so we can
+  # easily compare it against our "correct" output.
+  sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
+
+  check "$expected" "$actual"
+}
+
+# check with address
+cat > "$expected" <<EOF
+From: Test1 <test1@example.com>
+To: Some User <user@example.com>
+Date: Fri, 29 Sep 2006 00:00:00
+Message-Id: 1@test.nmh
+Subject: Testing message 1
+Resent-From: `${MH_LIBEXEC_DIR}/ap -format '%(localmbox)' 0 | \
+              sed 's/^<\(.*\)>$/\1/'`
+Resent-To: recipient@example.com
+Resent-Date:
+
+This is message number 1
+EOF
+
+test_rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
+
+# check -form
+cat > "$expected" <<EOF
+From: Test2 <test2@example.com>
+To: Some User <user@example.com>
+Date: Fri, 29 Sep 2006 00:00:00
+Message-Id: 2@test.nmh
+Subject: Testing message 2
+Resent-To: recipient@example.com
+Resent-From: Some User <user@example.com>
+Resent-Date:
+
+This is message number 2
+EOF
+
+cat > "$MH_TEST_DIR/Mail/rcvdistcomps" <<'EOF'
+%(lit)%(formataddr{addresses})\
+%<(nonnull)%(void(width))%(putaddr Resent-To:)%>
+%(lit)%(formataddr{to})\
+%<(nonnull)%(void(width))%(putaddr Resent-From:)\n%>
+EOF
+
+test_rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com \
+  < "$MH_TEST_DIR/Mail/inbox/2"
+