]> diplodocus.org Git - nmh/blob - test/slocal/test-slocal
Update XOAUTH2 documentation.
[nmh] / 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_LIBEXEC_DIR"/slocal
21
22 check_exit '-eq 1' $slocal -
23
24 expected="$MH_TEST_DIR"/$$.expected
25 actual="$MH_TEST_DIR"/$$.actual
26 actual2="$MH_TEST_DIR"/$$.actual2
27 md="$MH_TEST_DIR"/Mail/maildelivery
28
29 # check -help
30 start_test "-help"
31 cat >"$expected" <<EOF
32 Usage: slocal [switches]
33 switches are:
34 -addr address
35 -user name
36 -file file
37 -sender address
38 -mailbox file
39 -info data
40 -maildelivery file
41 -[no]verbose
42 -[no]suppressdup
43 -debug
44 -version
45 -help
46 EOF
47
48 #### Skip nmh intro text.
49 run_prog $slocal -help 2>&1 | sed '/^$/,$d' >"$actual"
50 check "$expected" "$actual"
51
52 # check -version
53 start_test "-version"
54 case `$slocal -vers` in
55 slocal\ --*) ;;
56 * ) printf '%s: slocal -vers generated unexpected output\n' "$0" >&2
57 failed=`expr ${failed:-0} + 1`;;
58 esac
59
60 # check unknown switch
61 start_test "unknown switch"
62 run_test "$slocal -nonexistent" 'slocal: -nonexistent unknown'
63
64 # check non-switch argument
65 start_test "non-switch argument"
66 run_test "$slocal nonexistent" 'slocal: only switch arguments are supported'
67
68 # If no mail spool, explicitly specify the mailbox.
69 if grep 'mmdfldir:.*/dev/null' ${MHMTSCONF}.old >/dev/null; then
70 mbox="-mailbox ${MH_TEST_DIR}/Mail/mbox"
71 else
72 mbox=
73 fi
74
75 #### Need to specify full path to tee on Cygwin.
76 [ -x /usr/bin/tee ] && tee=/usr/bin/tee || tee=tee
77
78 # check basic operation
79 start_test "basic operation"
80 # Can't use rcvstore because slocal wipes out the environment.
81 # So, it would put the message in the user's inbox, not the
82 # test inbox. slocal also freopens stdout and stderr to
83 # /dev/null, so we can't view them to verify simulated delivery.
84 cat >"$md" <<EOF
85 * - qpipe A "$tee $actual"
86 EOF
87 chmod go-w "$md"
88
89 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1
90 check "$MH_TEST_DIR/Mail/inbox/1" "$actual" 'keep first'
91
92 if [ ${failed:-0} -eq 1 ]; then
93 printf "\nRerunning failed basic slocal command with -verbose -debug to help
94 diagnose test failure . . .\n\n"
95 run_prog $slocal -verbose -debug -maildelivery "$md" $mbox \
96 <"$MH_TEST_DIR"/Mail/inbox/1
97 exit 1
98 fi
99
100 # check -debug
101 start_test "-debug"
102 run_prog $slocal -debug -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1 \
103 >"$actual2" 2>&1
104 run_test "grep ^retrieving $actual2" 'retrieving message from stdin'
105
106 # check -verbose
107 start_test "-verbose"
108 run_prog $slocal -verbose -maildelivery "$md" $mbox \
109 <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
110 run_test "grep ^delivering $actual2" "delivering to pipe \"$tee\", success."
111
112 # check -noverbose
113 start_test "-noverbose"
114 run_prog $slocal -verbose -noverbose -maildelivery "$md" $mbox \
115 <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
116 run_test "grep ^delivering $actual2" ''
117 rm -f "$actual2"
118
119 # check match of From
120 start_test "match of From"
121 cat >"$md" <<EOF
122 From test2@example.com qpipe A "$tee $actual"
123 EOF
124
125 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/2
126 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
127
128 # check R and ?
129 start_test "R and ?"
130 cat >"$md" <<EOF
131 From test3@example.com qpipe R "$tee $actual"
132 From test3@example.com qpipe ? "$tee $actual2"
133 EOF
134
135 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/3
136 check "$MH_TEST_DIR/Mail/inbox/3" "$actual" 'keep first'
137 check "$MH_TEST_DIR/Mail/inbox/3" "$actual2" 'keep first'
138
139 # check R and N
140 start_test "R and N"
141 cat >"$md" <<EOF
142 From test4@example.com qpipe R "$tee $actual"
143 From test4@example.com qpipe N "$tee $actual2"
144 EOF
145
146 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/4
147 check "$MH_TEST_DIR/Mail/inbox/4" "$actual" 'keep first'
148 check "$MH_TEST_DIR/Mail/inbox/4" "$actual2" 'keep first'
149
150 # check default
151 start_test "default"
152 cat >"$md" <<EOF
153 From test5@example.com qpipe R "$tee $actual"
154 default 1 qpipe A "$tee $actual2"
155 EOF
156
157 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/5
158 check "$MH_TEST_DIR/Mail/inbox/5" "$actual" 'keep first'
159 check "$MH_TEST_DIR/Mail/inbox/5" "$actual2" 'keep first'
160
161 # check -addr
162 start_test "-addr"
163 cat >"$md" <<EOF
164 addr someaddress qpipe A "$tee $actual"
165 EOF
166
167 run_prog $slocal -addr someaddress -maildelivery "$md" $mbox \
168 <"$MH_TEST_DIR"/Mail/inbox/6
169 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
170
171 # check -addr with . in address
172 start_test "-addr with . in address"
173 cat >"$md" <<EOF
174 addr "first.last" qpipe A "$tee $actual"
175 EOF
176 run_prog $slocal -addr 'first.last' \
177 -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/6
178 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
179
180 # check -info
181 start_test "-info"
182 cat >"$md" <<EOF
183 * - qpipe A "\$(info) $actual"
184 EOF
185
186 run_prog $slocal -info $tee -maildelivery "$md" $mbox \
187 <"$MH_TEST_DIR"/Mail/inbox/7
188 check "$MH_TEST_DIR/Mail/inbox/7" "$actual" 'keep first'
189
190 # check -sender, which is compared with "source"
191 start_test "-sender, which is compared with "source""
192 cat >"$md" <<EOF
193 source somesender qpipe A "$tee $actual"
194 EOF
195
196 run_prog $slocal -sender somesender -maildelivery "$md" $mbox \
197 <"$MH_TEST_DIR"/Mail/inbox/8
198 check "$MH_TEST_DIR/Mail/inbox/8" "$actual" 'keep first'
199
200 # check -user
201 start_test "-user"
202 cat >"$md" <<EOF
203 * - qpipe A "$tee $actual"
204 EOF
205
206 # Use current login for user because it must be an existing user on the host.
207 me=`"$MH_LIBEXEC_DIR"/ap -format '%(me)' 0`
208 run_prog $slocal -user "$me" -maildelivery "$md" $mbox \
209 <"$MH_TEST_DIR"/Mail/inbox/9
210 check "$MH_TEST_DIR/Mail/inbox/9" "$actual" 'keep first'
211
212 # Can't check -user with . in address because the user must
213 # have an account on the local system, and we can't guarantee
214 # that there is one.
215
216 # check -mailbox
217 start_test "-mailbox"
218 cat >"$md" <<EOF
219 EOF
220
221 run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
222 <"$MH_TEST_DIR"/Mail/inbox/10
223 inc -file "$actual" -silent -truncate
224 rm -f "$actual"
225 check "$MH_TEST_DIR/Mail/inbox/10" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
226
227 # check -file
228 start_test "-file"
229 run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
230 -file "$MH_TEST_DIR"/Mail/inbox/1
231 inc -file "$actual" -silent -truncate
232 rm -f "$actual"
233 check "$MH_TEST_DIR/Mail/inbox/1" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
234
235 # check -suppressdup
236 start_test "-suppressdup"
237 cat >"$md" <<EOF
238 * - qpipe A "$tee $actual"
239 EOF
240
241 run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
242 <"$MH_TEST_DIR"/Mail/inbox/2
243 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
244
245 run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
246 <"$MH_TEST_DIR"/Mail/inbox/2
247 if [ -f "$actual" ]; then
248 echo $0: check -suppressdup failed
249 failed=`expr ${failed:-0} + 1`
250 fi
251
252 # check -nosuppressdup
253 start_test "-nosuppressdup"
254 run_prog $slocal -suppress -nosuppressdup -maildelivery "$md" $mbox \
255 <"$MH_TEST_DIR"/Mail/inbox/2
256 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
257
258 finish_test
259 exit ${failed:-0}