Rework in the test framework; updated and new tests
[mmh] / test / tests / rcv / test-rcvdist
1 #!/bin/sh
2 ######################################################
3 #
4 # Test rcvdist
5 #
6 ######################################################
7
8 . "$MH_TEST_COMMON"
9
10
11
12 # check -help
13 runandcheck "rcvdist -help" <<!
14 Usage: rcvdist [switches] [switches for spost] address ...
15   switches are:
16   -form formfile
17   -Version
18   -help
19 !
20
21
22 # check -version
23 case `rcvdist -V` in
24   rcvdist\ --*) ;;
25   *           ) printf '%s: rcvdist -v generated unexpected output\n' "$0" >&2
26                 failed=`expr ${failed:-0} + 1`;;
27 esac
28
29 # check unknown switch
30 runandcheck "rcvdist -nonexistent" <<!
31 rcvdist: usage: rcvdist [switches] [switches for spost] address ...
32 !
33
34 # check with no switches
35 runandcheck "rcvdist" <<!
36 rcvdist: usage: rcvdist [switches] [switches for spost] address ...
37 !
38
39
40 exit
41 ### FIXME: port the following tests to mmh
42
43
44 #### Use sendmail/pipe below to override default mts.
45 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
46 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
47 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
48 MHMTSCONF="$mts_fakesendmail"
49
50 # arguments: rcvdist switches
51 test_rcvdist ()
52 {
53   run_prog $rcvdist "$@"
54
55   # fakesendmail drops the message and any cc's into this mbox.
56   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
57   inc -silent -file "$mbox"
58   rm -f "$mbox" "$mbox.map"
59
60   # It's hard to calculate the exact Date: header post is going to
61   # use, so we'll just use sed to remove the actual date so we can
62   # easily compare it against our "correct" output.
63   sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
64
65   check "$expected" "$actual"
66 }
67
68 # check with address
69 cat > "$expected" <<EOF
70 From: Test1 <test1@example.com>
71 To: Some User <user@example.com>
72 Date: Fri, 29 Sep 2006 00:00:00
73 Message-Id: 1@test.nmh
74 Subject: Testing message 1
75 Resent-From: `${MH_LIBEXEC_DIR}/ap -format '%(localmbox)' 0 | \
76               sed 's/^<\(.*\)>$/\1/'`
77 Resent-To: recipient@example.com
78 Resent-Date:
79
80 This is message number 1
81 EOF
82
83 test_rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
84
85 # check -form
86 cat > "$expected" <<EOF
87 From: Test2 <test2@example.com>
88 To: Some User <user@example.com>
89 Date: Fri, 29 Sep 2006 00:00:00
90 Message-Id: 2@test.nmh
91 Subject: Testing message 2
92 Resent-To: recipient@example.com
93 Resent-From: Some User <user@example.com>
94 Resent-Date:
95
96 This is message number 2
97 EOF
98
99 cat > "$MH_TEST_DIR/Mail/rcvdistcomps" <<'EOF'
100 %(lit)%(formataddr{addresses})\
101 %<(nonnull)%(void(width))%(putaddr Resent-To:)%>
102 %(lit)%(formataddr{to})\
103 %<(nonnull)%(void(width))%(putaddr Resent-From:)\n%>
104 EOF
105
106 test_rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com \
107   < "$MH_TEST_DIR/Mail/inbox/2"
108