]> diplodocus.org Git - nmh/blob - test/slocal/test-slocal
Wrapped code block of conditional statement with {}, so that the
[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 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 run_prog $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 # If no mail spool, explicitly specify the mailbox.
62 if grep 'mmdfldir:.*/dev/null' ${MHMTSCONF}.old >/dev/null; then
63 mbox="-mailbox ${MH_TEST_DIR}/Mail/mbox"
64 else
65 mbox=
66 fi
67
68 #### Need to specify full path to tee on Cygwin.
69 [ -x /usr/bin/tee ] && tee=/usr/bin/tee || tee=tee
70
71 # check basic operation
72 # Can't use rcvstore because slocal wipes out the environment.
73 # So, it would put the message in the user's inbox, not the
74 # test inbox. slocal also freopens stdout and stderr to
75 # /dev/null, so we can't view them to verify simulated delivery.
76 cat >"$md" <<EOF
77 * - qpipe A "$tee $actual"
78 EOF
79 chmod go-w "$md"
80
81 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1
82 check "$MH_TEST_DIR/Mail/inbox/1" "$actual" 'keep first'
83
84 if [ ${failed:-0} -eq 1 ]; then
85 printf "\nRerunning failed basic slocal command with -verbose -debug to help
86 diagnose test failure . . .\n\n"
87 run_prog $slocal -verbose -debug -maildelivery "$md" $mbox \
88 <"$MH_TEST_DIR"/Mail/inbox/1
89 exit 1
90 fi
91
92 # check -debug
93 run_prog $slocal -debug -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1 \
94 >"$actual2" 2>&1
95 run_test "grep ^retrieving $actual2" 'retrieving message from stdin'
96
97 # check -verbose
98 run_prog $slocal -verbose -maildelivery "$md" $mbox \
99 <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
100 run_test "grep ^delivering $actual2" "delivering to pipe \"$tee\", success."
101
102 # check -noverbose
103 run_prog $slocal -verbose -noverbose -maildelivery "$md" $mbox \
104 <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
105 run_test "grep ^delivering $actual2" ''
106 rm -f "$actual2"
107
108 # check match of From
109 cat >"$md" <<EOF
110 From test2@example.com qpipe A "$tee $actual"
111 EOF
112
113 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/2
114 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
115
116 # check R and ?
117 cat >"$md" <<EOF
118 From test3@example.com qpipe R "$tee $actual"
119 From test3@example.com qpipe ? "$tee $actual2"
120 EOF
121
122 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/3
123 check "$MH_TEST_DIR/Mail/inbox/3" "$actual" 'keep first'
124 check "$MH_TEST_DIR/Mail/inbox/3" "$actual2" 'keep first'
125
126 # check R and N
127 cat >"$md" <<EOF
128 From test4@example.com qpipe R "$tee $actual"
129 From test4@example.com qpipe N "$tee $actual2"
130 EOF
131
132 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/4
133 check "$MH_TEST_DIR/Mail/inbox/4" "$actual" 'keep first'
134 check "$MH_TEST_DIR/Mail/inbox/4" "$actual2" 'keep first'
135
136 # check default
137 cat >"$md" <<EOF
138 From test5@example.com qpipe R "$tee $actual"
139 default 1 qpipe A "$tee $actual2"
140 EOF
141
142 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/5
143 check "$MH_TEST_DIR/Mail/inbox/5" "$actual" 'keep first'
144 check "$MH_TEST_DIR/Mail/inbox/5" "$actual2" 'keep first'
145
146 # check -addr
147 cat >"$md" <<EOF
148 addr someaddress qpipe A "$tee $actual"
149 EOF
150
151 run_prog $slocal -addr someaddress -maildelivery "$md" $mbox \
152 <"$MH_TEST_DIR"/Mail/inbox/6
153 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
154
155 # check -addr with . in address
156 cat >"$md" <<EOF
157 addr "first.last" qpipe A "$tee $actual"
158 EOF
159 run_prog $slocal -addr 'first.last' \
160 -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/6
161 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
162
163 # check -info
164 cat >"$md" <<EOF
165 * - qpipe A "\$(info) $actual"
166 EOF
167
168 run_prog $slocal -info $tee -maildelivery "$md" $mbox \
169 <"$MH_TEST_DIR"/Mail/inbox/7
170 check "$MH_TEST_DIR/Mail/inbox/7" "$actual" 'keep first'
171
172 # check -sender, which is compared with "source"
173 cat >"$md" <<EOF
174 source somesender qpipe A "$tee $actual"
175 EOF
176
177 run_prog $slocal -sender somesender -maildelivery "$md" $mbox \
178 <"$MH_TEST_DIR"/Mail/inbox/8
179 check "$MH_TEST_DIR/Mail/inbox/8" "$actual" 'keep first'
180
181 # check -user
182 cat >"$md" <<EOF
183 * - qpipe A "$tee $actual"
184 EOF
185
186 # Use current login for user because it must be an existing user on the host.
187 me=`"$MH_LIBEXEC_DIR"/ap -format '%(me)' 0`
188 run_prog $slocal -user "$me" -maildelivery "$md" $mbox \
189 <"$MH_TEST_DIR"/Mail/inbox/9
190 check "$MH_TEST_DIR/Mail/inbox/9" "$actual" 'keep first'
191
192 # Can't check -user with . in address because the user must
193 # have an account on the local system, and we can't guarantee
194 # that there is one.
195
196 # check -mailbox
197 cat >"$md" <<EOF
198 EOF
199
200 run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
201 <"$MH_TEST_DIR"/Mail/inbox/10
202 inc -file "$actual" -silent -truncate
203 rm -f "$actual"
204 check "$MH_TEST_DIR/Mail/inbox/10" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
205
206 # check -file
207 run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
208 -file "$MH_TEST_DIR"/Mail/inbox/1
209 inc -file "$actual" -silent -truncate
210 rm -f "$actual"
211 check "$MH_TEST_DIR/Mail/inbox/1" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
212
213 # check -suppressdup
214 cat >"$md" <<EOF
215 * - qpipe A "$tee $actual"
216 EOF
217
218 run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
219 <"$MH_TEST_DIR"/Mail/inbox/2
220 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
221
222 run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
223 <"$MH_TEST_DIR"/Mail/inbox/2
224 if [ -f "$actual" ]; then
225 echo $0: check -suppressdup failed
226 failed=`expr ${failed:-0} + 1`
227 fi
228
229 # check -nosuppressdup
230 run_prog $slocal -suppress -nosuppressdup -maildelivery "$md" $mbox \
231 <"$MH_TEST_DIR"/Mail/inbox/2
232 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
233
234 exit ${failed:-0}