]> diplodocus.org Git - nmh/blob - test/refile/test-refile
Added start_test/finish_test to a bunch of tests.
[nmh] / test / refile / test-refile
1 #!/bin/sh
2 ######################################################
3 #
4 # Test refile
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 check_exit '-eq 1' refile -
20
21 expected=$MH_TEST_DIR/$$.expected
22 actual=$MH_TEST_DIR/$$.actual
23
24 cd $MH_TEST_DIR
25
26 run_prog folder -create +other -fast >/dev/null
27 run_prog folder -create +another -fast >/dev/null
28
29 # check with no options and no current message
30 start_test "with no options and no current message"
31 run_test 'refile' 'refile: no folder specified'
32
33 # check with current message
34 start_test "with current message"
35 run_prog folder +inbox 4 >/dev/null
36 run_test 'refile +other' ''
37 run_test 'folders -noheader' \
38 'another has no messages.
39 inbox+ has 9 messages (1-10); cur=4.
40 other has 1 message (1- 1).
41
42 TOTAL = 10 messages in 3 folders.'
43
44 # check with specified message
45 start_test "with specified message"
46 run_prog folder +inbox 5 >/dev/null
47 run_test 'refile 5 +other' ''
48 run_test 'folders -noheader' \
49 'another has no messages.
50 inbox+ has 8 messages (1-10); cur=5.
51 other has 2 messages (1- 2).
52
53 TOTAL = 10 messages in 3 folders.'
54
55 # check multiple messages
56 start_test "multiple messages"
57 run_test 'refile 6 7 +other' ''
58 run_test 'folders -noheader' \
59 'another has no messages.
60 inbox+ has 6 messages (1-10); cur=7.
61 other has 4 messages (1- 4).
62
63 TOTAL = 10 messages in 3 folders.'
64
65 # check multiple folders
66 start_test "multiple folders"
67 run_test 'refile 8 +other +another' ''
68 run_test 'folders -noheader' \
69 'another has 1 message (1- 1).
70 inbox+ has 5 messages (1-10); cur=8.
71 other has 5 messages (1- 5).
72
73 TOTAL = 11 messages in 3 folders.'
74
75 # check message number greater than highest
76 start_test "message number greater than highest"
77 run_test 'refile 11 +other' "refile: message 11 doesn't exist"
78 run_prog folder -f +another >/dev/null
79
80 # check -src
81 start_test "-src"
82 run_test 'refile 9 -src +inbox +other' ''
83 run_test 'folders -noheader' \
84 'another has 1 message (1- 1).
85 inbox+ has 4 messages (1-10); cur=9.
86 other has 6 messages (1- 6).
87
88 TOTAL = 11 messages in 3 folders.'
89
90 # check -file
91 start_test "-file"
92 run_test "refile -file $MH_TEST_DIR/Mail/inbox/10 +other" ''
93 run_test 'folders -noheader' \
94 'another has 1 message (1-1).
95 inbox+ has 3 messages (1-3).
96 other has 7 messages (1-7).
97
98 TOTAL = 11 messages in 3 folders.'
99
100 # check -file -, which isn't supported
101 start_test "-file -, which isn't supported"
102 run_test "refile -file - +other <$MH_TEST_DIR/Mail/inbox/9" \
103 'refile: missing argument to -file'
104 run_test 'folders -noheader' \
105 'another has 1 message (1-1).
106 inbox+ has 3 messages (1-3).
107 other has 7 messages (1-7).
108
109 TOTAL = 11 messages in 3 folders.'
110
111 run_test "refile -src +other all +inbox"
112 run_test 'folders -noheader' \
113 'another has 1 message (1- 1).
114 inbox has 10 messages (1-10); cur=9.
115 other+ has no messages.
116
117 TOTAL = 11 messages in 3 folders.'
118
119 # check -draft
120 start_test "-draft"
121 mv $MH_TEST_DIR/Mail/another/1 $MH_TEST_DIR/Mail/draft
122 rmdir $MH_TEST_DIR/Mail/another
123 run_test 'refile -draft +other' ''
124 run_test 'folders -noheader' \
125 'inbox has 10 messages (1-10); cur=9.
126 other+ has 1 message (1- 1).
127
128 TOTAL = 11 messages in 2 folders.'
129
130 check_for_hard_links
131 if [ $xdir_links_supported -eq 1 ]; then
132 # check -link
133 run_test 'refile 7 -src +inbox +other -link' ''
134 run_test 'folders -noheader' \
135 'inbox+ has 10 messages (1-10); cur=7.
136 other has 2 messages (1- 2).
137
138 TOTAL = 12 messages in 2 folders.'
139 # inbox/7 and other/2 are linked. Modify one and verify
140 # that the other changes as well.
141 echo '' >>$MH_TEST_DIR/Mail/other/2
142 run_test "cmp $MH_TEST_DIR/Mail/inbox/7 $MH_TEST_DIR/Mail/other/2" ''
143 else
144 # Hard links are not supported. Skip the -link test but emulate
145 # what it would have done using a copy instead of a link.
146 cp -p Mail/inbox/7 Mail/other/2
147 folder -f +inbox 7 >/dev/null
148 fi
149
150 # check -nolink
151 start_test "-nolink"
152 run_test 'refile 7 +other -link -nolink' ''
153 run_test 'folders -noheader' \
154 'inbox+ has 9 messages (1-10); cur=7.
155 other has 3 messages (1- 3).
156
157 TOTAL = 12 messages in 2 folders.'
158 # inbox/7 should no longer exist because it was moved, not linked.
159 run_test 'scan +inbox 7' "scan: message 7 doesn't exist"
160
161 # check -preserve
162 start_test "-preserve"
163 run_test 'refile 10 +other -preserve' ''
164 run_test 'folders -noheader' \
165 'inbox+ has 8 messages (1- 9).
166 other has 4 messages (1-10).
167
168 TOTAL = 12 messages in 2 folders.'
169 run_test 'scan +other last -format %(msg):%(decode{subject})' \
170 '10:Testing message 10'
171
172 # check -nopreserve
173 start_test "-nopreserve"
174 run_test 'refile 9 -src +inbox +other -preserve -nopreserve' ''
175 run_test 'folders -noheader' \
176 'inbox+ has 7 messages (1- 8).
177 other has 5 messages (1-11).
178
179 TOTAL = 12 messages in 2 folders.'
180 run_test 'scan +other last -format %(msg):%(decode{subject})' \
181 '11:Testing message 9'
182
183 sbackup="`mhparam sbackup`"
184
185 # check -unlink
186 start_test "-unlink"
187 run_test 'refile 3 -src +inbox +other -unlink' ''
188 run_test 'folders -noheader' \
189 'inbox+ has 6 messages (1- 8); cur=3.
190 other has 6 messages (1-12).
191
192 TOTAL = 12 messages in 2 folders.'
193 if test -f "$MH_TEST_DIR/Mail/inbox/${sbackup}3"; then
194 echo "$0: refile -unlink failed" 1>&2
195 failed=`expr ${failed:-0} + 1`
196 fi
197
198 # check -nounlink
199 start_test "-nounlink"
200 run_test 'refile 2 +other -unlink -nounlink' ''
201 run_test 'folders -noheader' \
202 'inbox+ has 5 messages (1- 8); cur=2.
203 other has 7 messages (1-13).
204
205 TOTAL = 12 messages in 2 folders.'
206 if test -f "$MH_TEST_DIR/Mail/inbox/${sbackup}2"; then
207 :
208 else
209 echo "$0: refile -nounlink failed" 1>&2
210 failed=`expr ${failed:-0} + 1`
211 fi
212
213 # test folder creation when stdin is not a tty
214 start_test "folder creation when stdin is not a tty"
215 refile first +newfolder </dev/null
216 run_test 'folders -noheader' \
217 'inbox+ has 4 messages (4- 8).
218 newfolder has 1 message (1- 1).
219 other has 7 messages (1-13).
220
221 TOTAL = 12 messages in 3 folders.'
222
223 # test -rmmproc
224 start_test "-rmmproc"
225 run_test 'refile first +other -rmmproc echo' '4'
226 run_test 'folders -noheader' \
227 'inbox+ has 4 messages (4- 8); cur=4.
228 newfolder has 1 message (1- 1).
229 other has 8 messages (1-14).
230
231 TOTAL = 13 messages in 3 folders.'
232
233 # test -normmproc
234 start_test "-normmproc"
235 run_test 'refile first +other -rmmproc echo -normmproc' ''
236 run_test 'folders -noheader' \
237 'inbox+ has 3 messages (5- 8).
238 newfolder has 1 message (1- 1).
239 other has 9 messages (1-15).
240
241 TOTAL = 13 messages in 3 folders.'
242
243 # test -retainsequences
244 start_test "-retainsequences"
245 mark first -seq seq1
246 mark last -seq seq2
247 refile first last -retainsequences +other
248 #### The following command changes the current folder to +other.
249 run_test 'mark +other -list -sequence seq1 -sequence seq2' \
250 "seq1: 16
251 seq2: 17"
252
253 # test -retainsequences when refiling to same folder (+other)
254 # cur is set to the original message number of the last message refiled.
255 start_test "-retainsequences when refiling to same folder (+other)"
256 mark first -seq seq1 -zero
257 mark first=2 -seq seq2 -zero
258 refile first:2 -retainsequences +other
259 run_test 'mark -list' "cur: 2
260 seq1: 18
261 seq2: 19"
262
263 finish_test
264 exit $failed