]> git.notmuchmail.org Git - notmuch/blob - test/T150-tagging.sh
emacs: Use `cl-lib' instead of deprecated `cl'
[notmuch] / test / T150-tagging.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch tag"'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_message '[subject]=One'
6 add_message '[subject]=Two'
7
8 test_begin_subtest "Adding tags"
9 notmuch tag +tag1 +tag2 +tag3 \*
10 output=$(notmuch search \* | notmuch_search_sanitize)
11 test_expect_equal "$output" "\
12 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 tag2 tag3 unread)
13 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag2 tag3 unread)"
14
15 test_begin_subtest "Removing tags"
16 notmuch tag -tag1 -tag2 \*
17 output=$(notmuch search \* | notmuch_search_sanitize)
18 test_expect_equal "$output" "\
19 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag3 unread)
20 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag3 unread)"
21
22 test_begin_subtest "No tag operations"
23 test_expect_code 1 'notmuch tag One'
24
25 test_begin_subtest "No query"
26 test_expect_code 1 'notmuch tag +tag2'
27
28 test_begin_subtest "Redundant tagging"
29 notmuch tag +tag1 -tag3 One
30 notmuch tag +tag1 -tag3 \*
31 output=$(notmuch search \* | notmuch_search_sanitize)
32 test_expect_equal "$output" "\
33 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 unread)
34 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
35
36 test_begin_subtest "Remove all"
37 notmuch tag --remove-all One
38 notmuch tag --remove-all +tag5 +tag6 +unread Two
39 output=$(notmuch search \* | notmuch_search_sanitize)
40 test_expect_equal "$output" "\
41 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One ()
42 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (tag5 tag6 unread)"
43
44 test_begin_subtest "Remove all with batch"
45 notmuch tag +tag1 One
46 notmuch tag --remove-all --batch <<EOF
47 -- One
48 +tag3 +tag4 +inbox -- Two
49 EOF
50 output=$(notmuch search \* | notmuch_search_sanitize)
51 test_expect_equal "$output" "\
52 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One ()
53 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag3 tag4)"
54
55 test_begin_subtest "Remove all with a no-op"
56 notmuch tag +inbox +tag1 +unread One
57 notmuch tag --remove-all +foo +inbox +tag1 -foo +unread Two
58 output=$(notmuch search \* | notmuch_search_sanitize)
59 test_expect_equal "$output" "\
60 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag1 unread)
61 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
62
63 test_begin_subtest "Special characters in tags"
64 notmuch tag +':" ' \*
65 notmuch tag -':" ' Two
66 output=$(notmuch search \* | notmuch_search_sanitize)
67 test_expect_equal "$output" "\
68 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)
69 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 unread)"
70
71 test_begin_subtest "Tagging order"
72 notmuch tag +tag4 -tag4 One
73 notmuch tag -tag4 +tag4 Two
74 output=$(notmuch search \* | notmuch_search_sanitize)
75 test_expect_equal "$output" "\
76 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)
77 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag4 unread)"
78
79 test_begin_subtest "--batch"
80 notmuch tag --batch <<EOF
81 # %20 is a space in tag
82 -:"%20 -tag1 +tag5 +tag6 -- One
83 +tag1 -tag1 -tag4 +tag4 -- Two
84 -tag6 One
85 +tag5 Two
86 EOF
87 output=$(notmuch search \* | notmuch_search_sanitize)
88 test_expect_equal "$output" "\
89 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (inbox tag5 unread)
90 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag4 tag5 unread)"
91
92 # generate a common input file for the next several tests.
93 cat > batch.in  <<EOF
94 # %40 is an @ in tag
95 +%40 -tag5 +tag6 -- One
96 +tag1 -tag1 -tag4 +tag4 -- Two
97 -tag5 +tag6 Two
98 EOF
99
100 cat > batch.expected <<EOF
101 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (@ inbox tag6 unread)
102 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag4 tag6 unread)
103 EOF
104
105 test_begin_subtest "--input"
106 notmuch dump --format=batch-tag > backup.tags
107 notmuch tag --input=batch.in
108 notmuch search \* | notmuch_search_sanitize > OUTPUT
109 notmuch restore --format=batch-tag < backup.tags
110 test_expect_equal_file batch.expected OUTPUT
111
112 test_begin_subtest "--batch --input"
113 notmuch dump --format=batch-tag > backup.tags
114 notmuch tag --batch --input=batch.in
115 notmuch search \* | notmuch_search_sanitize > OUTPUT
116 notmuch restore --format=batch-tag < backup.tags
117 test_expect_equal_file batch.expected OUTPUT
118
119 test_begin_subtest "--batch --input --remove-all"
120 notmuch dump --format=batch-tag > backup.tags
121 notmuch tag +foo +bar -- One
122 notmuch tag +tag7 -- Two
123 notmuch tag --batch --input=batch.in --remove-all
124 notmuch search \* | notmuch_search_sanitize > OUTPUT
125 notmuch restore --format=batch-tag < backup.tags
126 cat > batch_removeall.expected <<EOF
127 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (@ tag6)
128 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (tag6)
129 EOF
130 test_expect_equal_file batch_removeall.expected OUTPUT
131 rm batch_removeall.expected
132
133 test_begin_subtest "--batch, dependence on previous line"
134 notmuch dump --format=batch-tag > backup.tags
135 notmuch tag --batch<<EOF
136 +trigger -- One
137 +second_tag -- tag:trigger
138 EOF
139 NOTMUCH_DUMP_TAGS tag:second_tag > OUTPUT
140 notmuch restore --format=batch-tag < backup.tags
141 cat <<EOF >EXPECTED
142 +inbox +second_tag +tag5 +trigger +unread -- id:msg-001@notmuch-test-suite
143 EOF
144 test_expect_equal_file EXPECTED OUTPUT
145
146 test_begin_subtest "--batch, blank lines and comments"
147 notmuch dump | sort > EXPECTED
148 notmuch tag --batch <<EOF
149 # this line is a comment; the next has only white space
150          
151
152 # the previous line is empty
153 EOF
154 notmuch dump | sort > OUTPUT
155 test_expect_equal_file EXPECTED OUTPUT
156
157 test_begin_subtest '--batch: checking error messages'
158 notmuch dump --format=batch-tag > BACKUP
159 notmuch tag --batch <<EOF 2>OUTPUT
160 # the next line has a space
161  
162 # this line has no tag operations, but this is permitted in batch format.
163 a
164 +0
165 +a +b
166 # trailing whitespace
167 +a +b 
168 +c +d --
169 # this is a harmless comment, do not yell about it.
170
171 # the previous line was blank; also no yelling please
172 +%zz -- id:whatever
173 # the next non-comment line should report an an empty tag error for
174 # batch tagging, but not for restore
175 + +e -- id:foo
176 +- -- id:foo
177 EOF
178
179 cat <<EOF > EXPECTED
180 Warning: no query string [+0]
181 Warning: no query string [+a +b]
182 Warning: missing query string [+a +b ]
183 Warning: no query string after -- [+c +d --]
184 Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]
185 Warning: empty tag forbidden [+ +e -- id:foo]
186 Warning: tag starting with '-' forbidden [+- -- id:foo]
187 EOF
188
189 notmuch restore --format=batch-tag < BACKUP
190 test_expect_equal_file EXPECTED OUTPUT
191
192 test_begin_subtest '--batch: tags with quotes'
193 notmuch dump --format=batch-tag > BACKUP
194
195 notmuch tag --batch <<EOF
196 +%22%27%22%27%22%22%27%27 -- One
197 -%22%27%22%27%22%22%27%27 -- One
198 +%22%27%22%22%22%27 -- One
199 +%22%27%22%27%22%22%27%27 -- Two
200 EOF
201
202 cat <<EOF > EXPECTED
203 +%22%27%22%22%22%27 +inbox +tag5 +unread -- id:msg-001@notmuch-test-suite
204 +%22%27%22%27%22%22%27%27 +inbox +tag4 +tag5 +unread -- id:msg-002@notmuch-test-suite
205 EOF
206
207 NOTMUCH_DUMP_TAGS > OUTPUT
208 notmuch restore --format=batch-tag < BACKUP
209 test_expect_equal_file EXPECTED OUTPUT
210
211 test_begin_subtest '--batch: tags with punctuation and space'
212 notmuch dump --format=batch-tag > BACKUP
213
214 notmuch tag --batch <<EOF
215 +%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- One
216 -%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- One
217 +%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%20%60%7e -- Two
218 -%21@%23%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%20%60%7e -- Two
219 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- One
220 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e -- Two
221 EOF
222
223 cat <<EOF > EXPECTED
224 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e +inbox +tag4 +tag5 +unread -- id:msg-002@notmuch-test-suite
225 +%21@%23%20%24%25%5e%26%2a%29-_=+%5b%7b%5c%20%7c%3b%3a%27%20%22,.%3c%60%7e +inbox +tag5 +unread -- id:msg-001@notmuch-test-suite
226 EOF
227
228 NOTMUCH_DUMP_TAGS > OUTPUT
229 notmuch restore --format=batch-tag < BACKUP
230 test_expect_equal_file EXPECTED OUTPUT
231
232 test_begin_subtest '--batch: unicode tags'
233 notmuch dump --format=batch-tag > BACKUP
234
235 notmuch tag --batch <<EOF
236 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7 -- One
237 +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d -- One
238 +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27 -- One
239 +R -- One
240 +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6 -- One
241 +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d -- One
242 +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1 -- One
243 +P%c4%98%2f -- One
244 +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d -- One
245 +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b -- One
246 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7  +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d  +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27  +R  +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6  +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d  +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1  +P%c4%98%2f  +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d  +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b -- Two
247 EOF
248
249 cat <<EOF > EXPECTED
250 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7 +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27 +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1 +P%c4%98%2f +R +inbox +tag4 +tag5 +unread +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6 +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d -- id:msg-002@notmuch-test-suite
251 +%2a@%7d%cf%b5%f4%85%80%adO3%da%a7 +=%e0%ac%95%c8%b3+%ef%aa%95%c8%a64w%c7%9d%c9%a2%cf%b3%d6%82%24B%c4%a9%c5%a1UX%ee%99%b0%27E7%ca%a4%d0%8b%5d +A%e1%a0%bc%de%8b%d5%b2V%d9%9b%f3%b5%a2%a3M%d8%a1u@%f0%a0%ac%948%7e%f0%ab%86%af%27 +L%df%85%ef%a1%a5m@%d3%96%c2%ab%d4%9f%ca%b8%f3%b3%a2%bf%c7%b1_u%d7%b4%c7%b1 +P%c4%98%2f +R +inbox +tag5 +unread +%7e%d1%8b%25%ec%a0%ae%d1%a0M%3b%e3%b6%b7%e9%a4%87%3c%db%9a%cc%a8%e1%96%9d +%c4%bf7%c7%ab9H%c4%99k%ea%91%bd%c3%8ck%e2%b3%8dk%c5%952V%e4%99%b2%d9%b3%e4%8b%bda%5b%24%c7%9b +%da%88=f%cc%b9I%ce%af%7b%c9%97%e3%b9%8bH%cb%92X%d2%8c6 +%dc%9crh%d2%86B%e5%97%a2%22t%ed%99%82d -- id:msg-001@notmuch-test-suite
252 EOF
253
254 NOTMUCH_DUMP_TAGS > OUTPUT
255 notmuch restore --format=batch-tag < BACKUP
256 test_expect_equal_file EXPECTED OUTPUT
257
258 test_begin_subtest "--batch: only space and % needs to be encoded."
259 notmuch dump --format=batch-tag > BACKUP
260
261 notmuch tag --batch <<EOF
262 +winner *
263 +foo::bar%25 -- (One and Two) or (One and tag:winner)
264 +found::it -- tag:foo::bar%
265 # ignore this line and the next
266
267 +space%20in%20tags -- Two
268 # add tag '(tags)', among other stunts.
269 +crazy{ +(tags) +&are +#possible\ -- tag:"space in tags"
270 +match*crazy -- tag:crazy{
271 +some_tag -- id:"this is ""nauty)"""
272 EOF
273
274 cat <<EOF > EXPECTED
275 +%23possible%5c +%26are +%28tags%29 +crazy%7b +inbox +match%2acrazy +space%20in%20tags +tag4 +tag5 +unread +winner -- id:msg-002@notmuch-test-suite
276 +foo%3a%3abar%25 +found%3a%3ait +inbox +tag5 +unread +winner -- id:msg-001@notmuch-test-suite
277 EOF
278
279 NOTMUCH_DUMP_TAGS > OUTPUT
280 notmuch restore --format=batch-tag < BACKUP
281 test_expect_equal_file EXPECTED OUTPUT
282
283 test_begin_subtest '--batch: unicode message-ids'
284
285 ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \
286      --num-messages=100
287
288 notmuch dump --format=batch-tag | sed 's/^.* -- /+common_tag -- /' | \
289     sort > EXPECTED
290
291 notmuch dump --format=batch-tag | sed 's/^.* -- /  -- /' > INTERMEDIATE_STEP
292 notmuch restore --format=batch-tag < INTERMEDIATE_STEP
293
294 notmuch tag --batch < EXPECTED
295
296 notmuch dump --format=batch-tag| \
297     sort > OUTPUT
298
299 test_expect_equal_file EXPECTED OUTPUT
300
301 test_begin_subtest "Empty tag names"
302 test_expect_code 1 'notmuch tag + One'
303
304 test_begin_subtest "Tag name beginning with -"
305 test_expect_code 1 'notmuch tag +- One'
306
307 test_begin_subtest "Xapian exception: read only files"
308 chmod u-w  ${MAIL_DIR}/.notmuch/xapian/*.${db_ending}
309 output=$(notmuch tag +something '*' 2>&1 | sed 's/: .*$//' )
310 chmod u+w  ${MAIL_DIR}/.notmuch/xapian/*.${db_ending}
311 test_expect_equal "$output" "A Xapian exception occurred opening database"
312
313 test_done