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