File: test-refile

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (264 lines) | stat: -rwxr-xr-x 7,303 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/sh
######################################################
#
# Test refile
#
######################################################

set -e

if test -z "${MH_OBJ_DIR}"; then
    srcdir=`dirname $0`/../..
    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi

. "$MH_OBJ_DIR/test/common.sh"

setup_test

check_exit '-eq 1' refile -

expected=$MH_TEST_DIR/$$.expected
actual=$MH_TEST_DIR/$$.actual

cd $MH_TEST_DIR

run_prog folder -create +other -fast >/dev/null
run_prog folder -create +another -fast >/dev/null

# check with no options and no current message
start_test "with no options and no current message"
run_test 'refile' 'refile: no folder specified'

# check with current message
start_test "with current message"
run_prog folder +inbox 4 >/dev/null
run_test 'refile +other' ''
run_test 'folders -noheader' \
'another  has no messages.
inbox+   has  9 messages  (1-10); cur=4.
other    has  1 message   (1- 1).

TOTAL = 10 messages in 3 folders.'

# check with specified message
start_test "with specified message"
run_prog folder +inbox 5 >/dev/null
run_test 'refile 5 +other' ''
run_test 'folders -noheader' \
'another  has no messages.
inbox+   has  8 messages  (1-10); cur=5.
other    has  2 messages  (1- 2).

TOTAL = 10 messages in 3 folders.'

# check multiple messages
start_test "multiple messages"
run_test 'refile 6 7 +other' ''
run_test 'folders -noheader' \
'another  has no messages.
inbox+   has  6 messages  (1-10); cur=7.
other    has  4 messages  (1- 4).

TOTAL = 10 messages in 3 folders.'

# check multiple folders
start_test "multiple folders"
run_test 'refile 8 +other +another' ''
run_test 'folders -noheader' \
'another  has 1 message   (1- 1).
inbox+   has 5 messages  (1-10); cur=8.
other    has 5 messages  (1- 5).

TOTAL = 11 messages in 3 folders.'

# check message number greater than highest
start_test "message number greater than highest"
run_test 'refile 11 +other' "refile: message 11 doesn't exist"
run_prog folder -f +another >/dev/null

# check -src
start_test "-src"
run_test 'refile 9 -src +inbox +other' ''
run_test 'folders -noheader' \
'another  has 1 message   (1- 1).
inbox+   has 4 messages  (1-10); cur=9.
other    has 6 messages  (1- 6).

TOTAL = 11 messages in 3 folders.'

# check -file
start_test "-file"
run_test "refile -file $MH_TEST_DIR/Mail/inbox/10 +other" ''
run_test 'folders -noheader' \
'another  has 1 message   (1-1).
inbox+   has 3 messages  (1-3).
other    has 7 messages  (1-7).

TOTAL = 11 messages in 3 folders.'

# check -file -, which isn't supported
start_test "-file -, which isn't supported"
run_test "refile -file - +other <$MH_TEST_DIR/Mail/inbox/9" \
         'refile: missing argument to -file'
run_test 'folders -noheader' \
'another  has 1 message   (1-1).
inbox+   has 3 messages  (1-3).
other    has 7 messages  (1-7).

TOTAL = 11 messages in 3 folders.'

run_test "refile -src +other all +inbox"
run_test 'folders -noheader' \
'another  has  1 message   (1- 1).
inbox    has 10 messages  (1-10); cur=9.
other+   has no messages.

TOTAL = 11 messages in 3 folders.'

# check -draft
start_test "-draft"
mv $MH_TEST_DIR/Mail/another/1 $MH_TEST_DIR/Mail/draft
rmdir $MH_TEST_DIR/Mail/another
run_test 'refile -draft +other' ''
run_test 'folders -noheader' \
'inbox  has 10 messages  (1-10); cur=9.
other+ has  1 message   (1- 1).

TOTAL = 11 messages in 2 folders.'

check_for_hard_links
if [ $xdir_links_supported -eq 1 ]; then
  # check -link
  run_test 'refile 7 -src +inbox +other -link' ''
  run_test 'folders -noheader' \
  'inbox+ has 10 messages  (1-10); cur=7.
other  has  2 messages  (1- 2).

TOTAL = 12 messages in 2 folders.'
  # inbox/7 and other/2 are linked.  Modify one and verify
  # that the other changes as well.
  echo '' >>$MH_TEST_DIR/Mail/other/2
  run_test "cmp $MH_TEST_DIR/Mail/inbox/7 $MH_TEST_DIR/Mail/other/2" ''
else
  # Hard links are not supported.  Skip the -link test but emulate
  # what it would have done using a copy instead of a link.
  cp -p Mail/inbox/7 Mail/other/2
  folder -f +inbox 7 >/dev/null
fi

# check -nolink
start_test "-nolink"
run_test 'refile 7 +other -link -nolink' ''
run_test 'folders -noheader' \
'inbox+ has 9 messages  (1-10); cur=7.
other  has 3 messages  (1- 3).

TOTAL = 12 messages in 2 folders.'
# inbox/7 should no longer exist because it was moved, not linked.
run_test 'scan +inbox 7' "scan: message 7 doesn't exist"

# check -preserve
start_test "-preserve"
run_test 'refile 10 +other -preserve' ''
run_test 'folders -noheader' \
'inbox+ has 8 messages  (1- 9).
other  has 4 messages  (1-10).

TOTAL = 12 messages in 2 folders.'
run_test 'scan +other last -format %(msg):%(decode{subject})' \
         '10:Testing message 10'

# check -nopreserve
start_test "-nopreserve"
run_test 'refile 9 -src +inbox +other -preserve -nopreserve' ''
run_test 'folders -noheader' \
'inbox+ has 7 messages  (1- 8).
other  has 5 messages  (1-11).

TOTAL = 12 messages in 2 folders.'
run_test 'scan +other last -format %(msg):%(decode{subject})' \
         '11:Testing message 9'

sbackup="`mhparam sbackup`"

# check -unlink
start_test "-unlink"
run_test 'refile 3 -src +inbox +other -unlink' ''
run_test 'folders -noheader' \
'inbox+ has 6 messages  (1- 8); cur=3.
other  has 6 messages  (1-12).

TOTAL = 12 messages in 2 folders.'
if test -f "$MH_TEST_DIR/Mail/inbox/${sbackup}3"; then
  echo "$0: refile -unlink failed" 1>&2
  failed=`expr ${failed:-0} + 1`
fi

# check -nounlink
start_test "-nounlink"
run_test 'refile 2 +other -unlink -nounlink' ''
run_test 'folders -noheader' \
'inbox+ has 5 messages  (1- 8); cur=2.
other  has 7 messages  (1-13).

TOTAL = 12 messages in 2 folders.'
if test -f "$MH_TEST_DIR/Mail/inbox/${sbackup}2"; then
  :
else
  echo "$0: refile -nounlink failed" 1>&2
  failed=`expr ${failed:-0} + 1`
fi

# test folder creation when stdin is not a tty
start_test "folder creation when stdin is not a tty"
refile first +newfolder </dev/null
run_test 'folders -noheader' \
'inbox+     has 4 messages  (4- 8).
newfolder  has 1 message   (1- 1).
other      has 7 messages  (1-13).

TOTAL = 12 messages in 3 folders.'

# test -rmmproc
start_test "-rmmproc"
run_test 'refile first +other -rmmproc echo' '4'
run_test 'folders -noheader' \
'inbox+     has 4 messages  (4- 8); cur=4.
newfolder  has 1 message   (1- 1).
other      has 8 messages  (1-14).

TOTAL = 13 messages in 3 folders.'

# test -normmproc
start_test "-normmproc"
run_test 'refile first +other -rmmproc echo -normmproc' ''
run_test 'folders -noheader' \
'inbox+     has 3 messages  (5- 8).
newfolder  has 1 message   (1- 1).
other      has 9 messages  (1-15).

TOTAL = 13 messages in 3 folders.'

# test -retainsequences
start_test "-retainsequences"
mark first -seq seq1
mark last -seq seq2
refile first last -retainsequences +other
#### The following command changes the current folder to +other.
run_test 'mark +other -list -sequence seq1 -sequence seq2' \
         "seq1: 16
seq2: 17"

# test -retainsequences when refiling to same folder (+other)
# cur is set to the original message number of the last message refiled.
start_test "-retainsequences when refiling to same folder (+other)"
mark first -seq seq1 -zero
mark first=2 -seq seq2 -zero
refile first:2 -retainsequences +other
run_test 'mark -list' "cur: 2
seq1: 18
seq2: 19"

finish_test
exit $failed