]> diplodocus.org Git - nmh/blob - test/imap/test-scan
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-scan
1 #!/bin/sh
2
3 testname=${0#$srcdir/}
4
5 if test -z "$MH_OBJ_DIR"; then
6 srcdir=`dirname "$0"`/../..
7 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
8 fi
9
10 . "$MH_OBJ_DIR/test/common.sh"
11
12 setup_test_without_data Mail
13
14 rm -rf "$MH_TEST_DIR/panda"
15
16 imap_cleanup() {
17 #### Save exit status to use as status for this program.
18 status=$?
19 set +e
20
21 [ -n "$imapd_pid" ] && kill $imapd_pid
22 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
23
24 # TODO have cleanup allow additional cleanup registration?
25 # Or just allow it to accept status as argument.
26 (exit $status)
27 cleanup
28 }
29 trap imap_cleanup 0
30
31 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
32 install -d "$covdir"
33 export LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw"
34
35 start_fakeinetd env "HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
36 imapd_pid=$fakeinetd_pid
37
38 cat >> "$MH" <<EOF
39 Unseen-Sequence: unseen
40 Managed-Folders: imap
41 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
42 imap-socket: $MH_TEST_DIR/Mail/imap.d/socket
43 imap-db: $MH_TEST_DIR/Mail/imap.d
44 imap-host: 127.0.0.1
45 imap-port: $fakeinetd_port
46 imap-auth: PREAUTH
47 imap-tls: don't protect my data i know what i'm doing
48 imap-mailbox-root: test/
49 EOF
50 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
51 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
52 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
53 fi
54
55 mkdir "$MH_TEST_DIR/panda"
56 mkdir "$MH_TEST_DIR/panda/test"
57
58 expected="$MH_TEST_DIR/$$.expected"
59 actual="$MH_TEST_DIR/$$.actual"
60
61 # TODO duplicated with test-inc
62 removed_message=5
63 arith_val=1
64 message_count=11
65 cat > $MH_TEST_DIR/panda/test/fold <<EOF
66 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
67 Date:Sat, 24 Oct 2020 19:20:38 -0500
68 from:me
69 to:you
70 X-IMAPbase: 1603585238 $message_count testseq
71 Status: RO
72 X-Status:
73 X-Keywords:
74 X-UID: $arith_val
75
76 body
77
78 EOF
79 echo " $arith_val 10/24 me <<body >>" > "$expected.scan-all"
80
81 while [ $arith_val -lt $message_count ]; do
82 arith_eval $arith_val + 1
83 printf ' %2d 10/24 me <<body >>\n' $arith_val >> "$expected.scan-all"
84 printf ' %2d U 10/24 me <<body >>\n' $arith_val >> "$expected.scan-unseen"
85 cat >> $MH_TEST_DIR/panda/test/fold <<EOF
86 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
87 Date:Sat, 24 Oct 2020 19:20:38 -0500
88 from:me
89 to:you
90 Status: O
91 X-Status:
92 X-Keywords:
93 X-UID: $arith_val
94
95 body
96
97 EOF
98 arith_eval $arith_val + 1
99 if [ $arith_val -ne $removed_message ]; then
100 printf ' %2d U 10/24 me <<body >>\n' $arith_val >> "$expected.scan-unseen"
101 printf ' %2d 10/24 me <<body >>\n' $arith_val >> "$expected.scan-all"
102 fi
103 cat >> $MH_TEST_DIR/panda/test/fold <<EOF
104 From nmh@example.com Sat Oct 24 19:20:38 2020 -0500
105 Date:Sat, 24 Oct 2020 19:20:38 -0500
106 from:me
107 to:you
108 Status: O
109 X-Status:
110 X-Keywords:
111 X-UID: $arith_val
112
113 body
114
115 EOF
116 done
117
118 start_test 'inc then remove mesage 5'
119 check_exit '-eq 0' inc +imap
120 check_exit '-eq 0' rmm -unlink +imap/fold $removed_message
121
122 ################################################################################
123 start_test 'scan all implicitly'
124
125 run_prog scan +imap/fold -width 80 > "$actual"
126 check "$expected.scan-all" "$actual" 'keep first'
127
128 ################################################################################
129 start_test 'scan all explicitly'
130
131 run_prog scan +imap/fold -width 80 all > "$actual"
132 check "$expected.scan-all" "$actual" 'keep first'
133
134 ################################################################################
135 start_test 'scan unseen'
136
137 run_prog scan +imap/fold -form scan.unseen -width 80 unseen > "$actual"
138 check "$expected.scan-unseen" "$actual"
139
140 cat > "$expected" <<EOF
141 nmh-picked: 2-4 6-11
142 unseen: 2-4 6-11
143 EOF
144 check "$MH_TEST_DIR/Mail/imap/fold/.mh_sequences" "$expected" 'keep first'
145
146 ################################################################################
147 start_test 'scan some messages'
148
149 cat > "$expected" <<EOF
150 2 U 10/24 me <<body >>
151 3 U 10/24 me <<body >>
152 4 U 10/24 me <<body >>
153 6 U 10/24 me <<body >>
154 8 U 10/24 me <<body >>
155 9 U 10/24 me <<body >>
156 10 U 10/24 me <<body >>
157 EOF
158 run_prog scan +imap/fold -form scan.unseen -width 80 8-9 9-10 2-6 > "$actual"
159 check "$expected" "$actual"
160
161 cat > "$expected" <<EOF
162 nmh-picked: 2-4 6 8-10
163 unseen: 2-4 6-11
164 EOF
165 check "$MH_TEST_DIR/Mail/imap/fold/.mh_sequences" "$expected" 'keep first'
166
167 ################################################################################
168 start_test 'scan non-existent message'
169
170 cat > "$expected" <<EOF
171 scan: no messages match specification
172 EOF
173
174 run_prog scan +imap/fold -form scan.unseen -width 80 $removed_message > "$actual" 2>&1 || :
175 check "$expected" "$actual"
176
177 ################################################################################
178 start_test 'mark -del testseq unseen'
179
180 check_exit '-eq 0' mark -add -seq testseq 6 8 10
181 # TODO check output
182 check_exit '-eq 0' scan testseq
183
184 check_exit '-eq 0' mark -del -seq testseq unseen
185
186 # TODO should be 'scan: bad message list testseq'
187 cat > "$expected" <<EOF
188 scan: no messages match specification
189 EOF
190
191 run_prog scan +imap/fold -form scan.unseen -width 80 testseq > "$actual" 2>&1 || :
192 check "$expected" "$actual"
193
194 ################################################################################
195 start_test 'show unseen twice'
196
197 sed 's/^ 11 / 11+/' "$expected.scan-all" > "$expected"
198
199 check_exit '-eq 0' show unseen unseen
200
201 run_prog scan +imap/fold -width 80 > "$actual"
202 check "$expected" "$actual"
203
204 ################################################################################
205 start_test 'show 1-11'
206
207 sed 's/^ 11 / 11+/' "$expected.scan-all" > "$expected"
208 rm "$expected.scan-all"
209
210 check_exit '-eq 0' show 1-11
211
212 ################################################################################
213 start_test 'scan testseq'
214
215 check_exit '-eq 0' mark -add -seq testseq 2-3 6-8 11
216 cat > "$expected" <<EOF
217 2 10/24 me <<body >>
218 3 10/24 me <<body >>
219 6 10/24 me <<body >>
220 7 10/24 me <<body >>
221 8 10/24 me <<body >>
222 11+ 10/24 me <<body >>
223 EOF
224 run_prog scan +imap/fold -form scan.unseen -width 80 testseq > "$actual"
225 check "$expected" "$actual"
226
227 ################################################################################
228 start_test 'mark -del testseq 1'
229
230 check_exit '-eq 0' mark -del -seq testseq 2
231
232 cat > "$expected" <<EOF
233 3 10/24 me <<body >>
234 6 10/24 me <<body >>
235 7 10/24 me <<body >>
236 8 10/24 me <<body >>
237 11+ 10/24 me <<body >>
238 EOF
239 run_prog scan +imap/fold -form scan.unseen -width 80 testseq > "$actual"
240 check "$expected" "$actual"
241
242 ################################################################################
243 start_test 'mark -del testseq all'
244
245 check_exit '-eq 0' mark -del -seq testseq testseq
246
247 ################################################################################
248 start_test 'scan testseq after mark -del'
249
250 # TODO should be 'scan: bad message list testseq'
251 cat > "$expected" <<EOF
252 scan: no messages match specification
253 EOF
254
255 run_prog scan +imap/fold -form scan.unseen -width 80 testseq > "$actual" 2>&1 || :
256 check "$expected" "$actual"
257
258 finish_test
259 exit ${failed:-0}