File: test-slocal

package info (click to toggle)
nmh 1.6-16
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 6,312 kB
  • ctags: 3,934
  • sloc: ansic: 48,921; sh: 16,427; makefile: 560; perl: 509; lex: 402; awk: 74
file content (225 lines) | stat: -rwxr-xr-x 6,129 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/sh
######################################################
#
# Test slocal
#
######################################################

set -e

if test -z "$MH_OBJ_DIR"; then
    srcdir=`dirname $0`/../..
    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi

. "$MH_OBJ_DIR/test/common.sh"

setup_test

# Use proper program, maybe not the first one on PATH.
slocal="$MH_LIB_DIR"/slocal

expected="$MH_TEST_DIR"/$$.expected
actual="$MH_TEST_DIR"/$$.actual
actual2="$MH_TEST_DIR"/$$.actual2
md="$MH_TEST_DIR"/Mail/maildelivery

# check -help
cat >"$expected" <<EOF
Usage: slocal [switches]
  switches are:
  -addr address
  -user name
  -file file
  -sender address
  -mailbox file
  -info data
  -maildelivery file
  -[no]verbose
  -[no]suppressdup
  -debug
  -version
  -help
EOF

run_prog $slocal -help >"$actual" 2>&1
check "$expected" "$actual"

# check -version
case `$slocal -vers` in
  slocal\ --*) ;;
  *          ) printf '%s: slocal -vers generated unexpected output\n' "$0" >&2
               failed=`expr ${failed:-0} + 1`;;
esac

# check unknown switch
run_test "$slocal -nonexistent" 'slocal: -nonexistent unknown'

# check non-switch argument
run_test "$slocal nonexistent" 'slocal: only switch arguments are supported'

# If no mail spool, explicitly specify the mailbox.
if grep 'mmdfldir:.*/dev/null' ${MHMTSCONF}.old >/dev/null; then
  mbox="-mailbox ${MH_TEST_DIR}/Mail/mbox"
else
  mbox=
fi

#### Need to specify full path to tee on Cygwin.
[ -x /usr/bin/tee ]  &&  tee=/usr/bin/tee  ||  tee=tee

# check basic operation
# Can't use rcvstore because slocal wipes out the environment.
# So, it would put the message in the user's inbox, not the
# test inbox.  slocal also freopens stdout and stderr to
# /dev/null, so we can't view them to verify simulated delivery.
cat >"$md"  <<EOF
* - qpipe A "$tee $actual"
EOF
chmod go-w "$md"

run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1
check "$MH_TEST_DIR/Mail/inbox/1" "$actual" 'keep first'

if [ ${failed:-0} -eq 1 ]; then
  printf "\nRerunning failed basic slocal command with -verbose -debug to help
    diagnose test failure . . .\n\n"
  run_prog $slocal -verbose -debug -maildelivery "$md" $mbox \
    <"$MH_TEST_DIR"/Mail/inbox/1
  exit 1
fi

# check -debug
run_prog $slocal -debug -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1 \
  >"$actual2" 2>&1
run_test "grep ^retrieving $actual2" 'retrieving message from stdin'

# check -verbose
run_prog $slocal -verbose -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
run_test "grep ^delivering $actual2" "delivering to pipe \"$tee\", success."

# check -noverbose
run_prog $slocal -verbose -noverbose -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
run_test "grep ^delivering $actual2" ''
rm -f "$actual2"

# check match of From
cat >"$md"  <<EOF
From test2@example.com qpipe A "$tee $actual"
EOF

run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/2
check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'

# check R and ?
cat >"$md"  <<EOF
From test3@example.com qpipe R "$tee $actual"
From test3@example.com qpipe ? "$tee $actual2"
EOF

run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/3
check "$MH_TEST_DIR/Mail/inbox/3" "$actual" 'keep first'
check "$MH_TEST_DIR/Mail/inbox/3" "$actual2" 'keep first'

# check R and N
cat >"$md"  <<EOF
From test4@example.com qpipe R "$tee $actual"
From test4@example.com qpipe N "$tee $actual2"
EOF

run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/4
check "$MH_TEST_DIR/Mail/inbox/4" "$actual" 'keep first'
check "$MH_TEST_DIR/Mail/inbox/4" "$actual2" 'keep first'

# check default
cat >"$md"  <<EOF
From test5@example.com qpipe R "$tee $actual"
default 1 qpipe A "$tee $actual2"
EOF

run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/5
check "$MH_TEST_DIR/Mail/inbox/5" "$actual" 'keep first'
check "$MH_TEST_DIR/Mail/inbox/5" "$actual2" 'keep first'

# Use current login for address, user, etc., because it must be an
# existing user on the host.
me=`"$MH_LIB_DIR"/ap -format '%(me)' 0`

# check -addr
cat >"$md"  <<EOF
addr "$me" qpipe A "$tee $actual"
EOF

run_prog $slocal -addr "$me" -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/6
check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'

# check -info
cat >"$md"  <<EOF
* - qpipe A "\$(info) $actual"
EOF

run_prog $slocal -info $tee -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/7
check "$MH_TEST_DIR/Mail/inbox/7" "$actual" 'keep first'

# check -sender, which is compared with "source"
cat >"$md"  <<EOF
source "$me" qpipe A "$tee $actual"
EOF

run_prog $slocal -sender "$me" -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/8
check "$MH_TEST_DIR/Mail/inbox/8" "$actual" 'keep first'

# check -user
cat >"$md"  <<EOF
* - qpipe A "$tee $actual"
EOF

run_prog $slocal -user "$me" -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/9
check "$MH_TEST_DIR/Mail/inbox/9" "$actual" 'keep first'

# check -mailbox
cat >"$md"  <<EOF
EOF

run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
  <"$MH_TEST_DIR"/Mail/inbox/10
inc -file "$actual" -silent -truncate
rm -f "$actual"
check "$MH_TEST_DIR/Mail/inbox/10" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'

# check -file
run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
  -file "$MH_TEST_DIR"/Mail/inbox/1
inc -file "$actual" -silent -truncate
rm -f "$actual"
check "$MH_TEST_DIR/Mail/inbox/1" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'

# check -suppressdup
cat >"$md"  <<EOF
* - qpipe A "$tee $actual"
EOF

run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/2
check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'

run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/2
if [ -f "$actual" ]; then
  echo $0: check -suppressdup failed
  failed=`expr ${failed:-0} + 1`
fi

# check -nosuppressdup
run_prog $slocal -suppress -nosuppressdup -maildelivery "$md" $mbox \
  <"$MH_TEST_DIR"/Mail/inbox/2
check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'


exit ${failed:-0}