2 test_description="\"notmuch dump\" and \"notmuch restore\""
3 . $(dirname "$0")/test-lib.sh || exit 1
5 NOTMUCH_NEW > /dev/null
6 test_begin_subtest "dump header"
8 #notmuch-dump batch-tag:3 config,properties,tags
11 test_expect_equal_file EXPECTED OUTPUT
14 test_begin_subtest "Dumping all tags"
15 test_expect_success 'generate_message && notmuch new && notmuch dump > dump.expected'
17 # The use of from:cworth is rather arbitrary: it matches some of the
18 # email corpus' messages, but not all of them.
20 test_begin_subtest "Dumping all tags II"
22 'notmuch tag +ABC +DEF -- from:cworth &&
23 notmuch dump > dump-ABC_DEF.expected &&
24 ! cmp dump.expected dump-ABC_DEF.expected'
26 test_begin_subtest "Clearing all tags"
28 'sed -e "s/(\([^(]*\))$/()/" < dump.expected > clear.expected &&
29 notmuch restore --input=clear.expected &&
30 notmuch dump > clear.actual &&
31 test_cmp clear.expected clear.actual'
33 test_begin_subtest "Clearing all tags"
35 'notmuch tag +ABC +DEF -- from:cworth &&
36 notmuch restore --accumulate < dump.expected &&
37 notmuch dump > dump.actual &&
38 test_cmp dump-ABC_DEF.expected dump.actual'
40 test_begin_subtest "Restoring original tags"
42 'notmuch restore --input=dump.expected &&
43 notmuch dump > dump.actual &&
44 test_cmp dump.expected dump.actual'
46 test_begin_subtest "Restore with nothing to do"
48 'notmuch restore < dump.expected &&
49 notmuch dump > dump.actual &&
50 test_cmp dump.expected dump.actual'
52 test_begin_subtest "Accumulate with existing tags"
54 'notmuch restore --accumulate --input=dump.expected &&
55 notmuch dump > dump.actual &&
56 test_cmp dump.expected dump.actual'
58 test_begin_subtest "Accumulate with no tags"
60 'notmuch restore --accumulate < clear.expected &&
61 notmuch dump > dump.actual &&
62 test_cmp dump.expected dump.actual'
64 test_begin_subtest "Accumulate with new tags"
66 'notmuch restore --input=dump.expected &&
67 notmuch restore --accumulate --input=dump-ABC_DEF.expected &&
68 notmuch dump > OUTPUT.$test_count &&
69 notmuch restore --input=dump.expected &&
70 test_cmp dump-ABC_DEF.expected OUTPUT.$test_count'
72 # notmuch restore currently only considers the first argument.
73 test_begin_subtest "Invalid restore invocation"
75 'test_must_fail notmuch restore --input=dump.expected another_one'
77 test_begin_subtest "dump --output=outfile"
78 notmuch dump --output=dump-outfile.actual
79 test_expect_equal_file dump.expected dump-outfile.actual
81 test_begin_subtest "dump --output=outfile --"
82 notmuch dump --output=dump-1-arg-dash.actual --
83 test_expect_equal_file dump.expected dump-1-arg-dash.actual
87 test_begin_subtest "dump --gzip"
88 notmuch dump --gzip > dump-gzip.gz
90 test_expect_equal_file dump.expected dump-gzip
92 test_begin_subtest "dump --gzip --output=outfile"
93 notmuch dump --gzip --output=dump-gzip-outfile.gz
94 gunzip dump-gzip-outfile.gz
95 test_expect_equal_file dump.expected dump-gzip-outfile
97 test_begin_subtest "restoring gzipped stdin"
98 notmuch dump --gzip --output=backup.gz
99 notmuch tag +new_tag '*'
100 notmuch restore < backup.gz
101 notmuch dump --output=dump.actual
102 test_expect_equal_file dump.expected dump.actual
104 test_begin_subtest "restoring gzipped file"
105 notmuch dump --gzip --output=backup.gz
106 notmuch tag +new_tag '*'
107 notmuch restore --input=backup.gz
108 notmuch dump --output=dump.actual
109 test_expect_equal_file dump.expected dump.actual
111 # Note, we assume all messages from cworth have a message-id
112 # containing cworth.org
114 { head -1 dump.expected ; grep 'cworth[.]org' dump.expected; } > dump-cworth.expected
116 test_begin_subtest "dump -- from:cworth"
117 notmuch dump -- from:cworth > dump-dash-cworth.actual
118 test_expect_equal_file dump-cworth.expected dump-dash-cworth.actual
120 test_begin_subtest "dump --output=outfile from:cworth"
121 notmuch dump --output=dump-outfile-cworth.actual from:cworth
122 test_expect_equal_file dump-cworth.expected dump-outfile-cworth.actual
124 test_begin_subtest "dump --output=outfile -- from:cworth"
125 notmuch dump --output=dump-outfile-dash-inbox.actual -- from:cworth
126 test_expect_equal_file dump-cworth.expected dump-outfile-dash-inbox.actual
128 test_begin_subtest "Check for a safe set of message-ids"
129 notmuch search --output=messages from:cworth | sed s/^id:// > EXPECTED
130 notmuch search --output=messages from:cworth | sed s/^id:// |\
131 $TEST_DIRECTORY/hex-xcode --direction=encode > OUTPUT
132 test_expect_equal_file EXPECTED OUTPUT
134 test_begin_subtest "format=batch-tag, dump sanity check."
135 NOTMUCH_DUMP_TAGS --format=sup from:cworth | cut -f1 -d' ' | \
136 sort > EXPECTED.$test_count
137 NOTMUCH_DUMP_TAGS --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
138 sort > OUTPUT.$test_count
139 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
141 test_begin_subtest "format=batch-tag, missing newline"
142 printf "+a_tag_without_newline -- id:20091117232137.GA7669@griffis1.net" > IN
143 notmuch restore --accumulate < IN
144 NOTMUCH_DUMP_TAGS id:20091117232137.GA7669@griffis1.net > OUT
146 +a_tag_without_newline +inbox +unread -- id:20091117232137.GA7669@griffis1.net
148 test_expect_equal_file EXPECTED OUT
150 test_begin_subtest "format=batch-tag, # round-trip"
151 notmuch dump --format=sup | sort > EXPECTED.$test_count
152 notmuch dump --format=batch-tag > DUMPFILE
153 notmuch restore --format=batch-tag < DUMPFILE
154 notmuch dump --format=sup | sort > OUTPUT.$test_count
155 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
157 test_begin_subtest "format=batch-tag, # blank lines and comments"
158 notmuch dump --format=batch-tag| sort > EXPECTED.$test_count
159 notmuch restore <<EOF
160 # this line is a comment; the next has only white space
163 # the previous line is empty
165 notmuch dump --format=batch-tag | sort > OUTPUT.$test_count
166 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
168 test_begin_subtest "format=batch-tag, # reverse-round-trip empty tag"
169 cat <<EOF >EXPECTED.$test_count
170 + -- id:20091117232137.GA7669@griffis1.net
172 notmuch restore --format=batch-tag < EXPECTED.$test_count
173 NOTMUCH_DUMP_TAGS --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count
174 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
176 tag1='comic_swear=$&^%$^%\\//-+$^%$'
177 enc1=$($TEST_DIRECTORY/hex-xcode --direction=encode "$tag1")
179 tag2=$(printf 'this\n tag\t has\n spaces')
180 enc2=$($TEST_DIRECTORY/hex-xcode --direction=encode "$tag2")
182 enc3='%c3%91%c3%a5%c3%b0%c3%a3%c3%a5%c3%a9-%c3%8f%c3%8a'
183 tag3=$($TEST_DIRECTORY/hex-xcode --direction=decode $enc3)
185 notmuch dump --format=batch-tag > BACKUP
187 notmuch tag +"$tag1" +"$tag2" +"$tag3" -inbox -unread "*"
189 # initial segment of file used for several tests below.
190 cat <<EOF > comments-and-blanks
193 # next line has leading whitespace
198 test_begin_subtest 'restoring empty file is not an error'
199 notmuch restore < /dev/null 2>OUTPUT.$test_count
200 cp /dev/null EXPECTED
201 test_expect_equal_file EXPECTED OUTPUT.$test_count
203 test_begin_subtest 'file of comments and blank lines is not an error'
204 notmuch restore --input=comments-and-blanks
206 test_expect_equal "$ret_val" "0"
208 cp comments-and-blanks leading-comments-blanks-batch-tag
209 echo "+some_tag -- id:yun1vjwegii.fsf@aiko.keithp.com" \
210 >> leading-comments-blanks-batch-tag
212 test_begin_subtest 'detect format=batch-tag with leading comments and blanks'
213 notmuch restore --input=leading-comments-blanks-batch-tag
214 notmuch search --output=tags id:yun1vjwegii.fsf@aiko.keithp.com > OUTPUT.$test_count
215 echo "some_tag" > EXPECTED
216 test_expect_equal_file EXPECTED OUTPUT.$test_count
218 cp comments-and-blanks leading-comments-blanks-sup
219 echo "yun1vjwegii.fsf@aiko.keithp.com (another_tag)" \
220 >> leading-comments-blanks-sup
222 test_begin_subtest 'detect format=sup with leading comments and blanks'
223 notmuch restore --input=leading-comments-blanks-sup
224 notmuch search --output=tags id:yun1vjwegii.fsf@aiko.keithp.com > OUTPUT.$test_count
225 echo "another_tag" > EXPECTED
226 test_expect_equal_file EXPECTED OUTPUT.$test_count
228 test_begin_subtest 'format=batch-tag, round trip with strange tags'
229 notmuch dump --format=batch-tag > EXPECTED.$test_count
230 notmuch dump --format=batch-tag > DUMPFILE
231 notmuch restore --format=batch-tag < DUMPFILE
232 notmuch dump --format=batch-tag > OUTPUT.$test_count
233 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
235 test_begin_subtest 'format=batch-tag, checking encoded output'
236 NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth |\
237 awk "{ print \"+$enc1 +$enc2 +$enc3 -- \" \$5 }" > EXPECTED.$test_count
238 NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth > OUTPUT.$test_count
239 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
241 test_begin_subtest 'restoring sane tags'
242 notmuch restore --format=batch-tag < BACKUP
243 notmuch dump --format=batch-tag > OUTPUT.$test_count
244 test_expect_equal_file BACKUP OUTPUT.$test_count
246 test_begin_subtest 'format=batch-tag, restore=auto'
247 notmuch dump --format=batch-tag > EXPECTED.$test_count
248 notmuch tag -inbox -unread "*"
249 notmuch restore --format=auto < EXPECTED.$test_count
250 notmuch dump --format=batch-tag > OUTPUT.$test_count
251 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
253 test_begin_subtest 'format=sup, restore=auto'
254 notmuch dump --format=sup > EXPECTED.$test_count
255 notmuch tag -inbox -unread "*"
256 notmuch restore --format=auto < EXPECTED.$test_count
257 notmuch dump --format=sup > OUTPUT.$test_count
258 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
260 test_begin_subtest 'format=batch-tag, restore=default'
261 notmuch dump --format=batch-tag > EXPECTED.$test_count
262 notmuch tag -inbox -unread "*"
263 notmuch restore < EXPECTED.$test_count
264 notmuch dump --format=batch-tag > OUTPUT.$test_count
265 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
267 test_begin_subtest 'format=sup, restore=default'
268 notmuch dump --format=sup > EXPECTED.$test_count
269 notmuch tag -inbox -unread "*"
270 notmuch restore < EXPECTED.$test_count
271 notmuch dump --format=sup > OUTPUT.$test_count
272 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
274 test_begin_subtest 'restore: checking error messages'
275 notmuch restore <<EOF 2>OUTPUT
276 # the next line has a space
281 # trailing whitespace
284 # this is a harmless comment, do not yell about it.
286 # the previous line was blank; also no yelling please
290 # the next non-comment line should report an an empty tag error for
291 # batch tagging, but not for restore
292 + +e -- id:20091117232137.GA7669@griffis1.net
293 # valid id, but warning about missing message
294 +e id:missing_message_id
299 +e -- id:"a_message_id_with""_a_quote"
300 +e -- id:"a message id with spaces"
301 +e -- id:an_id_with_leading_and_trailing_ws \
306 Warning: cannot parse query: a (skipping)
307 Warning: no query string [+0]
308 Warning: no query string [+a +b]
309 Warning: missing query string [+a +b ]
310 Warning: no query string after -- [+c +d --]
311 Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]
312 Warning: cannot parse query: id:" (skipping)
313 Warning: not an id query: tag:abc (skipping)
314 Warning: cannot apply tags to missing message: missing_message_id
315 Warning: cannot parse query: id:some)stuff (skipping)
316 Warning: cannot parse query: id:some stuff (skipping)
317 Warning: cannot apply tags to missing message: some"stuff
318 Warning: cannot apply tags to missing message: a_message_id_with"_a_quote
319 Warning: cannot apply tags to missing message: a message id with spaces
320 Warning: cannot apply tags to missing message: an_id_with_leading_and_trailing_ws
323 test_expect_equal_file EXPECTED OUTPUT
325 test_begin_subtest 'roundtripping random message-ids and tags'
327 ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \
330 notmuch dump --format=batch-tag| \
331 sort > EXPECTED.$test_count
333 notmuch tag +this_tag_is_very_unlikely_to_be_random '*'
335 notmuch restore --format=batch-tag < EXPECTED.$test_count
337 notmuch dump --format=batch-tag| \
338 sort > OUTPUT.$test_count
340 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
344 # Note the database is "poisoned" for sup format at this point.