Added test-slocal.
[mmh] / test / slocal / test-slocal
1 #!/bin/sh
2 ######################################################
3 #
4 # Test slocal
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, maybe not the first one on PATH.
20 slocal="$MH_LIB_DIR"/slocal
21
22 expected="$MH_TEST_DIR"/$$.expected
23 actual="$MH_TEST_DIR"/$$.actual
24 actual2="$MH_TEST_DIR"/$$.actual2
25 md="$MH_TEST_DIR"/Mail/maildelivery
26
27 # check -help
28 cat >"$expected" <<EOF
29 Usage: slocal [switches]
30   switches are:
31   -addr address
32   -user name
33   -file file
34   -sender address
35   -mailbox file
36   -info data
37   -maildelivery file
38   -[no]verbose
39   -[no]suppressdup
40   -debug
41   -version
42   -help
43 EOF
44
45 $slocal -help >"$actual" 2>&1
46 check "$expected" "$actual"
47
48 # check -version
49 case `$slocal -vers` in
50   slocal\ --*) ;;
51   *          ) printf '%s: slocal -vers generated unexpected output\n' "$0" >&2
52                failed=`expr ${failed:-0} + 1`;;
53 esac
54
55 # check unknown switch
56 run_test "$slocal -nonexistent" 'slocal: -nonexistent unknown'
57
58 # check non-switch argument
59 run_test "$slocal nonexistent" 'slocal: only switch arguments are supported'
60
61 # check basic operation
62 # Can't use rcvstore because slocal wipes out the environment.
63 # So, it would put the message in the user's inbox, not the
64 # test inbox.  slocal also freopens stdout and stderr to
65 # /dev/null, so we can't view them to verify simulated delivery.
66 cat >$md  <<EOF
67 * 1 qpipe A "tee $actual"
68 EOF
69
70 $slocal -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/1
71 check "$MH_TEST_DIR/Mail/inbox/1" "$actual" 'keep first'
72
73 # check -debug
74 $slocal -debug -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
75 run_test "grep ^retrieving $actual2" 'retrieving message from stdin'
76
77 # check -verbose
78 $slocal -verbose -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
79 run_test "grep ^delivering $actual2" 'delivering to pipe "tee", success.'
80
81 # check -noverbose
82 $slocal -verbose -noverbose -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/1 \
83   >"$actual2" 2>&1
84 run_test "grep ^delivering $actual2" ''
85 rm -f "$actual2"
86
87 # check match of From
88 cat >$md  <<EOF
89 From test2@example.com qpipe A "tee $actual"
90 EOF
91
92 $slocal -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/2
93 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
94
95 # check R and ?
96 cat >$md  <<EOF
97 From test3@example.com qpipe R "tee $actual"
98 From test3@example.com qpipe ? "tee $actual2"
99 EOF
100
101 $slocal -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/3
102 check "$MH_TEST_DIR/Mail/inbox/3" "$actual" 'keep first'
103 check "$MH_TEST_DIR/Mail/inbox/3" "$actual2" 'keep first'
104
105 # check R and N
106 cat >$md  <<EOF
107 From test4@example.com qpipe R "tee $actual"
108 From test4@example.com qpipe N "tee $actual2"
109 EOF
110
111 $slocal -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/4
112 check "$MH_TEST_DIR/Mail/inbox/4" "$actual" 'keep first'
113 check "$MH_TEST_DIR/Mail/inbox/4" "$actual2" 'keep first'
114
115 # check default
116 cat >$md  <<EOF
117 From test5@example.com qpipe R "tee $actual"
118 default 1 qpipe A "tee $actual2"
119 EOF
120
121 $slocal -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/5
122 check "$MH_TEST_DIR/Mail/inbox/5" "$actual" 'keep first'
123 check "$MH_TEST_DIR/Mail/inbox/5" "$actual2" 'keep first'
124
125 # Use current login for address, user, etc., because it must be an
126 # existing user on the host.
127 me=`"$MH_LIB_DIR"/ap -format '%(me)' 0`
128
129 # check -addr
130 cat >$md  <<EOF
131 addr "$me" qpipe A "tee $actual"
132 EOF
133
134 $slocal -addr "$me" -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/6
135 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
136
137 # check -info
138 cat >$md  <<EOF
139 * 1 qpipe A "\$(info) $actual"
140 EOF
141
142 $slocal -info tee -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/7
143 check "$MH_TEST_DIR/Mail/inbox/7" "$actual" 'keep first'
144
145 # check -sender, which is compared with "source"
146 cat >$md  <<EOF
147 source "$me" qpipe A "tee $actual"
148 EOF
149
150 $slocal -sender "$me" -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/8
151 check "$MH_TEST_DIR/Mail/inbox/8" "$actual" 'keep first'
152
153 # check -user
154 cat >$md  <<EOF
155 * 1 qpipe A "tee $actual"
156 EOF
157
158 $slocal -user "$me" -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/9
159 check "$MH_TEST_DIR/Mail/inbox/9" "$actual" 'keep first'
160
161 # check -mailbox
162 cat >$md  <<EOF
163 EOF
164
165 $slocal -mailbox "$actual" -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/10
166 inc -file "$actual" -silent -truncate
167 rm -f "$actual"
168 check "$MH_TEST_DIR/Mail/inbox/10" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
169
170 # check -file
171 $slocal -mailbox "$actual" -maildelivery $md -file "$MH_TEST_DIR"/Mail/inbox/1
172 inc -file "$actual" -silent -truncate
173 rm -f "$actual"
174 check "$MH_TEST_DIR/Mail/inbox/1" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
175
176 # check -suppressdup
177 cat >$md  <<EOF
178 * 1 qpipe A "tee $actual"
179 EOF
180
181 $slocal -suppressdup -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/2
182 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
183
184 $slocal -suppressdup -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/2
185 if [ -f "$actual" ]; then
186   echo $0: check -suppressdup failed
187   failed=`expr ${failed:-0} + 1`
188 fi
189
190 # check -nosuppressdup
191 $slocal -suppress -nosuppressdup -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/2
192 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
193
194
195 exit ${failed:-0}