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