2 test_description="\"notmuch dump\" and \"notmuch restore\""
3 . ./test-lib.sh || exit 1
7 test_begin_subtest "Dumping all tags"
8 test_expect_success 'generate_message && notmuch new && notmuch dump > dump.expected'
10 # The use of from:cworth is rather arbitrary: it matches some of the
11 # email corpus' messages, but not all of them.
13 test_begin_subtest "Dumping all tags II"
15 'notmuch tag +ABC +DEF -- from:cworth &&
16 notmuch dump > dump-ABC_DEF.expected &&
17 ! cmp dump.expected dump-ABC_DEF.expected'
19 test_begin_subtest "Clearing all tags"
21 'sed -e "s/(\([^(]*\))$/()/" < dump.expected > clear.expected &&
22 notmuch restore --input=clear.expected &&
23 notmuch dump > clear.actual &&
24 test_cmp clear.expected clear.actual'
26 test_begin_subtest "Clearing all tags"
28 'notmuch tag +ABC +DEF -- from:cworth &&
29 notmuch restore --accumulate < dump.expected &&
30 notmuch dump > dump.actual &&
31 test_cmp dump-ABC_DEF.expected dump.actual'
33 test_begin_subtest "Restoring original tags"
35 'notmuch restore --input=dump.expected &&
36 notmuch dump > dump.actual &&
37 test_cmp dump.expected dump.actual'
39 test_begin_subtest "Restore with nothing to do"
41 'notmuch restore < dump.expected &&
42 notmuch dump > dump.actual &&
43 test_cmp dump.expected dump.actual'
45 test_begin_subtest "Accumulate with existing tags"
47 'notmuch restore --accumulate --input=dump.expected &&
48 notmuch dump > dump.actual &&
49 test_cmp dump.expected dump.actual'
51 test_begin_subtest "Accumulate with no tags"
53 'notmuch restore --accumulate < clear.expected &&
54 notmuch dump > dump.actual &&
55 test_cmp dump.expected dump.actual'
57 test_begin_subtest "Accumulate with new tags"
59 'notmuch restore --input=dump.expected &&
60 notmuch restore --accumulate --input=dump-ABC_DEF.expected &&
61 notmuch dump > OUTPUT.$test_count &&
62 notmuch restore --input=dump.expected &&
63 test_cmp dump-ABC_DEF.expected OUTPUT.$test_count'
65 # notmuch restore currently only considers the first argument.
66 test_begin_subtest "Invalid restore invocation"
68 'test_must_fail notmuch restore --input=dump.expected another_one'
70 test_begin_subtest "dump --output=outfile"
71 notmuch dump --output=dump-outfile.actual
72 test_expect_equal_file dump.expected dump-outfile.actual
74 test_begin_subtest "dump --output=outfile --"
75 notmuch dump --output=dump-1-arg-dash.actual --
76 test_expect_equal_file dump.expected dump-1-arg-dash.actual
80 test_begin_subtest "dump --gzip"
81 notmuch dump --gzip > dump-gzip.gz
83 test_expect_equal_file dump.expected dump-gzip
85 test_begin_subtest "dump --gzip --output=outfile"
86 notmuch dump --gzip --output=dump-gzip-outfile.gz
87 gunzip dump-gzip-outfile.gz
88 test_expect_equal_file dump.expected dump-gzip-outfile
90 test_begin_subtest "restoring gzipped stdin"
91 notmuch dump --gzip --output=backup.gz
92 notmuch tag +new_tag '*'
93 notmuch restore < backup.gz
94 notmuch dump --output=dump.actual
95 test_expect_equal_file dump.expected dump.actual
97 test_begin_subtest "restoring gzipped file"
98 notmuch dump --gzip --output=backup.gz
99 notmuch tag +new_tag '*'
100 notmuch restore --input=backup.gz
101 notmuch dump --output=dump.actual
102 test_expect_equal_file dump.expected dump.actual
104 # Note, we assume all messages from cworth have a message-id
105 # containing cworth.org
107 { head -1 dump.expected ; grep 'cworth[.]org' dump.expected; } > dump-cworth.expected
109 test_begin_subtest "dump -- from:cworth"
110 notmuch dump -- from:cworth > dump-dash-cworth.actual
111 test_expect_equal_file dump-cworth.expected dump-dash-cworth.actual
113 test_begin_subtest "dump --output=outfile from:cworth"
114 notmuch dump --output=dump-outfile-cworth.actual from:cworth
115 test_expect_equal_file dump-cworth.expected dump-outfile-cworth.actual
117 test_begin_subtest "dump --output=outfile -- from:cworth"
118 notmuch dump --output=dump-outfile-dash-inbox.actual -- from:cworth
119 test_expect_equal_file dump-cworth.expected dump-outfile-dash-inbox.actual
121 test_begin_subtest "Check for a safe set of message-ids"
122 notmuch search --output=messages from:cworth | sed s/^id:// > EXPECTED
123 notmuch search --output=messages from:cworth | sed s/^id:// |\
124 $TEST_DIRECTORY/hex-xcode --direction=encode > OUTPUT
125 test_expect_equal_file OUTPUT EXPECTED
127 test_begin_subtest "format=batch-tag, dump sanity check."
128 NOTMUCH_DUMP_TAGS --format=sup from:cworth | cut -f1 -d' ' | \
129 sort > EXPECTED.$test_count
130 NOTMUCH_DUMP_TAGS --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
131 sort > OUTPUT.$test_count
132 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
134 test_begin_subtest "format=batch-tag, missing newline"
135 printf "+a_tag_without_newline -- id:20091117232137.GA7669@griffis1.net" > IN
136 notmuch restore --accumulate < IN
137 NOTMUCH_DUMP_TAGS id:20091117232137.GA7669@griffis1.net > OUT
139 +a_tag_without_newline +inbox +unread -- id:20091117232137.GA7669@griffis1.net
141 test_expect_equal_file EXPECTED OUT
143 test_begin_subtest "format=batch-tag, # round-trip"
144 notmuch dump --format=sup | sort > EXPECTED.$test_count
145 notmuch dump --format=batch-tag > DUMPFILE
146 notmuch restore --format=batch-tag < DUMPFILE
147 notmuch dump --format=sup | sort > OUTPUT.$test_count
148 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
150 test_begin_subtest "format=batch-tag, # blank lines and comments"
151 notmuch dump --format=batch-tag| sort > EXPECTED.$test_count
152 notmuch restore <<EOF
153 # this line is a comment; the next has only white space
156 # the previous line is empty
158 notmuch dump --format=batch-tag | sort > OUTPUT.$test_count
159 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
161 test_begin_subtest "format=batch-tag, # reverse-round-trip empty tag"
162 cat <<EOF >EXPECTED.$test_count
163 + -- id:20091117232137.GA7669@griffis1.net
165 notmuch restore --format=batch-tag < EXPECTED.$test_count
166 NOTMUCH_DUMP_TAGS --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count
167 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
169 tag1='comic_swear=$&^%$^%\\//-+$^%$'
170 enc1=$($TEST_DIRECTORY/hex-xcode --direction=encode "$tag1")
172 tag2=$(printf 'this\n tag\t has\n spaces')
173 enc2=$($TEST_DIRECTORY/hex-xcode --direction=encode "$tag2")
175 enc3='%c3%91%c3%a5%c3%b0%c3%a3%c3%a5%c3%a9-%c3%8f%c3%8a'
176 tag3=$($TEST_DIRECTORY/hex-xcode --direction=decode $enc3)
178 notmuch dump --format=batch-tag > BACKUP
180 notmuch tag +"$tag1" +"$tag2" +"$tag3" -inbox -unread "*"
182 # initial segment of file used for several tests below.
183 cat <<EOF > comments-and-blanks
186 # next line has leading whitespace
191 test_begin_subtest 'restoring empty file is not an error'
192 notmuch restore < /dev/null 2>OUTPUT.$test_count
193 cp /dev/null EXPECTED
194 test_expect_equal_file EXPECTED OUTPUT.$test_count
196 test_begin_subtest 'file of comments and blank lines is not an error'
197 notmuch restore --input=comments-and-blanks
199 test_expect_equal "$ret_val" "0"
201 cp comments-and-blanks leading-comments-blanks-batch-tag
202 echo "+some_tag -- id:yun1vjwegii.fsf@aiko.keithp.com" \
203 >> leading-comments-blanks-batch-tag
205 test_begin_subtest 'detect format=batch-tag with leading comments and blanks'
206 notmuch restore --input=leading-comments-blanks-batch-tag
207 notmuch search --output=tags id:yun1vjwegii.fsf@aiko.keithp.com > OUTPUT.$test_count
208 echo "some_tag" > EXPECTED
209 test_expect_equal_file EXPECTED OUTPUT.$test_count
211 cp comments-and-blanks leading-comments-blanks-sup
212 echo "yun1vjwegii.fsf@aiko.keithp.com (another_tag)" \
213 >> leading-comments-blanks-sup
215 test_begin_subtest 'detect format=sup with leading comments and blanks'
216 notmuch restore --input=leading-comments-blanks-sup
217 notmuch search --output=tags id:yun1vjwegii.fsf@aiko.keithp.com > OUTPUT.$test_count
218 echo "another_tag" > EXPECTED
219 test_expect_equal_file EXPECTED OUTPUT.$test_count
221 test_begin_subtest 'format=batch-tag, round trip with strange tags'
222 notmuch dump --format=batch-tag > EXPECTED.$test_count
223 notmuch dump --format=batch-tag > DUMPFILE
224 notmuch restore --format=batch-tag < DUMPFILE
225 notmuch dump --format=batch-tag > OUTPUT.$test_count
226 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
228 test_begin_subtest 'format=batch-tag, checking encoded output'
229 NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth |\
230 awk "{ print \"+$enc1 +$enc2 +$enc3 -- \" \$5 }" > EXPECTED.$test_count
231 NOTMUCH_DUMP_TAGS --format=batch-tag -- from:cworth > OUTPUT.$test_count
232 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
234 test_begin_subtest 'restoring sane tags'
235 notmuch restore --format=batch-tag < BACKUP
236 notmuch dump --format=batch-tag > OUTPUT.$test_count
237 test_expect_equal_file BACKUP OUTPUT.$test_count
239 test_begin_subtest 'format=batch-tag, restore=auto'
240 notmuch dump --format=batch-tag > EXPECTED.$test_count
241 notmuch tag -inbox -unread "*"
242 notmuch restore --format=auto < EXPECTED.$test_count
243 notmuch dump --format=batch-tag > OUTPUT.$test_count
244 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
246 test_begin_subtest 'format=sup, restore=auto'
247 notmuch dump --format=sup > EXPECTED.$test_count
248 notmuch tag -inbox -unread "*"
249 notmuch restore --format=auto < EXPECTED.$test_count
250 notmuch dump --format=sup > OUTPUT.$test_count
251 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
253 test_begin_subtest 'format=batch-tag, restore=default'
254 notmuch dump --format=batch-tag > EXPECTED.$test_count
255 notmuch tag -inbox -unread "*"
256 notmuch restore < EXPECTED.$test_count
257 notmuch dump --format=batch-tag > OUTPUT.$test_count
258 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
260 test_begin_subtest 'format=sup, restore=default'
261 notmuch dump --format=sup > EXPECTED.$test_count
262 notmuch tag -inbox -unread "*"
263 notmuch restore < EXPECTED.$test_count
264 notmuch dump --format=sup > OUTPUT.$test_count
265 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
267 test_begin_subtest 'restore: checking error messages'
268 notmuch restore <<EOF 2>OUTPUT
269 # the next line has a space
274 # trailing whitespace
277 # this is a harmless comment, do not yell about it.
279 # the previous line was blank; also no yelling please
283 # the next non-comment line should report an an empty tag error for
284 # batch tagging, but not for restore
285 + +e -- id:20091117232137.GA7669@griffis1.net
286 # valid id, but warning about missing message
287 +e id:missing_message_id
292 +e -- id:"a_message_id_with""_a_quote"
293 +e -- id:"a message id with spaces"
294 +e -- id:an_id_with_leading_and_trailing_ws \
299 Warning: cannot parse query: a (skipping)
300 Warning: no query string [+0]
301 Warning: no query string [+a +b]
302 Warning: missing query string [+a +b ]
303 Warning: no query string after -- [+c +d --]
304 Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]
305 Warning: cannot parse query: id:" (skipping)
306 Warning: not an id query: tag:abc (skipping)
307 Warning: cannot apply tags to missing message: missing_message_id
308 Warning: cannot parse query: id:some)stuff (skipping)
309 Warning: cannot parse query: id:some stuff (skipping)
310 Warning: cannot apply tags to missing message: some"stuff
311 Warning: cannot apply tags to missing message: a_message_id_with"_a_quote
312 Warning: cannot apply tags to missing message: a message id with spaces
313 Warning: cannot apply tags to missing message: an_id_with_leading_and_trailing_ws
316 test_expect_equal_file EXPECTED OUTPUT
318 test_begin_subtest 'roundtripping random message-ids and tags'
320 ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \
323 notmuch dump --format=batch-tag| \
324 sort > EXPECTED.$test_count
326 notmuch tag +this_tag_is_very_unlikely_to_be_random '*'
328 notmuch restore --format=batch-tag < EXPECTED.$test_count
330 notmuch dump --format=batch-tag| \
331 sort > OUTPUT.$test_count
333 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
337 # Note the database is "poisoned" for sup format at this point.