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