]> git.notmuchmail.org Git - notmuch/blob - test/dump-restore
test/dump-restore: add test for warning/error messages
[notmuch] / test / dump-restore
1 #!/usr/bin/env bash
2 test_description="\"notmuch dump\" and \"notmuch restore\""
3 . ./test-lib.sh
4
5 add_email_corpus
6
7 test_expect_success 'Dumping all tags' \
8   'generate_message &&
9   notmuch new &&
10   notmuch dump > dump.expected'
11
12 # The use of from:cworth is rather arbitrary: it matches some of the
13 # email corpus' messages, but not all of them.
14
15 test_expect_success 'Dumping all tags II' \
16   'notmuch tag +ABC +DEF -- from:cworth &&
17   notmuch dump > dump-ABC_DEF.expected &&
18   ! cmp dump.expected dump-ABC_DEF.expected'
19
20 test_expect_success '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'
25
26 test_expect_success 'Accumulate original tags' \
27   'notmuch tag +ABC +DEF -- from:cworth &&
28   notmuch restore --accumulate < dump.expected &&
29   notmuch dump > dump.actual &&
30   test_cmp dump-ABC_DEF.expected dump.actual'
31
32 test_expect_success 'Restoring original tags' \
33   'notmuch restore --input=dump.expected &&
34   notmuch dump > dump.actual &&
35   test_cmp dump.expected dump.actual'
36
37 test_expect_success 'Restore with nothing to do' \
38   'notmuch restore < dump.expected &&
39   notmuch dump > dump.actual &&
40   test_cmp dump.expected dump.actual'
41
42 test_expect_success 'Accumulate with existing tags' \
43   'notmuch restore --accumulate --input=dump.expected &&
44   notmuch dump > dump.actual &&
45   test_cmp dump.expected dump.actual'
46
47 test_expect_success 'Accumulate with no tags' \
48   'notmuch restore --accumulate < clear.expected &&
49   notmuch dump > dump.actual &&
50   test_cmp dump.expected dump.actual'
51
52 test_expect_success 'Accumulate with new tags' \
53   'notmuch restore --input=dump.expected &&
54   notmuch restore --accumulate --input=dump-ABC_DEF.expected &&
55   notmuch dump >  OUTPUT.$test_count &&
56   notmuch restore --input=dump.expected &&
57   test_cmp dump-ABC_DEF.expected OUTPUT.$test_count'
58
59 # notmuch restore currently only considers the first argument.
60 test_expect_success 'Invalid restore invocation' \
61   'test_must_fail notmuch restore --input=dump.expected another_one'
62
63 test_begin_subtest "dump --output=outfile"
64 notmuch dump --output=dump-outfile.actual
65 test_expect_equal_file dump.expected dump-outfile.actual
66
67 test_begin_subtest "dump --output=outfile --"
68 notmuch dump --output=dump-1-arg-dash.actual --
69 test_expect_equal_file dump.expected dump-1-arg-dash.actual
70
71 # Note, we assume all messages from cworth have a message-id
72 # containing cworth.org
73
74 grep 'cworth[.]org' dump.expected > dump-cworth.expected
75
76 test_begin_subtest "dump -- from:cworth"
77 notmuch dump -- from:cworth > dump-dash-cworth.actual
78 test_expect_equal_file dump-cworth.expected dump-dash-cworth.actual
79
80 test_begin_subtest "dump --output=outfile from:cworth"
81 notmuch dump --output=dump-outfile-cworth.actual from:cworth
82 test_expect_equal_file dump-cworth.expected dump-outfile-cworth.actual
83
84 test_begin_subtest "dump --output=outfile -- from:cworth"
85 notmuch dump --output=dump-outfile-dash-inbox.actual -- from:cworth
86 test_expect_equal_file dump-cworth.expected dump-outfile-dash-inbox.actual
87
88 test_begin_subtest "Check for a safe set of message-ids"
89 notmuch search --output=messages from:cworth | sed s/^id:// > EXPECTED
90 notmuch search --output=messages from:cworth | sed s/^id:// |\
91         $TEST_DIRECTORY/hex-xcode --direction=encode > OUTPUT
92 test_expect_equal_file OUTPUT EXPECTED
93
94 test_begin_subtest "format=batch-tag, dump sanity check."
95 notmuch dump --format=sup from:cworth | cut -f1 -d' ' | \
96     sort > EXPECTED.$test_count
97 notmuch dump --format=batch-tag from:cworth | sed 's/^.*-- id://' | \
98     sort > OUTPUT.$test_count
99 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
100
101 test_begin_subtest "format=batch-tag, # round-trip"
102 notmuch dump --format=sup | sort > EXPECTED.$test_count
103 notmuch dump --format=batch-tag | notmuch restore --format=batch-tag
104 notmuch dump --format=sup | sort > OUTPUT.$test_count
105 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
106
107 test_begin_subtest "format=batch-tag, # blank lines and comments"
108 notmuch dump --format=batch-tag| sort > EXPECTED.$test_count
109 notmuch restore <<EOF
110 # this line is a comment; the next has only white space
111          
112
113 # the previous line is empty
114 EOF
115 notmuch dump --format=batch-tag | sort > OUTPUT.$test_count
116 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
117
118 test_begin_subtest "format=batch-tag, # reverse-round-trip empty tag"
119 cat <<EOF >EXPECTED.$test_count
120 + -- id:20091117232137.GA7669@griffis1.net
121 EOF
122 notmuch restore --format=batch-tag < EXPECTED.$test_count
123 notmuch dump --format=batch-tag id:20091117232137.GA7669@griffis1.net > OUTPUT.$test_count
124 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
125
126 tag1='comic_swear=$&^%$^%\\//-+$^%$'
127 enc1=$($TEST_DIRECTORY/hex-xcode --direction=encode "$tag1")
128
129 tag2=$(printf 'this\n tag\t has\n spaces')
130 enc2=$($TEST_DIRECTORY/hex-xcode --direction=encode "$tag2")
131
132 enc3='%c3%91%c3%a5%c3%b0%c3%a3%c3%a5%c3%a9-%c3%8f%c3%8a'
133 tag3=$($TEST_DIRECTORY/hex-xcode --direction=decode $enc3)
134
135 notmuch dump --format=batch-tag > BACKUP
136
137 notmuch tag +"$tag1" +"$tag2" +"$tag3" -inbox -unread "*"
138
139 test_begin_subtest 'format=batch-tag, round trip with strange tags'
140 notmuch dump --format=batch-tag > EXPECTED.$test_count
141 notmuch dump --format=batch-tag | notmuch restore --format=batch-tag
142 notmuch dump --format=batch-tag > OUTPUT.$test_count
143 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
144
145 test_begin_subtest 'format=batch-tag, checking encoded output'
146 notmuch dump --format=batch-tag -- from:cworth |\
147          awk "{ print \"+$enc1 +$enc2 +$enc3 -- \" \$5 }" > EXPECTED.$test_count
148 notmuch dump --format=batch-tag -- from:cworth  > OUTPUT.$test_count
149 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
150
151 test_begin_subtest 'restoring sane tags'
152 notmuch restore --format=batch-tag < BACKUP
153 notmuch dump --format=batch-tag > OUTPUT.$test_count
154 test_expect_equal_file BACKUP OUTPUT.$test_count
155
156 test_begin_subtest 'format=batch-tag, restore=auto'
157 notmuch dump --format=batch-tag > EXPECTED.$test_count
158 notmuch tag -inbox -unread "*"
159 notmuch restore --format=auto < EXPECTED.$test_count
160 notmuch dump --format=batch-tag > OUTPUT.$test_count
161 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
162
163 test_begin_subtest 'format=sup, restore=auto'
164 notmuch dump --format=sup > EXPECTED.$test_count
165 notmuch tag -inbox -unread "*"
166 notmuch restore --format=auto < EXPECTED.$test_count
167 notmuch dump --format=sup > OUTPUT.$test_count
168 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
169
170 test_begin_subtest 'format=batch-tag, restore=default'
171 notmuch dump --format=batch-tag > EXPECTED.$test_count
172 notmuch tag -inbox -unread "*"
173 notmuch restore < EXPECTED.$test_count
174 notmuch dump --format=batch-tag > OUTPUT.$test_count
175 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
176
177 test_begin_subtest 'format=sup, restore=default'
178 notmuch dump --format=sup > EXPECTED.$test_count
179 notmuch tag -inbox -unread "*"
180 notmuch restore < EXPECTED.$test_count
181 notmuch dump --format=sup > OUTPUT.$test_count
182 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
183
184 test_begin_subtest 'restore: checking error messages'
185 notmuch restore <<EOF 2>OUTPUT
186 # the next line has a space
187  
188 a
189 +0
190 +a +b
191 # trailing whitespace
192 +a +b 
193 +c +d --
194 # this is a harmless comment, do not yell about it.
195
196 # the previous line was blank; also no yelling please
197 +%zz -- id:whatever
198 +e +f id:%yy
199 # the next non-comment line should report an an empty tag error for
200 # batch tagging, but not for restore
201 + +e -- id:20091117232137.GA7669@griffis1.net
202 # highlight the sketchy id parsing; this should be last
203 +g -- id:foo and bar
204 EOF
205
206 cat <<EOF > EXPECTED
207 Warning: unsupported query: a
208 Warning: no query string [+0]
209 Warning: no query string [+a +b]
210 Warning: missing query string [+a +b ]
211 Warning: no query string after -- [+c +d --]
212 Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]
213 Warning: hex decoding of query id:%yy failed [+e +f id:%yy]
214 Warning: cannot apply tags to missing message: foo and bar
215 EOF
216
217 test_expect_equal_file EXPECTED OUTPUT
218
219 test_begin_subtest 'roundtripping random message-ids and tags'
220
221     ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \
222                         --num-messages=100
223
224      notmuch dump --format=batch-tag| \
225          sort > EXPECTED.$test_count
226
227      notmuch tag +this_tag_is_very_unlikely_to_be_random '*'
228
229      notmuch restore --format=batch-tag < EXPECTED.$test_count
230
231      notmuch dump --format=batch-tag| \
232          sort > OUTPUT.$test_count
233
234 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
235
236 test_done
237
238 # Note the database is "poisoned" for sup format at this point.