]> diplodocus.org Git - nmh/blob - test/slocal/test-slocal
A little closer, but still has problems.
[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_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 # 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 $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 $slocal -verbose -debug -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1
88 exit 1
89 fi
90
91 # check -debug
92 $slocal -debug -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1 \
93 >"$actual2" 2>&1
94 run_test "grep ^retrieving $actual2" 'retrieving message from stdin'
95
96 # check -verbose
97 $slocal -verbose -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1 \
98 >"$actual2" 2>&1
99 run_test "grep ^delivering $actual2" "delivering to pipe \"$tee\", success."
100
101 # check -noverbose
102 $slocal -verbose -noverbose -maildelivery "$md" $mbox \
103 <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
104 run_test "grep ^delivering $actual2" ''
105 rm -f "$actual2"
106
107 # check match of From
108 cat >"$md" <<EOF
109 From test2@example.com qpipe A "$tee $actual"
110 EOF
111
112 $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/2
113 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
114
115 # check R and ?
116 cat >"$md" <<EOF
117 From test3@example.com qpipe R "$tee $actual"
118 From test3@example.com qpipe ? "$tee $actual2"
119 EOF
120
121 $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/3
122 check "$MH_TEST_DIR/Mail/inbox/3" "$actual" 'keep first'
123 check "$MH_TEST_DIR/Mail/inbox/3" "$actual2" 'keep first'
124
125 # check R and N
126 cat >"$md" <<EOF
127 From test4@example.com qpipe R "$tee $actual"
128 From test4@example.com qpipe N "$tee $actual2"
129 EOF
130
131 $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/4
132 check "$MH_TEST_DIR/Mail/inbox/4" "$actual" 'keep first'
133 check "$MH_TEST_DIR/Mail/inbox/4" "$actual2" 'keep first'
134
135 # check default
136 cat >"$md" <<EOF
137 From test5@example.com qpipe R "$tee $actual"
138 default 1 qpipe A "$tee $actual2"
139 EOF
140
141 $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/5
142 check "$MH_TEST_DIR/Mail/inbox/5" "$actual" 'keep first'
143 check "$MH_TEST_DIR/Mail/inbox/5" "$actual2" 'keep first'
144
145 # Use current login for address, user, etc., because it must be an
146 # existing user on the host.
147 me=`"$MH_LIB_DIR"/ap -format '%(me)' 0`
148
149 # check -addr
150 cat >"$md" <<EOF
151 addr "$me" qpipe A "$tee $actual"
152 EOF
153
154 $slocal -addr "$me" -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/6
155 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
156
157 # check -info
158 cat >"$md" <<EOF
159 * - qpipe A "\$(info) $actual"
160 EOF
161
162 $slocal -info $tee -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/7
163 check "$MH_TEST_DIR/Mail/inbox/7" "$actual" 'keep first'
164
165 # check -sender, which is compared with "source"
166 cat >"$md" <<EOF
167 source "$me" qpipe A "$tee $actual"
168 EOF
169
170 $slocal -sender "$me" -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/8
171 check "$MH_TEST_DIR/Mail/inbox/8" "$actual" 'keep first'
172
173 # check -user
174 cat >"$md" <<EOF
175 * - qpipe A "$tee $actual"
176 EOF
177
178 $slocal -user "$me" -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/9
179 check "$MH_TEST_DIR/Mail/inbox/9" "$actual" 'keep first'
180
181 # check -mailbox
182 cat >"$md" <<EOF
183 EOF
184
185 $slocal -mailbox "$actual" -maildelivery "$md" <"$MH_TEST_DIR"/Mail/inbox/10
186 inc -file "$actual" -silent -truncate
187 rm -f "$actual"
188 check "$MH_TEST_DIR/Mail/inbox/10" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
189
190 # check -file
191 $slocal -mailbox "$actual" -maildelivery "$md" -file "$MH_TEST_DIR"/Mail/inbox/1
192 inc -file "$actual" -silent -truncate
193 rm -f "$actual"
194 check "$MH_TEST_DIR/Mail/inbox/1" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
195
196 # check -suppressdup
197 cat >"$md" <<EOF
198 * - qpipe A "$tee $actual"
199 EOF
200
201 $slocal -suppressdup -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/2
202 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
203
204 $slocal -suppressdup -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/2
205 if [ -f "$actual" ]; then
206 echo $0: check -suppressdup failed
207 failed=`expr ${failed:-0} + 1`
208 fi
209
210 # check -nosuppressdup
211 $slocal -suppress -nosuppressdup -maildelivery "$md" $mbox \
212 <"$MH_TEST_DIR"/Mail/inbox/2
213 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
214
215
216 exit ${failed:-0}