Updates to test/common.sh.in:
[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 check_for_hard_links
119 if [ $hard_links_supported -eq 1 ]; then
120   # check -link
121   run_test 'refile 7 -src +inbox +other -link' ''
122   run_test 'folders -noheader' \
123   'inbox+ has 10 messages  (1-10); cur=7.
124 other  has  2 messages  (1- 2).
125
126 TOTAL = 12 messages in 2 folders.'
127   # inbox/7 and other/2 are linked.  Modify one and verify
128   # that the other changes as well.
129   echo '' >>$MH_TEST_DIR/Mail/other/2
130   run_test "cmp $MH_TEST_DIR/Mail/inbox/7 $MH_TEST_DIR/Mail/other/2" ''
131 else
132   # Hard links are not supported.  Skip the -link test but emulate
133   # what it would have done using a copy instead of a link.
134   cp -p Mail/inbox/7 Mail/other/2
135   folder -f +inbox 7 >/dev/null
136 fi
137
138 # check -nolink
139 run_test 'refile 7 +other -link -nolink' ''
140 run_test 'folders -noheader' \
141 'inbox+ has 9 messages  (1-10); cur=7.
142 other  has 3 messages  (1- 3).
143
144 TOTAL = 12 messages in 2 folders.'
145 # inbox/7 should no longer exist because it was moved, not linked.
146 run_test 'scan +inbox 7' "scan: message 7 doesn't exist"
147
148 # check -preserve
149 run_test 'refile 10 +other -preserve' ''
150 run_test 'folders -noheader' \
151 'inbox+ has 8 messages  (1- 9).
152 other  has 4 messages  (1-10).
153
154 TOTAL = 12 messages in 2 folders.'
155 run_test 'scan +other last -format %(msg):%(decode{subject})' \
156          '10:Testing message 10'
157
158 # check -nopreserve
159 run_test 'refile 9 -src +inbox +other -preserve -nopreserve' ''
160 run_test 'folders -noheader' \
161 'inbox+ has 7 messages  (1- 8).
162 other  has 5 messages  (1-11).
163
164 TOTAL = 12 messages in 2 folders.'
165 run_test 'scan +other last -format %(msg):%(decode{subject})' \
166          '11:Testing message 9'
167
168 # check -unlink
169 run_test 'refile 3 -src +inbox +other -unlink' ''
170 run_test 'folders -noheader' \
171 'inbox+ has 6 messages  (1- 8); cur=3.
172 other  has 6 messages  (1-12).
173
174 TOTAL = 12 messages in 2 folders.'
175 if test -f $MH_TEST_DIR/Mail/inbox/,3; then
176   echo "$0: refile -unlink failed" 1>&2
177   failed=`expr ${failed:-0} + 1`
178 fi
179
180 # check -nounlink
181 run_test 'refile 2 +other -unlink -nounlink' ''
182 run_test 'folders -noheader' \
183 'inbox+ has 5 messages  (1- 8); cur=2.
184 other  has 7 messages  (1-13).
185
186 TOTAL = 12 messages in 2 folders.'
187 if test -f $MH_TEST_DIR/Mail/inbox/,2; then
188   :
189 else
190   echo "$0: refile -nounlink failed" 1>&2
191   failed=`expr ${failed:-0} + 1`
192 fi
193
194 # test folder creation when stdin is not a tty
195 refile first +newfolder </dev/null
196 run_test 'folders -noheader' \
197 'inbox+     has 4 messages  (4- 8).
198 newfolder  has 1 message   (1- 1).
199 other      has 7 messages  (1-13).
200
201 TOTAL = 12 messages in 3 folders.'
202
203 # test -rmmproc
204 run_test 'refile first +other -rmmproc echo' '4'
205 run_test 'folders -noheader' \
206 'inbox+     has 4 messages  (4- 8); cur=4.
207 newfolder  has 1 message   (1- 1).
208 other      has 8 messages  (1-14).
209
210 TOTAL = 13 messages in 3 folders.'
211
212 # test -normmproc
213 run_test 'refile first +other -rmmproc echo -normmproc' ''
214 run_test 'folders -noheader' \
215 'inbox+     has 3 messages  (5- 8).
216 newfolder  has 1 message   (1- 1).
217 other      has 9 messages  (1-15).
218
219 TOTAL = 13 messages in 3 folders.'
220
221
222 exit $failed