test: notmuch address --deduplicate=no tests
[notmuch] / test / T095-address.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch address" in several variants'
3 . ./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 OUTPUT EXPECTED
29
30 test_begin_subtest "without --output"
31 notmuch address '*' >OUTPUT
32 # Use EXPECTED from previous subtest
33 test_expect_equal_file OUTPUT EXPECTED
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 OUTPUT EXPECTED
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 OUTPUT EXPECTED
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 OUTPUT EXPECTED
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 OUTPUT EXPECTED
121
122 test_begin_subtest "--output=count --format=json"
123 # Since the iteration order of GHashTable is not specified, we
124 # preprocess and sort the results to keep the order stable here.
125 notmuch address --output=count --format=json '*' | \
126     sed -e 's/^\[//' -e 's/]$//' -e 's/,$//' | sort >OUTPUT
127 cat <<EOF >EXPECTED
128 {"name": "Adrian Perez de Castro", "address": "aperez@igalia.com", "name-addr": "Adrian Perez de Castro <aperez@igalia.com>", "count": 1}
129 {"name": "Alex Botero-Lowry", "address": "alex.boterolowry@gmail.com", "name-addr": "Alex Botero-Lowry <alex.boterolowry@gmail.com>", "count": 2}
130 {"name": "Alexander Botero-Lowry", "address": "alex.boterolowry@gmail.com", "name-addr": "Alexander Botero-Lowry <alex.boterolowry@gmail.com>", "count": 4}
131 {"name": "Aron Griffis", "address": "agriffis@n01se.net", "name-addr": "Aron Griffis <agriffis@n01se.net>", "count": 1}
132 {"name": "Carl Worth", "address": "cworth@cworth.org", "name-addr": "Carl Worth <cworth@cworth.org>", "count": 12}
133 {"name": "Chris Wilson", "address": "chris@chris-wilson.co.uk", "name-addr": "Chris Wilson <chris@chris-wilson.co.uk>", "count": 1}
134 {"name": "François Boulogne", "address": "boulogne.f@gmail.com", "name-addr": "François Boulogne <boulogne.f@gmail.com>", "count": 1}
135 {"name": "Ingmar Vanhassel", "address": "ingmar@exherbo.org", "name-addr": "Ingmar Vanhassel <ingmar@exherbo.org>", "count": 1}
136 {"name": "Israel Herraiz", "address": "isra@herraiz.org", "name-addr": "Israel Herraiz <isra@herraiz.org>", "count": 1}
137 {"name": "Jan Janak", "address": "jan@ryngle.com", "name-addr": "Jan Janak <jan@ryngle.com>", "count": 4}
138 {"name": "Jjgod Jiang", "address": "gzjjgod@gmail.com", "name-addr": "Jjgod Jiang <gzjjgod@gmail.com>", "count": 2}
139 {"name": "Keith Packard", "address": "keithp@keithp.com", "name-addr": "Keith Packard <keithp@keithp.com>", "count": 7}
140 {"name": "Lars Kellogg-Stedman", "address": "lars@seas.harvard.edu", "name-addr": "Lars Kellogg-Stedman <lars@seas.harvard.edu>", "count": 5}
141 {"name": "Mikhail Gusarov", "address": "dottedmag@dottedmag.net", "name-addr": "Mikhail Gusarov <dottedmag@dottedmag.net>", "count": 5}
142 {"name": "Olivier Berger", "address": "olivier.berger@it-sudparis.eu", "name-addr": "Olivier Berger <olivier.berger@it-sudparis.eu>", "count": 1}
143 {"name": "Rolland Santimano", "address": "rollandsantimano@yahoo.com", "name-addr": "Rolland Santimano <rollandsantimano@yahoo.com>", "count": 1}
144 {"name": "Stewart Smith", "address": "stewart@flamingspork.com", "name-addr": "Stewart Smith <stewart@flamingspork.com>", "count": 3}
145 EOF
146 test_expect_equal_file OUTPUT EXPECTED
147
148 test_begin_subtest "--deduplicate=no --sort=oldest-first --output=sender"
149 notmuch address --deduplicate=no --sort=oldest-first --output=sender '*' >OUTPUT
150 cat <<EOF >EXPECTED
151 Mikhail Gusarov <dottedmag@dottedmag.net>
152 Mikhail Gusarov <dottedmag@dottedmag.net>
153 Carl Worth <cworth@cworth.org>
154 Lars Kellogg-Stedman <lars@seas.harvard.edu>
155 Mikhail Gusarov <dottedmag@dottedmag.net>
156 Alex Botero-Lowry <alex.boterolowry@gmail.com>
157 Carl Worth <cworth@cworth.org>
158 Lars Kellogg-Stedman <lars@seas.harvard.edu>
159 Mikhail Gusarov <dottedmag@dottedmag.net>
160 Mikhail Gusarov <dottedmag@dottedmag.net>
161 Keith Packard <keithp@keithp.com>
162 Keith Packard <keithp@keithp.com>
163 Keith Packard <keithp@keithp.com>
164 Jan Janak <jan@ryngle.com>
165 Jan Janak <jan@ryngle.com>
166 Jan Janak <jan@ryngle.com>
167 Israel Herraiz <isra@herraiz.org>
168 Adrian Perez de Castro <aperez@igalia.com>
169 Aron Griffis <agriffis@n01se.net>
170 Ingmar Vanhassel <ingmar@exherbo.org>
171 Alex Botero-Lowry <alex.boterolowry@gmail.com>
172 Lars Kellogg-Stedman <lars@seas.harvard.edu>
173 Lars Kellogg-Stedman <lars@seas.harvard.edu>
174 Lars Kellogg-Stedman <lars@seas.harvard.edu>
175 Stewart Smith <stewart@flamingspork.com>
176 Stewart Smith <stewart@flamingspork.com>
177 Keith Packard <keithp@keithp.com>
178 Keith Packard <keithp@keithp.com>
179 Keith Packard <keithp@keithp.com>
180 Stewart Smith <stewart@flamingspork.com>
181 Jjgod Jiang <gzjjgod@gmail.com>
182 Jan Janak <jan@ryngle.com>
183 Rolland Santimano <rollandsantimano@yahoo.com>
184 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
185 Jjgod Jiang <gzjjgod@gmail.com>
186 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
187 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
188 Keith Packard <keithp@keithp.com>
189 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
190 Carl Worth <cworth@cworth.org>
191 Carl Worth <cworth@cworth.org>
192 Carl Worth <cworth@cworth.org>
193 Carl Worth <cworth@cworth.org>
194 Carl Worth <cworth@cworth.org>
195 Carl Worth <cworth@cworth.org>
196 Carl Worth <cworth@cworth.org>
197 Carl Worth <cworth@cworth.org>
198 Carl Worth <cworth@cworth.org>
199 Carl Worth <cworth@cworth.org>
200 Chris Wilson <chris@chris-wilson.co.uk>
201 Olivier Berger <olivier.berger@it-sudparis.eu>
202 François Boulogne <boulogne.f@gmail.com>
203 EOF
204 test_expect_equal_file OUTPUT EXPECTED
205
206 test_begin_subtest "--deduplicate=no --sort=newest-first --output=sender --output=recipients"
207 notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo/new >OUTPUT
208 cat <<EOF >EXPECTED
209 Mikhail Gusarov <dottedmag@dottedmag.net>
210 notmuch@notmuchmail.org
211 Mikhail Gusarov <dottedmag@dottedmag.net>
212 notmuch@notmuchmail.org
213 Lars Kellogg-Stedman <lars@seas.harvard.edu>
214 notmuch@notmuchmail.org
215 EOF
216 test_expect_equal_file OUTPUT EXPECTED
217
218 test_done