]> git.cworth.org Git - notmuch-old/blob - test/T095-address.sh
lib/sexp: add parameter expansion for regex and wildcard
[notmuch-old] / test / T095-address.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch address" in several variants'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_email_corpus
6
7 test_begin_subtest "--output=sender"
8 notmuch address --output=sender '*' >OUTPUT
9 cat <<EOF >EXPECTED
10 François Boulogne <boulogne.f@gmail.com>
11 Olivier Berger <olivier.berger@it-sudparis.eu>
12 Chris Wilson <chris@chris-wilson.co.uk>
13 Carl Worth <cworth@cworth.org>
14 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
15 Keith Packard <keithp@keithp.com>
16 Jjgod Jiang <gzjjgod@gmail.com>
17 Rolland Santimano <rollandsantimano@yahoo.com>
18 Jan Janak <jan@ryngle.com>
19 Stewart Smith <stewart@flamingspork.com>
20 Lars Kellogg-Stedman <lars@seas.harvard.edu>
21 Alex Botero-Lowry <alex.boterolowry@gmail.com>
22 Ingmar Vanhassel <ingmar@exherbo.org>
23 Aron Griffis <agriffis@n01se.net>
24 Adrian Perez de Castro <aperez@igalia.com>
25 Israel Herraiz <isra@herraiz.org>
26 Mikhail Gusarov <dottedmag@dottedmag.net>
27 EOF
28 test_expect_equal_file EXPECTED OUTPUT
29
30 test_begin_subtest "without --output"
31 notmuch address '*' >OUTPUT
32 # Use EXPECTED from previous subtest
33 test_expect_equal_file EXPECTED OUTPUT
34
35 test_begin_subtest "--output=sender --format=json"
36 notmuch address --output=sender --format=json '*' >OUTPUT
37 cat <<EOF >EXPECTED
38 [{"name": "François Boulogne", "address": "boulogne.f@gmail.com", "name-addr": "François Boulogne <boulogne.f@gmail.com>"},
39 {"name": "Olivier Berger", "address": "olivier.berger@it-sudparis.eu", "name-addr": "Olivier Berger <olivier.berger@it-sudparis.eu>"},
40 {"name": "Chris Wilson", "address": "chris@chris-wilson.co.uk", "name-addr": "Chris Wilson <chris@chris-wilson.co.uk>"},
41 {"name": "Carl Worth", "address": "cworth@cworth.org", "name-addr": "Carl Worth <cworth@cworth.org>"},
42 {"name": "Alexander Botero-Lowry", "address": "alex.boterolowry@gmail.com", "name-addr": "Alexander Botero-Lowry <alex.boterolowry@gmail.com>"},
43 {"name": "Keith Packard", "address": "keithp@keithp.com", "name-addr": "Keith Packard <keithp@keithp.com>"},
44 {"name": "Jjgod Jiang", "address": "gzjjgod@gmail.com", "name-addr": "Jjgod Jiang <gzjjgod@gmail.com>"},
45 {"name": "Rolland Santimano", "address": "rollandsantimano@yahoo.com", "name-addr": "Rolland Santimano <rollandsantimano@yahoo.com>"},
46 {"name": "Jan Janak", "address": "jan@ryngle.com", "name-addr": "Jan Janak <jan@ryngle.com>"},
47 {"name": "Stewart Smith", "address": "stewart@flamingspork.com", "name-addr": "Stewart Smith <stewart@flamingspork.com>"},
48 {"name": "Lars Kellogg-Stedman", "address": "lars@seas.harvard.edu", "name-addr": "Lars Kellogg-Stedman <lars@seas.harvard.edu>"},
49 {"name": "Alex Botero-Lowry", "address": "alex.boterolowry@gmail.com", "name-addr": "Alex Botero-Lowry <alex.boterolowry@gmail.com>"},
50 {"name": "Ingmar Vanhassel", "address": "ingmar@exherbo.org", "name-addr": "Ingmar Vanhassel <ingmar@exherbo.org>"},
51 {"name": "Aron Griffis", "address": "agriffis@n01se.net", "name-addr": "Aron Griffis <agriffis@n01se.net>"},
52 {"name": "Adrian Perez de Castro", "address": "aperez@igalia.com", "name-addr": "Adrian Perez de Castro <aperez@igalia.com>"},
53 {"name": "Israel Herraiz", "address": "isra@herraiz.org", "name-addr": "Israel Herraiz <isra@herraiz.org>"},
54 {"name": "Mikhail Gusarov", "address": "dottedmag@dottedmag.net", "name-addr": "Mikhail Gusarov <dottedmag@dottedmag.net>"}]
55 EOF
56 test_expect_equal_file EXPECTED OUTPUT
57
58 test_begin_subtest "--output=recipients"
59 notmuch address --output=recipients '*' >OUTPUT
60 cat <<EOF >EXPECTED
61 Allan McRae <allan@archlinux.org>
62 "Discussion about the Arch User Repository (AUR)" <aur-general@archlinux.org>
63 olivier.berger@it-sudparis.eu
64 notmuch@notmuchmail.org
65 notmuch <notmuch@notmuchmail.org>
66 Keith Packard <keithp@keithp.com>
67 Mikhail Gusarov <dottedmag@dottedmag.net>
68 EOF
69 test_expect_equal_file EXPECTED OUTPUT
70
71 test_begin_subtest "--output=sender --output=recipients"
72 notmuch address --output=sender --output=recipients '*' >OUTPUT
73 cat <<EOF >EXPECTED
74 François Boulogne <boulogne.f@gmail.com>
75 Allan McRae <allan@archlinux.org>
76 "Discussion about the Arch User Repository (AUR)" <aur-general@archlinux.org>
77 Olivier Berger <olivier.berger@it-sudparis.eu>
78 olivier.berger@it-sudparis.eu
79 Chris Wilson <chris@chris-wilson.co.uk>
80 notmuch@notmuchmail.org
81 Carl Worth <cworth@cworth.org>
82 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
83 Keith Packard <keithp@keithp.com>
84 Jjgod Jiang <gzjjgod@gmail.com>
85 Rolland Santimano <rollandsantimano@yahoo.com>
86 Jan Janak <jan@ryngle.com>
87 Stewart Smith <stewart@flamingspork.com>
88 Lars Kellogg-Stedman <lars@seas.harvard.edu>
89 notmuch <notmuch@notmuchmail.org>
90 Alex Botero-Lowry <alex.boterolowry@gmail.com>
91 Ingmar Vanhassel <ingmar@exherbo.org>
92 Aron Griffis <agriffis@n01se.net>
93 Adrian Perez de Castro <aperez@igalia.com>
94 Israel Herraiz <isra@herraiz.org>
95 Mikhail Gusarov <dottedmag@dottedmag.net>
96 EOF
97 test_expect_equal_file EXPECTED OUTPUT
98
99 test_begin_subtest "--output=sender --output=count"
100 notmuch address --output=sender --output=count '*' | sort -n >OUTPUT
101 cat <<EOF >EXPECTED
102 1       Adrian Perez de Castro <aperez@igalia.com>
103 1       Aron Griffis <agriffis@n01se.net>
104 1       Chris Wilson <chris@chris-wilson.co.uk>
105 1       François Boulogne <boulogne.f@gmail.com>
106 1       Ingmar Vanhassel <ingmar@exherbo.org>
107 1       Israel Herraiz <isra@herraiz.org>
108 1       Olivier Berger <olivier.berger@it-sudparis.eu>
109 1       Rolland Santimano <rollandsantimano@yahoo.com>
110 2       Alex Botero-Lowry <alex.boterolowry@gmail.com>
111 2       Jjgod Jiang <gzjjgod@gmail.com>
112 3       Stewart Smith <stewart@flamingspork.com>
113 4       Alexander Botero-Lowry <alex.boterolowry@gmail.com>
114 4       Jan Janak <jan@ryngle.com>
115 5       Lars Kellogg-Stedman <lars@seas.harvard.edu>
116 5       Mikhail Gusarov <dottedmag@dottedmag.net>
117 7       Keith Packard <keithp@keithp.com>
118 12      Carl Worth <cworth@cworth.org>
119 EOF
120 test_expect_equal_file EXPECTED OUTPUT
121
122 test_begin_subtest "--output=recipients --output=address"
123 notmuch address --output=recipients --output=address '*' >OUTPUT
124 cat <<EOF >EXPECTED
125 allan@archlinux.org
126 aur-general@archlinux.org
127 olivier.berger@it-sudparis.eu
128 notmuch@notmuchmail.org
129 notmuch@notmuchmail.org
130 keithp@keithp.com
131 dottedmag@dottedmag.net
132 EOF
133 test_expect_equal_file EXPECTED OUTPUT
134
135 test_begin_subtest "--output=sender --output=address --output=count"
136 notmuch address --output=sender --output=address --output=count '*' | sort -n >OUTPUT
137 cat <<EOF >EXPECTED
138 1       agriffis@n01se.net
139 1       aperez@igalia.com
140 1       boulogne.f@gmail.com
141 1       chris@chris-wilson.co.uk
142 1       ingmar@exherbo.org
143 1       isra@herraiz.org
144 1       olivier.berger@it-sudparis.eu
145 1       rollandsantimano@yahoo.com
146 2       alex.boterolowry@gmail.com
147 2       gzjjgod@gmail.com
148 3       stewart@flamingspork.com
149 4       alex.boterolowry@gmail.com
150 4       jan@ryngle.com
151 5       dottedmag@dottedmag.net
152 5       lars@seas.harvard.edu
153 7       keithp@keithp.com
154 12      cworth@cworth.org
155 EOF
156 test_expect_equal_file EXPECTED OUTPUT
157
158 test_begin_subtest "--output=count --format=json"
159 # Since the iteration order of GHashTable is not specified, we
160 # preprocess and sort the results to keep the order stable here.
161 notmuch address --output=count --format=json '*' | \
162     sed -e 's/^\[//' -e 's/]$//' -e 's/,$//' | sort >OUTPUT
163 cat <<EOF >EXPECTED
164 {"name": "Adrian Perez de Castro", "address": "aperez@igalia.com", "name-addr": "Adrian Perez de Castro <aperez@igalia.com>", "count": 1}
165 {"name": "Alex Botero-Lowry", "address": "alex.boterolowry@gmail.com", "name-addr": "Alex Botero-Lowry <alex.boterolowry@gmail.com>", "count": 2}
166 {"name": "Alexander Botero-Lowry", "address": "alex.boterolowry@gmail.com", "name-addr": "Alexander Botero-Lowry <alex.boterolowry@gmail.com>", "count": 4}
167 {"name": "Aron Griffis", "address": "agriffis@n01se.net", "name-addr": "Aron Griffis <agriffis@n01se.net>", "count": 1}
168 {"name": "Carl Worth", "address": "cworth@cworth.org", "name-addr": "Carl Worth <cworth@cworth.org>", "count": 12}
169 {"name": "Chris Wilson", "address": "chris@chris-wilson.co.uk", "name-addr": "Chris Wilson <chris@chris-wilson.co.uk>", "count": 1}
170 {"name": "François Boulogne", "address": "boulogne.f@gmail.com", "name-addr": "François Boulogne <boulogne.f@gmail.com>", "count": 1}
171 {"name": "Ingmar Vanhassel", "address": "ingmar@exherbo.org", "name-addr": "Ingmar Vanhassel <ingmar@exherbo.org>", "count": 1}
172 {"name": "Israel Herraiz", "address": "isra@herraiz.org", "name-addr": "Israel Herraiz <isra@herraiz.org>", "count": 1}
173 {"name": "Jan Janak", "address": "jan@ryngle.com", "name-addr": "Jan Janak <jan@ryngle.com>", "count": 4}
174 {"name": "Jjgod Jiang", "address": "gzjjgod@gmail.com", "name-addr": "Jjgod Jiang <gzjjgod@gmail.com>", "count": 2}
175 {"name": "Keith Packard", "address": "keithp@keithp.com", "name-addr": "Keith Packard <keithp@keithp.com>", "count": 7}
176 {"name": "Lars Kellogg-Stedman", "address": "lars@seas.harvard.edu", "name-addr": "Lars Kellogg-Stedman <lars@seas.harvard.edu>", "count": 5}
177 {"name": "Mikhail Gusarov", "address": "dottedmag@dottedmag.net", "name-addr": "Mikhail Gusarov <dottedmag@dottedmag.net>", "count": 5}
178 {"name": "Olivier Berger", "address": "olivier.berger@it-sudparis.eu", "name-addr": "Olivier Berger <olivier.berger@it-sudparis.eu>", "count": 1}
179 {"name": "Rolland Santimano", "address": "rollandsantimano@yahoo.com", "name-addr": "Rolland Santimano <rollandsantimano@yahoo.com>", "count": 1}
180 {"name": "Stewart Smith", "address": "stewart@flamingspork.com", "name-addr": "Stewart Smith <stewart@flamingspork.com>", "count": 3}
181 EOF
182 test_expect_equal_file EXPECTED OUTPUT
183
184 test_begin_subtest "--deduplicate=no --sort=oldest-first --output=sender"
185 notmuch address --deduplicate=no --sort=oldest-first --output=sender '*' >OUTPUT
186 cat <<EOF >EXPECTED
187 Mikhail Gusarov <dottedmag@dottedmag.net>
188 Mikhail Gusarov <dottedmag@dottedmag.net>
189 Carl Worth <cworth@cworth.org>
190 Lars Kellogg-Stedman <lars@seas.harvard.edu>
191 Mikhail Gusarov <dottedmag@dottedmag.net>
192 Alex Botero-Lowry <alex.boterolowry@gmail.com>
193 Carl Worth <cworth@cworth.org>
194 Lars Kellogg-Stedman <lars@seas.harvard.edu>
195 Mikhail Gusarov <dottedmag@dottedmag.net>
196 Mikhail Gusarov <dottedmag@dottedmag.net>
197 Keith Packard <keithp@keithp.com>
198 Keith Packard <keithp@keithp.com>
199 Keith Packard <keithp@keithp.com>
200 Jan Janak <jan@ryngle.com>
201 Jan Janak <jan@ryngle.com>
202 Jan Janak <jan@ryngle.com>
203 Israel Herraiz <isra@herraiz.org>
204 Adrian Perez de Castro <aperez@igalia.com>
205 Aron Griffis <agriffis@n01se.net>
206 Ingmar Vanhassel <ingmar@exherbo.org>
207 Alex Botero-Lowry <alex.boterolowry@gmail.com>
208 Lars Kellogg-Stedman <lars@seas.harvard.edu>
209 Lars Kellogg-Stedman <lars@seas.harvard.edu>
210 Lars Kellogg-Stedman <lars@seas.harvard.edu>
211 Stewart Smith <stewart@flamingspork.com>
212 Stewart Smith <stewart@flamingspork.com>
213 Keith Packard <keithp@keithp.com>
214 Keith Packard <keithp@keithp.com>
215 Keith Packard <keithp@keithp.com>
216 Stewart Smith <stewart@flamingspork.com>
217 Jjgod Jiang <gzjjgod@gmail.com>
218 Jan Janak <jan@ryngle.com>
219 Rolland Santimano <rollandsantimano@yahoo.com>
220 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
221 Jjgod Jiang <gzjjgod@gmail.com>
222 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
223 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
224 Keith Packard <keithp@keithp.com>
225 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
226 Carl Worth <cworth@cworth.org>
227 Carl Worth <cworth@cworth.org>
228 Carl Worth <cworth@cworth.org>
229 Carl Worth <cworth@cworth.org>
230 Carl Worth <cworth@cworth.org>
231 Carl Worth <cworth@cworth.org>
232 Carl Worth <cworth@cworth.org>
233 Carl Worth <cworth@cworth.org>
234 Carl Worth <cworth@cworth.org>
235 Carl Worth <cworth@cworth.org>
236 Chris Wilson <chris@chris-wilson.co.uk>
237 Olivier Berger <olivier.berger@it-sudparis.eu>
238 François Boulogne <boulogne.f@gmail.com>
239 EOF
240 test_expect_equal_file EXPECTED OUTPUT
241
242 test_begin_subtest "--deduplicate=no --sort=newest-first --output=sender --output=recipients"
243 notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo/new >OUTPUT
244 cat <<EOF >EXPECTED
245 Mikhail Gusarov <dottedmag@dottedmag.net>
246 notmuch@notmuchmail.org
247 Mikhail Gusarov <dottedmag@dottedmag.net>
248 notmuch@notmuchmail.org
249 Lars Kellogg-Stedman <lars@seas.harvard.edu>
250 notmuch@notmuchmail.org
251 EOF
252 test_expect_equal_file EXPECTED OUTPUT
253
254 test_begin_subtest "--deduplicate=address --output=sender --output=recipients"
255 notmuch address --deduplicate=address --output=sender --output=recipients '*' | sort >OUTPUT
256 cat <<EOF >EXPECTED
257 "Discussion about the Arch User Repository (AUR)" <aur-general@archlinux.org>
258 Adrian Perez de Castro <aperez@igalia.com>
259 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
260 Allan McRae <allan@archlinux.org>
261 Aron Griffis <agriffis@n01se.net>
262 Carl Worth <cworth@cworth.org>
263 Chris Wilson <chris@chris-wilson.co.uk>
264 François Boulogne <boulogne.f@gmail.com>
265 Ingmar Vanhassel <ingmar@exherbo.org>
266 Israel Herraiz <isra@herraiz.org>
267 Jan Janak <jan@ryngle.com>
268 Jjgod Jiang <gzjjgod@gmail.com>
269 Keith Packard <keithp@keithp.com>
270 Lars Kellogg-Stedman <lars@seas.harvard.edu>
271 Mikhail Gusarov <dottedmag@dottedmag.net>
272 Olivier Berger <olivier.berger@it-sudparis.eu>
273 Rolland Santimano <rollandsantimano@yahoo.com>
274 Stewart Smith <stewart@flamingspork.com>
275 notmuch@notmuchmail.org
276 EOF
277 test_expect_equal_file EXPECTED OUTPUT
278
279 generate_message '[from]="Foo Bar <foo.bar@example.com>"'
280 generate_message '[from]="Foo Bar <Foo.Bar@Example.Com>"'
281 generate_message '[from]="Foo Bar <foo.bar@example.com>"'
282 generate_message '[from]="Bar <Foo.Bar@Example.Com>"'
283 generate_message '[from]="Foo <foo.bar@example.com>"'
284 generate_message '[from]="<foo.bar@example.com>"'
285 generate_message '[from]="foo.bar@example.com"'
286 generate_message '[from]="Baz <foo.bar+baz@example.com>"'
287 generate_message '[from]="Foo Bar <foo.bar+baz@example.com>"'
288 generate_message '[from]="Baz <foo.bar+baz@example.com>"'
289 notmuch new > /dev/null
290
291 test_begin_subtest "--deduplicate=no --output=sender"
292 notmuch address --deduplicate=no --output=sender from:example.com | sort >OUTPUT
293 cat <<EOF >EXPECTED
294 Bar <Foo.Bar@Example.Com>
295 Baz <foo.bar+baz@example.com>
296 Baz <foo.bar+baz@example.com>
297 Foo <foo.bar@example.com>
298 Foo Bar <Foo.Bar@Example.Com>
299 Foo Bar <foo.bar+baz@example.com>
300 Foo Bar <foo.bar@example.com>
301 Foo Bar <foo.bar@example.com>
302 foo.bar@example.com
303 foo.bar@example.com
304 EOF
305 test_expect_equal_file EXPECTED OUTPUT
306
307 test_begin_subtest "--deduplicate=mailbox --output=sender --output=count"
308 notmuch address --deduplicate=mailbox --output=sender --output=count from:example.com | sort -n >OUTPUT
309 cat <<EOF >EXPECTED
310 1       Bar <Foo.Bar@Example.Com>
311 1       Foo <foo.bar@example.com>
312 1       Foo Bar <Foo.Bar@Example.Com>
313 1       Foo Bar <foo.bar+baz@example.com>
314 2       Baz <foo.bar+baz@example.com>
315 2       Foo Bar <foo.bar@example.com>
316 2       foo.bar@example.com
317 EOF
318 test_expect_equal_file EXPECTED OUTPUT
319
320 test_begin_subtest "--deduplicate=address --output=sender --output=count"
321 notmuch address --deduplicate=address --output=sender --output=count from:example.com | sort -n >OUTPUT
322 cat <<EOF >EXPECTED
323 3       Baz <foo.bar+baz@example.com>
324 7       Foo Bar <foo.bar@example.com>
325 EOF
326 test_expect_equal_file EXPECTED OUTPUT
327
328 if [[ NOTMUCH_HAVE_SFSEXP = 1 ]]; then
329     test_begin_subtest "sexpr query: all messages"
330     notmuch address '*' > EXPECTED
331     notmuch address --query=sexp '()' > OUTPUT
332     test_expect_equal_file EXPECTED OUTPUT
333 fi
334
335 test_done