0d9303cf1b6d9c5547c8da46bb0fee796ab94b28
[mmh] / 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 expected=$MH_TEST_DIR/$$.expected
20 actual=$MH_TEST_DIR/$$.actual
21
22 cd $MH_TEST_DIR
23
24 folder -create +other -fast >/dev/null
25 folder -create +another -fast >/dev/null
26
27 # check with no options and no current message
28 run_test 'refile' 'refile: no folder specified'
29
30 # check with current message
31 folder +inbox 4 >/dev/null
32 run_test 'refile +other' ''
33 run_test 'folders -noheader' \
34 'another  has no messages.
35 inbox+   has  9 messages  (1-10); cur=4.
36 other    has  1 message   (1- 1).
37
38 TOTAL = 10 messages in 3 folders.'
39
40 # check with specified message
41 folder +inbox 5 >/dev/null
42 run_test 'refile 5 +other' ''
43 run_test 'folders -noheader' \
44 'another  has no messages.
45 inbox+   has  8 messages  (1-10); cur=5.
46 other    has  2 messages  (1- 2).
47
48 TOTAL = 10 messages in 3 folders.'
49
50 # check multiple messages
51 run_test 'refile 6 7 +other' ''
52 run_test 'folders -noheader' \
53 'another  has no messages.
54 inbox+   has  6 messages  (1-10); cur=7.
55 other    has  4 messages  (1- 4).
56
57 TOTAL = 10 messages in 3 folders.'
58
59 # check multiple folders
60 run_test 'refile 8 +other +another' ''
61 run_test 'folders -noheader' \
62 'another  has 1 message   (1- 1).
63 inbox+   has 5 messages  (1-10); cur=8.
64 other    has 5 messages  (1- 5).
65
66 TOTAL = 11 messages in 3 folders.'
67
68 # check message number greater than highest
69 run_test 'refile 11 +other' "refile: message 11 doesn't exist"
70 folder -f +another >/dev/null
71
72 # check -src
73 run_test 'refile 9 -src +inbox +other' ''
74 run_test 'folders -noheader' \
75 'another  has 1 message   (1- 1).
76 inbox+   has 4 messages  (1-10); cur=9.
77 other    has 6 messages  (1- 6).
78
79 TOTAL = 11 messages in 3 folders.'
80
81 # check -file
82 run_test "refile -file $MH_TEST_DIR/Mail/inbox/10 +other" ''
83 run_test 'folders -noheader' \
84 'another  has 1 message   (1-1).
85 inbox+   has 3 messages  (1-3).
86 other    has 7 messages  (1-7).
87
88 TOTAL = 11 messages in 3 folders.'
89
90 # check -file -, which isn't supported
91 run_test "refile -file - +other <$MH_TEST_DIR/Mail/inbox/9" \
92          'refile: missing argument to -file'
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 run_test "refile -src +other all +inbox"
101 run_test 'folders -noheader' \
102 'another  has  1 message   (1- 1).
103 inbox    has 10 messages  (1-10); cur=9.
104 other+   has no messages.
105
106 TOTAL = 11 messages in 3 folders.'
107
108 # check -draft
109 mv $MH_TEST_DIR/Mail/another/1 $MH_TEST_DIR/Mail/draft
110 rmdir $MH_TEST_DIR/Mail/another
111 run_test 'refile -draft +other' ''
112 run_test 'folders -noheader' \
113 'inbox  has 10 messages  (1-10); cur=9.
114 other+ has  1 message   (1- 1).
115
116 TOTAL = 11 messages in 2 folders.'
117
118 printf '' > $$.txt
119 set +e
120 if link $$.txt $$-2.txt 2>/dev/null; then
121   # Hard links are supported.
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 set -e
140 rm -f $$.txt $$-2.txt
141
142 # check -nolink
143 run_test 'refile 7 +other -link -nolink' ''
144 run_test 'folders -noheader' \
145 'inbox+ has 9 messages  (1-10); cur=7.
146 other  has 3 messages  (1- 3).
147
148 TOTAL = 12 messages in 2 folders.'
149 # inbox/7 should no longer exist because it was moved, not linked.
150 run_test 'scan +inbox 7' "scan: message 7 doesn't exist"
151
152 # check -preserve
153 run_test 'refile 10 +other -preserve' ''
154 run_test 'folders -noheader' \
155 'inbox+ has 8 messages  (1- 9).
156 other  has 4 messages  (1-10).
157
158 TOTAL = 12 messages in 2 folders.'
159 run_test 'scan +other last -format %(msg):%(decode{subject})' \
160          '10:Testing message 10'
161
162 # check -nopreserve
163 run_test 'refile 9 -src +inbox +other -preserve -nopreserve' ''
164 run_test 'folders -noheader' \
165 'inbox+ has 7 messages  (1- 8).
166 other  has 5 messages  (1-11).
167
168 TOTAL = 12 messages in 2 folders.'
169 run_test 'scan +other last -format %(msg):%(decode{subject})' \
170          '11:Testing message 9'
171
172 # check -unlink
173 run_test 'refile 3 -src +inbox +other -unlink' ''
174 run_test 'folders -noheader' \
175 'inbox+ has 6 messages  (1- 8); cur=3.
176 other  has 6 messages  (1-12).
177
178 TOTAL = 12 messages in 2 folders.'
179 if test -f $MH_TEST_DIR/Mail/inbox/,3; then
180   echo "$0: refile -unlink failed" 1>&2
181   failed=`expr ${failed:-0} + 1`
182 fi
183
184 # check -nounlink
185 run_test 'refile 2 +other -unlink -nounlink' ''
186 run_test 'folders -noheader' \
187 'inbox+ has 5 messages  (1- 8); cur=2.
188 other  has 7 messages  (1-13).
189
190 TOTAL = 12 messages in 2 folders.'
191 if test -f $MH_TEST_DIR/Mail/inbox/,2; then
192   :
193 else
194   echo "$0: refile -nounlink failed" 1>&2
195   failed=`expr ${failed:-0} + 1`
196 fi
197
198 # test folder creation when stdin is not a tty
199 refile first +newfolder </dev/null
200 run_test 'folders -noheader' \
201 'inbox+     has 4 messages  (4- 8).
202 newfolder  has 1 message   (1- 1).
203 other      has 7 messages  (1-13).
204
205 TOTAL = 12 messages in 3 folders.'
206
207 # test -rmmproc
208 run_test 'refile first +other -rmmproc echo' '4'
209 run_test 'folders -noheader' \
210 'inbox+     has 4 messages  (4- 8); cur=4.
211 newfolder  has 1 message   (1- 1).
212 other      has 8 messages  (1-14).
213
214 TOTAL = 13 messages in 3 folders.'
215
216 # test -normmproc
217 run_test 'refile first +other -rmmproc echo -normmproc' ''
218 run_test 'folders -noheader' \
219 'inbox+     has 3 messages  (5- 8).
220 newfolder  has 1 message   (1- 1).
221 other      has 9 messages  (1-15).
222
223 TOTAL = 13 messages in 3 folders.'
224
225
226 exit $failed