]> git.notmuchmail.org Git - notmuch/blob - test/T090-search-output.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T090-search-output.sh
1 #!/usr/bin/env bash
2 test_description='various settings for "notmuch search --output="'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_email_corpus
6
7 test_begin_subtest "--output=threads"
8 notmuch search --output=threads '*' | sed -e s/thread:.*/thread:THREADID/ >OUTPUT
9 cat <<EOF >EXPECTED
10 thread:THREADID
11 thread:THREADID
12 thread:THREADID
13 thread:THREADID
14 thread:THREADID
15 thread:THREADID
16 thread:THREADID
17 thread:THREADID
18 thread:THREADID
19 thread:THREADID
20 thread:THREADID
21 thread:THREADID
22 thread:THREADID
23 thread:THREADID
24 thread:THREADID
25 thread:THREADID
26 thread:THREADID
27 thread:THREADID
28 thread:THREADID
29 thread:THREADID
30 thread:THREADID
31 thread:THREADID
32 thread:THREADID
33 thread:THREADID
34 EOF
35 test_expect_equal_file EXPECTED OUTPUT
36
37 test_begin_subtest "--output=threads --format=json"
38 notmuch search --format=json --output=threads '*' | sed -e s/\".*\"/\"THREADID\"/ >OUTPUT
39 cat <<EOF >EXPECTED
40 ["THREADID",
41 "THREADID",
42 "THREADID",
43 "THREADID",
44 "THREADID",
45 "THREADID",
46 "THREADID",
47 "THREADID",
48 "THREADID",
49 "THREADID",
50 "THREADID",
51 "THREADID",
52 "THREADID",
53 "THREADID",
54 "THREADID",
55 "THREADID",
56 "THREADID",
57 "THREADID",
58 "THREADID",
59 "THREADID",
60 "THREADID",
61 "THREADID",
62 "THREADID",
63 "THREADID"]
64 EOF
65 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
66
67 test_begin_subtest "--output=messages"
68 notmuch search --output=messages '*' >OUTPUT
69 cat <<EOF >EXPECTED
70 id:4EFC743A.3060609@april.org
71 id:877h1wv7mg.fsf@inf-8657.int-evry.fr
72 id:1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk
73 id:877htoqdbo.fsf@yoom.home.cworth.org
74 id:878we4qdqf.fsf@yoom.home.cworth.org
75 id:87aaykqe24.fsf@yoom.home.cworth.org
76 id:87bpj0qeng.fsf@yoom.home.cworth.org
77 id:87fx8cqf8v.fsf@yoom.home.cworth.org
78 id:87hbssqfix.fsf@yoom.home.cworth.org
79 id:87iqd8qgiz.fsf@yoom.home.cworth.org
80 id:87k4xoqgnl.fsf@yoom.home.cworth.org
81 id:87ocn0qh6d.fsf@yoom.home.cworth.org
82 id:87pr7gqidx.fsf@yoom.home.cworth.org
83 id:867hto2p0t.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me
84 id:1258532999-9316-1-git-send-email-keithp@keithp.com
85 id:86aayk2rbj.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me
86 id:86d43g2w3y.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me
87 id:ddd65cda0911172214t60d22b63hcfeb5a19ab54a39b@mail.gmail.com
88 id:86einw2xof.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me
89 id:736613.51770.qm@web113505.mail.gq1.yahoo.com
90 id:1258520223-15328-1-git-send-email-jan@ryngle.com
91 id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com
92 id:1258510940-7018-1-git-send-email-stewart@flamingspork.com
93 id:yunzl6kd1w0.fsf@aiko.keithp.com
94 id:yun1vjwegii.fsf@aiko.keithp.com
95 id:yun3a4cegoa.fsf@aiko.keithp.com
96 id:1258509400-32511-1-git-send-email-stewart@flamingspork.com
97 id:1258506353-20352-1-git-send-email-stewart@flamingspork.com
98 id:20091118010116.GC25380@dottiness.seas.harvard.edu
99 id:20091118005829.GB25380@dottiness.seas.harvard.edu
100 id:20091118005040.GA25380@dottiness.seas.harvard.edu
101 id:cf0c4d610911171623q3e27a0adx802e47039b57604b@mail.gmail.com
102 id:1258500222-32066-1-git-send-email-ingmar@exherbo.org
103 id:20091117232137.GA7669@griffis1.net
104 id:20091118002059.067214ed@hikari
105 id:1258498485-sup-142@elly
106 id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com
107 id:f35dbb950911171435ieecd458o853c873e35f4be95@mail.gmail.com
108 id:1258496327-12086-1-git-send-email-jan@ryngle.com
109 id:1258493565-13508-1-git-send-email-keithp@keithp.com
110 id:yunaayketfm.fsf@aiko.keithp.com
111 id:yunbpj0etua.fsf@aiko.keithp.com
112 id:1258491078-29658-1-git-send-email-dottedmag@dottedmag.net
113 id:87fx8can9z.fsf@vertex.dottedmag
114 id:20091117203301.GV3165@dottiness.seas.harvard.edu
115 id:87lji4lx9v.fsf@yoom.home.cworth.org
116 id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com
117 id:87iqd9rn3l.fsf@vertex.dottedmag
118 id:20091117190054.GU3165@dottiness.seas.harvard.edu
119 id:87lji5cbwo.fsf@yoom.home.cworth.org
120 id:1258471718-6781-2-git-send-email-dottedmag@dottedmag.net
121 id:1258471718-6781-1-git-send-email-dottedmag@dottedmag.net
122 EOF
123 test_expect_equal_file EXPECTED OUTPUT
124
125 test_begin_subtest "--output=messages --duplicate=1"
126 notmuch search --output=messages --duplicate=1 '*' >OUTPUT
127 # reuse same EXPECTED as above
128 test_expect_equal_file EXPECTED OUTPUT
129
130 test_begin_subtest "--output=messages --duplicate=2"
131 notmuch search --output=messages --duplicate=2 '*' >OUTPUT
132 cat <<EOF >EXPECTED
133 id:20091117232137.GA7669@griffis1.net
134 EOF
135 test_expect_equal_file EXPECTED OUTPUT
136
137 test_begin_subtest "--output=messages --duplicate=3"
138 notmuch search --output=messages --duplicate=3 '*' >OUTPUT
139 cat <<EOF >EXPECTED
140 EOF
141 test_expect_equal_file EXPECTED OUTPUT
142
143 test_begin_subtest "--output=messages --format=json"
144 notmuch search --format=json --output=messages '*' >OUTPUT
145 cat <<EOF >EXPECTED
146 ["4EFC743A.3060609@april.org",
147 "877h1wv7mg.fsf@inf-8657.int-evry.fr",
148 "1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk",
149 "877htoqdbo.fsf@yoom.home.cworth.org",
150 "878we4qdqf.fsf@yoom.home.cworth.org",
151 "87aaykqe24.fsf@yoom.home.cworth.org",
152 "87bpj0qeng.fsf@yoom.home.cworth.org",
153 "87fx8cqf8v.fsf@yoom.home.cworth.org",
154 "87hbssqfix.fsf@yoom.home.cworth.org",
155 "87iqd8qgiz.fsf@yoom.home.cworth.org",
156 "87k4xoqgnl.fsf@yoom.home.cworth.org",
157 "87ocn0qh6d.fsf@yoom.home.cworth.org",
158 "87pr7gqidx.fsf@yoom.home.cworth.org",
159 "867hto2p0t.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me",
160 "1258532999-9316-1-git-send-email-keithp@keithp.com",
161 "86aayk2rbj.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me",
162 "86d43g2w3y.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me",
163 "ddd65cda0911172214t60d22b63hcfeb5a19ab54a39b@mail.gmail.com",
164 "86einw2xof.fsf@fortitudo.i-did-not-set--mail-host-address--so-tickle-me",
165 "736613.51770.qm@web113505.mail.gq1.yahoo.com",
166 "1258520223-15328-1-git-send-email-jan@ryngle.com",
167 "ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com",
168 "1258510940-7018-1-git-send-email-stewart@flamingspork.com",
169 "yunzl6kd1w0.fsf@aiko.keithp.com",
170 "yun1vjwegii.fsf@aiko.keithp.com",
171 "yun3a4cegoa.fsf@aiko.keithp.com",
172 "1258509400-32511-1-git-send-email-stewart@flamingspork.com",
173 "1258506353-20352-1-git-send-email-stewart@flamingspork.com",
174 "20091118010116.GC25380@dottiness.seas.harvard.edu",
175 "20091118005829.GB25380@dottiness.seas.harvard.edu",
176 "20091118005040.GA25380@dottiness.seas.harvard.edu",
177 "cf0c4d610911171623q3e27a0adx802e47039b57604b@mail.gmail.com",
178 "1258500222-32066-1-git-send-email-ingmar@exherbo.org",
179 "20091117232137.GA7669@griffis1.net",
180 "20091118002059.067214ed@hikari",
181 "1258498485-sup-142@elly",
182 "f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com",
183 "f35dbb950911171435ieecd458o853c873e35f4be95@mail.gmail.com",
184 "1258496327-12086-1-git-send-email-jan@ryngle.com",
185 "1258493565-13508-1-git-send-email-keithp@keithp.com",
186 "yunaayketfm.fsf@aiko.keithp.com",
187 "yunbpj0etua.fsf@aiko.keithp.com",
188 "1258491078-29658-1-git-send-email-dottedmag@dottedmag.net",
189 "87fx8can9z.fsf@vertex.dottedmag",
190 "20091117203301.GV3165@dottiness.seas.harvard.edu",
191 "87lji4lx9v.fsf@yoom.home.cworth.org",
192 "cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com",
193 "87iqd9rn3l.fsf@vertex.dottedmag",
194 "20091117190054.GU3165@dottiness.seas.harvard.edu",
195 "87lji5cbwo.fsf@yoom.home.cworth.org",
196 "1258471718-6781-2-git-send-email-dottedmag@dottedmag.net",
197 "1258471718-6781-1-git-send-email-dottedmag@dottedmag.net"]
198 EOF
199 test_expect_equal_file EXPECTED OUTPUT
200
201 test_begin_subtest "--output=messages --format=json --duplicate=1"
202 notmuch search --output=messages --format=json --duplicate=1 '*' >OUTPUT
203 # reuse same EXPECTED as above
204 test_expect_equal_file EXPECTED OUTPUT
205
206 test_begin_subtest "--output=messages --format=json --duplicate=2"
207 notmuch search --output=messages --format=json --duplicate=2 '*' >OUTPUT
208 cat <<EOF >EXPECTED
209 ["20091117232137.GA7669@griffis1.net"]
210 EOF
211 test_expect_equal_file EXPECTED OUTPUT
212
213 test_begin_subtest "--output=messages --format=json --duplicate=3"
214 notmuch search --output=messages --format=json --duplicate=3 '*' >OUTPUT
215 cat <<EOF >EXPECTED
216 []
217 EOF
218 test_expect_equal_file EXPECTED OUTPUT
219
220 test_begin_subtest "--output=files"
221 notmuch search --output=files '*' | notmuch_search_files_sanitize | sort >OUTPUT
222 cat <<EOF >EXPECTED
223 MAIL_DIR/01:2,
224 MAIL_DIR/02:2,
225 MAIL_DIR/bar/17:2,
226 MAIL_DIR/bar/18:2,
227 MAIL_DIR/bar/baz/05:2,
228 MAIL_DIR/bar/baz/23:2,
229 MAIL_DIR/bar/baz/24:2,
230 MAIL_DIR/bar/baz/cur/25:2,
231 MAIL_DIR/bar/baz/cur/26:2,
232 MAIL_DIR/bar/baz/new/27:2,
233 MAIL_DIR/bar/baz/new/28:2,
234 MAIL_DIR/bar/cur/19:2,
235 MAIL_DIR/bar/cur/20:2,
236 MAIL_DIR/bar/new/21:2,
237 MAIL_DIR/bar/new/22:2,
238 MAIL_DIR/cur/29:2,
239 MAIL_DIR/cur/30:2,
240 MAIL_DIR/cur/31:2,
241 MAIL_DIR/cur/32:2,
242 MAIL_DIR/cur/33:2,
243 MAIL_DIR/cur/34:2,
244 MAIL_DIR/cur/35:2,
245 MAIL_DIR/cur/36:2,
246 MAIL_DIR/cur/37:2,
247 MAIL_DIR/cur/38:2,
248 MAIL_DIR/cur/39:2,
249 MAIL_DIR/cur/40:2,
250 MAIL_DIR/cur/41:2,
251 MAIL_DIR/cur/42:2,
252 MAIL_DIR/cur/43:2,
253 MAIL_DIR/cur/44:2,
254 MAIL_DIR/cur/45:2,
255 MAIL_DIR/cur/46:2,
256 MAIL_DIR/cur/47:2,
257 MAIL_DIR/cur/48:2,
258 MAIL_DIR/cur/49:2,
259 MAIL_DIR/cur/50:2,
260 MAIL_DIR/cur/51:2,
261 MAIL_DIR/cur/52:2,
262 MAIL_DIR/cur/53:2,
263 MAIL_DIR/foo/06:2,
264 MAIL_DIR/foo/baz/11:2,
265 MAIL_DIR/foo/baz/12:2,
266 MAIL_DIR/foo/baz/cur/13:2,
267 MAIL_DIR/foo/baz/cur/14:2,
268 MAIL_DIR/foo/baz/new/15:2,
269 MAIL_DIR/foo/baz/new/16:2,
270 MAIL_DIR/foo/cur/07:2,
271 MAIL_DIR/foo/cur/08:2,
272 MAIL_DIR/foo/new/03:2,
273 MAIL_DIR/foo/new/09:2,
274 MAIL_DIR/foo/new/10:2,
275 MAIL_DIR/new/04:2,
276 EOF
277 test_expect_equal_file EXPECTED OUTPUT
278
279 dup1=$(notmuch search --output=files id:20091117232137.GA7669@griffis1.net | head -n 1 | sed -e "s,$MAIL_DIR,MAIL_DIR,")
280 dup2=$(notmuch search --output=files id:20091117232137.GA7669@griffis1.net | tail -n 1 | sed -e "s,$MAIL_DIR,MAIL_DIR,")
281
282 test_begin_subtest "--output=files --duplicate=1"
283 notmuch search --output=files --duplicate=1 '*' | notmuch_search_files_sanitize | sort >OUTPUT
284 cat <<EOF | sort >EXPECTED
285 $dup1
286 MAIL_DIR/cur/52:2,
287 MAIL_DIR/cur/53:2,
288 MAIL_DIR/cur/50:2,
289 MAIL_DIR/cur/49:2,
290 MAIL_DIR/cur/48:2,
291 MAIL_DIR/cur/47:2,
292 MAIL_DIR/cur/46:2,
293 MAIL_DIR/cur/45:2,
294 MAIL_DIR/cur/44:2,
295 MAIL_DIR/cur/43:2,
296 MAIL_DIR/cur/42:2,
297 MAIL_DIR/cur/41:2,
298 MAIL_DIR/cur/40:2,
299 MAIL_DIR/cur/39:2,
300 MAIL_DIR/cur/38:2,
301 MAIL_DIR/cur/37:2,
302 MAIL_DIR/cur/36:2,
303 MAIL_DIR/cur/35:2,
304 MAIL_DIR/cur/34:2,
305 MAIL_DIR/cur/33:2,
306 MAIL_DIR/cur/32:2,
307 MAIL_DIR/cur/31:2,
308 MAIL_DIR/cur/30:2,
309 MAIL_DIR/cur/29:2,
310 MAIL_DIR/bar/baz/new/28:2,
311 MAIL_DIR/bar/baz/new/27:2,
312 MAIL_DIR/bar/baz/cur/26:2,
313 MAIL_DIR/bar/baz/cur/25:2,
314 MAIL_DIR/bar/baz/24:2,
315 MAIL_DIR/bar/baz/23:2,
316 MAIL_DIR/bar/new/22:2,
317 MAIL_DIR/bar/new/21:2,
318 MAIL_DIR/bar/cur/19:2,
319 MAIL_DIR/bar/cur/20:2,
320 MAIL_DIR/bar/17:2,
321 MAIL_DIR/foo/baz/new/16:2,
322 MAIL_DIR/foo/baz/new/15:2,
323 MAIL_DIR/foo/baz/cur/14:2,
324 MAIL_DIR/foo/baz/cur/13:2,
325 MAIL_DIR/foo/baz/12:2,
326 MAIL_DIR/foo/baz/11:2,
327 MAIL_DIR/foo/new/10:2,
328 MAIL_DIR/foo/new/09:2,
329 MAIL_DIR/foo/cur/08:2,
330 MAIL_DIR/foo/06:2,
331 MAIL_DIR/bar/baz/05:2,
332 MAIL_DIR/new/04:2,
333 MAIL_DIR/foo/new/03:2,
334 MAIL_DIR/foo/cur/07:2,
335 MAIL_DIR/02:2,
336 MAIL_DIR/01:2,
337 EOF
338 test_expect_equal_file EXPECTED OUTPUT
339
340 test_begin_subtest "--output=files --format=json"
341 notmuch search --format=json --output=files '*' | notmuch_search_files_sanitize \
342     | test_sort_json >OUTPUT
343 cat <<EOF | test_sort_json >EXPECTED
344 ["MAIL_DIR/cur/52:2,",
345 "MAIL_DIR/cur/53:2,",
346 "MAIL_DIR/cur/50:2,",
347 "MAIL_DIR/cur/49:2,",
348 "MAIL_DIR/cur/48:2,",
349 "MAIL_DIR/cur/47:2,",
350 "MAIL_DIR/cur/46:2,",
351 "MAIL_DIR/cur/45:2,",
352 "MAIL_DIR/cur/44:2,",
353 "MAIL_DIR/cur/43:2,",
354 "MAIL_DIR/cur/42:2,",
355 "MAIL_DIR/cur/41:2,",
356 "MAIL_DIR/cur/40:2,",
357 "MAIL_DIR/cur/39:2,",
358 "MAIL_DIR/cur/38:2,",
359 "MAIL_DIR/cur/37:2,",
360 "MAIL_DIR/cur/36:2,",
361 "MAIL_DIR/cur/35:2,",
362 "MAIL_DIR/cur/34:2,",
363 "MAIL_DIR/cur/33:2,",
364 "MAIL_DIR/cur/32:2,",
365 "MAIL_DIR/cur/31:2,",
366 "MAIL_DIR/cur/30:2,",
367 "MAIL_DIR/cur/29:2,",
368 "MAIL_DIR/bar/baz/new/28:2,",
369 "MAIL_DIR/bar/baz/new/27:2,",
370 "MAIL_DIR/bar/baz/cur/26:2,",
371 "MAIL_DIR/bar/baz/cur/25:2,",
372 "MAIL_DIR/bar/baz/24:2,",
373 "MAIL_DIR/bar/baz/23:2,",
374 "MAIL_DIR/bar/new/22:2,",
375 "MAIL_DIR/bar/new/21:2,",
376 "MAIL_DIR/bar/cur/19:2,",
377 "MAIL_DIR/bar/18:2,",
378 "MAIL_DIR/cur/51:2,",
379 "MAIL_DIR/bar/cur/20:2,",
380 "MAIL_DIR/bar/17:2,",
381 "MAIL_DIR/foo/baz/new/16:2,",
382 "MAIL_DIR/foo/baz/new/15:2,",
383 "MAIL_DIR/foo/baz/cur/14:2,",
384 "MAIL_DIR/foo/baz/cur/13:2,",
385 "MAIL_DIR/foo/baz/12:2,",
386 "MAIL_DIR/foo/baz/11:2,",
387 "MAIL_DIR/foo/new/10:2,",
388 "MAIL_DIR/foo/new/09:2,",
389 "MAIL_DIR/foo/cur/08:2,",
390 "MAIL_DIR/foo/06:2,",
391 "MAIL_DIR/bar/baz/05:2,",
392 "MAIL_DIR/new/04:2,",
393 "MAIL_DIR/foo/new/03:2,",
394 "MAIL_DIR/foo/cur/07:2,",
395 "MAIL_DIR/02:2,",
396 "MAIL_DIR/01:2,"]
397 EOF
398 test_expect_equal_file EXPECTED OUTPUT
399
400 test_begin_subtest "--output=files --format=json --duplicate=2"
401 notmuch search --format=json --output=files --duplicate=2 '*' | notmuch_search_files_sanitize >OUTPUT
402 cat <<EOF >EXPECTED
403 ["$dup2"]
404 EOF
405 test_expect_equal_file EXPECTED OUTPUT
406
407 test_begin_subtest "--output=tags"
408 notmuch search --output=tags '*' >OUTPUT
409 cat <<EOF >EXPECTED
410 attachment
411 inbox
412 signed
413 unread
414 EOF
415 test_expect_equal_file EXPECTED OUTPUT
416
417 test_begin_subtest "--output=tags --format=json"
418 notmuch search --format=json --output=tags '*' >OUTPUT
419 cat <<EOF >EXPECTED
420 ["attachment",
421 "inbox",
422 "signed",
423 "unread"]
424 EOF
425 test_expect_equal_file EXPECTED OUTPUT
426
427 test_begin_subtest "sanitize output for quoted-printable line-breaks in author and subject"
428 add_message "[subject]='two =?ISO-8859-1?Q?line=0A_subject?=
429         headers'"
430 notmuch search id:"$gen_msg_id" | notmuch_search_sanitize >OUTPUT
431 cat <<EOF >EXPECTED
432 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; two line  subject headers (inbox unread)
433 EOF
434 test_expect_equal_file EXPECTED OUTPUT
435
436 test_begin_subtest "search for non-existent message prints nothing"
437 notmuch search "no-message-matches-this" > OUTPUT
438 : >EXPECTED
439 test_expect_equal_file EXPECTED OUTPUT
440
441 test_begin_subtest "search --format=json for non-existent message prints proper empty json"
442 notmuch search --format=json "no-message-matches-this" > OUTPUT
443 echo "[]" >EXPECTED
444 test_expect_equal_file EXPECTED OUTPUT
445
446 test_done