]> diplodocus.org Git - nmh/blobdiff - test/rcv/test-rcvdist
Removed redundant initialization of local variable tls.
[nmh] / test / rcv / test-rcvdist
index d13a202817db2bd1a949c8693e5d1f5aa0cac801..bdc32f7604b133371fd0f90a92f4b0ea79c2ed47 100755 (executable)
@@ -12,18 +12,25 @@ if test -z "${MH_OBJ_DIR}"; then
     MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
 fi
 
-. "$MH_OBJ_DIR/test/common.sh"
+. "${MH_OBJ_DIR}/test/common.sh"
 
 setup_test
 
 # Use proper program, likely not the first one on PATH.
-rcvdist="${MH_LIB_DIR}/rcvdist"
+rcvdist="${MH_LIBEXEC_DIR}/rcvdist"
+
+arith_eval 64000 + $$ % 1000
+localport=$arith_val
+testname="${MH_TEST_DIR}/$$"
+
+check_exit '-eq 1' $rcvdist -
 
 expected=$MH_TEST_DIR/$$.expected
 actual=$MH_TEST_DIR/$$.actual
 
 
 # check -help
+start_test -help
 cat >$expected <<EOF
 Usage: rcvdist [switches] [switches for postproc] address ...
   switches are:
@@ -32,78 +39,148 @@ Usage: rcvdist [switches] [switches for postproc] address ...
   -help
 EOF
 
-$rcvdist -help >"$actual" 2>&1
+#### Skip nmh intro text.
+run_prog "$rcvdist" -help 2>&1 | sed '/^$/,$d' >"$actual"
 check "$expected" "$actual"
 
 # check -version
+start_test -version
 case `$rcvdist -v` in
   rcvdist\ --*) ;;
-  *           ) printf "$0: rcvdist -v generated unexpected output\n" >&2
+  *           ) printf '%s: rcvdist -v generated unexpected output\n' "$0" >&2
                 failed=`expr ${failed:-0} + 1`;;
 esac
 
 # check unknown switch
+start_test 'unknown switch'
 run_test "$rcvdist -nonexistent" \
   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
 
 # check with no switches
+start_test 'no switches'
 run_test "$rcvdist" \
   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
 
-# check with address
-# Replace post:
-cat >"$MH_TEST_DIR/Mail/notpost" <<EOF
-if grep '^Resent-From: ' "\$2" >/dev/null; then
-  sed 's/^Resent-From:.*/Resent-From:/' "\$2" >"$actual"
-else
-  printf 'post: message has no Resent-From: header\n'
-  printf 'post: See default components files for examples\n'
-  printf 'post: re-format message and try again\n'
-  exit 1
-fi
+#### Use fakesmtp for this first test.
+# check post switch with argument
+start_test 'post switch with argument'
+
+cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Date: Sun, 14 Jan 2018 12:00:00 -0500
+
+This is a test.
+EOF
+
+cat > "${testname}.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<somebody@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Date:
+Resent-To: somebody@example.com
+Resent-From: Somebody Else <somebody@example.com>
+Resent-Date:
+
+This is a test.
+.
+QUIT
 EOF
-chmod u+x "$MH_TEST_DIR/Mail/notpost"
-sed 's/postproc:.*/#:/' "$MH" > "${MH}-new"
-printf "postproc: $MH_TEST_DIR/Mail/notpost\n" >>"${MH}-new"
-mv -f "${MH}-new" "$MH"
 
-#### An extra space gets inserted between each header field name
-#### and body.  That probably should be fixed.
+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
+
+# Set this for the EHLO command
+echo "clientname: nosuchhost.example.com" >> ${MHMTSCONF}
+
+# $1: message draft file
+# $2: output filename for fakesmtp, i.e., the sent message
+test_post ()
+{
+    pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$2" $localport`
+
+    run_prog $rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" -server 127.0.0.1 -port $localport somebody@example.com <$1
+
+    sed -e 's/^Date:.*/Date:/' -e 's/^Resent-Date:.*/Resent-Date:/' "$2" > "$2".nodate
+    rm -f "$2"
+
+    check "$2".nodate "$3"
+}
+
+test_post "${MH_TEST_DIR}/Mail/draft" "${testname}.fakesmtp" "${testname}.expected"
+
+#### 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"
+
+  # 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
+start_test 'with address'
 cat > "$expected" <<EOF
-From:  Test1 <test1@example.com>
-To:  Some User <user@example.com>
-Date:  Fri, 29 Sep 2006 00:00:00
-Subject:  Testing message 1
-Resent-From:
-Resent-To:  recipient@example.com
+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-To: recipient@example.com
+Resent-From: Some User <user@example.com>
+Resent-Date:
 
 This is message number 1
 EOF
 
-$rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
-check "$expected" "$actual"
+test_rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
 
 # check -form
+start_test -form
 cat > "$expected" <<EOF
-From:  Test1 <test1@example.com>
-To:  Some User <user@example.com>
-Date:  Fri, 29 Sep 2006 00:00:00
-Subject:  Testing message 1
+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:
+Resent-From: Some User <user@example.com>
+Resent-Date:
 
-This is message number 1
+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"
 
-$rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com < \
-  "$MH_TEST_DIR/Mail/inbox/1"
-check "$expected" "$actual"
 
+finish_test
 exit ${failed:-0}