]> git.cworth.org Git - notmuch/blob - test/T081-sexpr-search.sh
24c6edd15ac75cbff06662ef36f4c88ad5973d33
[notmuch] / test / T081-sexpr-search.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch search" in several variations'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 if [ $NOTMUCH_HAVE_SFSEXP -ne 1 ]; then
6     printf "Skipping due to missing sfsexp library\n"
7     test_done
8 fi
9
10 add_email_corpus
11
12 for query in '()' '(not)' '(and)' '(or ())' '(or (not))' '(or (and))' \
13             '(or (and) (or) (not (and)))'; do
14     test_begin_subtest "all messages: $query"
15     notmuch search '*' > EXPECTED
16     notmuch search --query=sexp "$query" > OUTPUT
17     test_expect_equal_file EXPECTED OUTPUT
18 done
19
20 for query in '(or)' '(not ())' '(not (not))' '(not (and))' \
21                    '(not (or (and) (or) (not (and))))'; do
22     test_begin_subtest "no messages: $query"
23     notmuch search --query=sexp "$query" > OUTPUT
24     test_expect_equal_file /dev/null OUTPUT
25 done
26
27 test_begin_subtest "and of exact terms"
28 notmuch search --query=sexp '(and "wonderful" "wizard")' | notmuch_search_sanitize > OUTPUT
29 cat <<EOF > EXPECTED
30 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
31 EOF
32 test_expect_equal_file EXPECTED OUTPUT
33
34 test_begin_subtest "or of exact terms"
35 notmuch search --query=sexp '(or "php" "wizard")' | notmuch_search_sanitize > OUTPUT
36 cat <<EOF > EXPECTED
37 thread:XXX   2010-12-29 [1/1] François Boulogne; [aur-general] Guidelines: cp, mkdir vs install (inbox unread)
38 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
39 EOF
40 test_expect_equal_file EXPECTED OUTPUT
41
42 test_begin_subtest "single term in body"
43 notmuch search --query=sexp 'wizard' | notmuch_search_sanitize>OUTPUT
44 cat <<EOF > EXPECTED
45 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
46 EOF
47 test_expect_equal_file EXPECTED OUTPUT
48
49 test_begin_subtest "single term in body (case insensitive)"
50 notmuch search --query=sexp 'Wizard' | notmuch_search_sanitize>OUTPUT
51 cat <<EOF > EXPECTED
52 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
53 EOF
54 test_expect_equal_file EXPECTED OUTPUT
55
56 test_begin_subtest "single term in body, stemmed version"
57 notmuch search arriv > EXPECTED
58 notmuch search --query=sexp arriv > OUTPUT
59 test_expect_equal_file EXPECTED OUTPUT
60
61 test_begin_subtest "single term in body, unstemmed version"
62 notmuch search --query=sexp '"arriv"' > OUTPUT
63 test_expect_equal_file /dev/null OUTPUT
64
65 test_begin_subtest "Search by 'subject'"
66 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
67 output=$(notmuch search --query=sexp '(subject subjectsearchtest)' | notmuch_search_sanitize)
68 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
69
70 test_begin_subtest "Search by 'subject' (case insensitive)"
71 notmuch search tag:inbox and subject:maildir | notmuch_search_sanitize > EXPECTED
72 notmuch search --query=sexp '(subject "Maildir")' | notmuch_search_sanitize > OUTPUT
73 test_expect_equal_file EXPECTED OUTPUT
74
75 test_begin_subtest "Search by 'subject' (utf-8):"
76 add_message [subject]=utf8-sübjéct '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
77 output=$(notmuch search --query=sexp '(subject utf8 sübjéct)' | notmuch_search_sanitize)
78 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
79
80 test_begin_subtest "Search by 'subject' (utf-8, and):"
81 output=$(notmuch search --query=sexp '(subject (and utf8 sübjéct))' | notmuch_search_sanitize)
82 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
83
84 test_begin_subtest "Search by 'subject' (utf-8, and outside):"
85 output=$(notmuch search --query=sexp '(and (subject utf8) (subject sübjéct))' | notmuch_search_sanitize)
86 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
87
88 test_begin_subtest "Search by 'subject' (utf-8, or):"
89 notmuch search --query=sexp '(subject (or utf8 subjectsearchtest))' | notmuch_search_sanitize > OUTPUT
90 cat <<EOF > EXPECTED
91 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
92 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)
93 EOF
94 test_expect_equal_file EXPECTED OUTPUT
95
96 test_begin_subtest "Search by 'subject' (utf-8, or outside):"
97 notmuch search --query=sexp '(or (subject utf8) (subject subjectsearchtest))' | notmuch_search_sanitize > OUTPUT
98 cat <<EOF > EXPECTED
99 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
100 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)
101 EOF
102 test_expect_equal_file EXPECTED OUTPUT
103
104 test_begin_subtest "Search by 'attachment'"
105 notmuch search attachment:notmuch-help.patch > EXPECTED
106 notmuch search --query=sexp '(attachment notmuch-help.patch)' > OUTPUT
107 test_expect_equal_file EXPECTED OUTPUT
108
109 test_begin_subtest "Search by 'body'"
110 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
111 output=$(notmuch search --query=sexp '(body bodysearchtest)' | notmuch_search_sanitize)
112 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
113
114 test_begin_subtest "Search by 'body' (phrase)"
115 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
116 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
117 output=$(notmuch search --query=sexp '(body "body search phrase")' | notmuch_search_sanitize)
118 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
119
120 test_begin_subtest "Search by 'body' (utf-8):"
121 add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="message body utf8: bödý"'
122 output=$(notmuch search --query=sexp '(body bödý)' | notmuch_search_sanitize)
123 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
124
125 test_begin_subtest "Search by 'from'"
126 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
127 output=$(notmuch search --query=sexp '(from searchbyfrom)' | notmuch_search_sanitize)
128 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
129
130 test_begin_subtest "Search by 'from' (address)"
131 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
132 output=$(notmuch search --query=sexp '(from searchbyfrom@example.com)' | notmuch_search_sanitize)
133 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
134
135 test_begin_subtest "Search by 'from' (name)"
136 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
137 output=$(notmuch search --query=sexp '(from "Search By From Name")' | notmuch_search_sanitize)
138 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
139
140 test_begin_subtest "Search by 'from' (name and address)"
141 output=$(notmuch search --query=sexp '(from "Search By From Name <test@example.com>")' | notmuch_search_sanitize)
142 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
143
144 add_message '[dir]=bad' '[subject]="To the bone"'
145 add_message '[dir]=.' '[subject]="Top level"'
146 add_message '[dir]=bad/news' '[subject]="Bears"'
147 mkdir -p "${MAIL_DIR}/duplicate/bad/news"
148 cp "$gen_msg_filename" "${MAIL_DIR}/duplicate/bad/news"
149
150 add_message '[dir]=things' '[subject]="These are a few"'
151 add_message '[dir]=things/favorite' '[subject]="Raindrops, whiskers, kettles"'
152 add_message '[dir]=things/bad' '[subject]="Bites, stings, sad feelings"'
153
154 test_begin_subtest "Search by 'folder' (multiple)"
155 output=$(notmuch search --query=sexp '(folder bad bad/news things/bad)' | notmuch_search_sanitize)
156 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)
157 thread:XXX   2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)
158 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)"
159
160 test_begin_subtest "Search by 'folder': top level."
161 notmuch search folder:'""' > EXPECTED
162 notmuch search --query=sexp '(folder "")'  > OUTPUT
163 test_expect_equal_file EXPECTED OUTPUT
164
165 test_begin_subtest "Search by 'id'"
166 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
167 output=$(notmuch search --query=sexp "(id ${gen_msg_id})" | notmuch_search_sanitize)
168 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
169
170 test_begin_subtest "Search by 'id' (or)"
171 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
172 output=$(notmuch search --query=sexp "(id non-existent-mid ${gen_msg_id})" | notmuch_search_sanitize)
173 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
174
175 test_begin_subtest "Search by 'is' (multiple)"
176 notmuch tag -inbox tag:searchbytag
177 notmuch search is:inbox AND is:unread | notmuch_search_sanitize > EXPECTED
178 notmuch search --query=sexp '(is inbox unread)' | notmuch_search_sanitize > OUTPUT
179 notmuch tag +inbox tag:searchbytag
180 test_expect_equal_file EXPECTED OUTPUT
181
182 test_begin_subtest "Search by 'mid'"
183 add_message '[subject]="search by mid"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
184 output=$(notmuch search --query=sexp "(mid ${gen_msg_id})" | notmuch_search_sanitize)
185 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by mid (inbox unread)"
186
187 test_begin_subtest "Search by 'mid' (or)"
188 add_message '[subject]="search by mid"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
189 output=$(notmuch search --query=sexp "(mid non-existent-mid ${gen_msg_id})" | notmuch_search_sanitize)
190 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by mid (inbox unread)"
191
192 test_begin_subtest "Search by 'mimetype'"
193 notmuch search mimetype:text/html > EXPECTED
194 notmuch search --query=sexp '(mimetype text html)'  > OUTPUT
195 test_expect_equal_file EXPECTED OUTPUT
196
197 test_begin_subtest "Search by 'subject' (utf-8, phrase-token):"
198 output=$(notmuch search --query=sexp '(subject utf8-sübjéct)' | notmuch_search_sanitize)
199 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
200
201 test_begin_subtest "Search by 'subject' (utf-8, quoted string):"
202 output=$(notmuch search --query=sexp '(subject "utf8 sübjéct")' | notmuch_search_sanitize)
203 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
204
205 test_begin_subtest "Search by 'subject' (combine phrase, term):"
206 output=$(notmuch search --query=sexp '(subject Mac "compatibility issues")' | notmuch_search_sanitize)
207 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
208
209 test_begin_subtest "Search by 'subject' (combine phrase, term 2):"
210 notmuch search --query=sexp '(subject (or utf8 "compatibility issues"))' | notmuch_search_sanitize > OUTPUT
211 cat <<EOF > EXPECTED
212 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
213 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)
214 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)
215 EOF
216 test_expect_equal_file EXPECTED OUTPUT
217
218 test_begin_subtest "Search by 'subject' (combine phrase, term 3):"
219 notmuch search --query=sexp '(subject issues X/Darwin)' | notmuch_search_sanitize > OUTPUT
220 cat <<EOF > EXPECTED
221 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
222 EOF
223 test_expect_equal_file EXPECTED OUTPUT
224
225 test_begin_subtest "Search by 'tag'"
226 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
227 notmuch tag +searchbytag id:${gen_msg_id}
228 output=$(notmuch search --query=sexp '(tag searchbytag)' | notmuch_search_sanitize)
229 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
230
231 test_begin_subtest "Search by 'tag' (multiple)"
232 notmuch tag -inbox tag:searchbytag
233 notmuch search tag:inbox AND tag:unread | notmuch_search_sanitize > EXPECTED
234 notmuch search --query=sexp '(tag inbox unread)' | notmuch_search_sanitize > OUTPUT
235 notmuch tag +inbox tag:searchbytag
236 test_expect_equal_file EXPECTED OUTPUT
237
238 test_begin_subtest "Search by 'tag' and 'subject'"
239 notmuch search tag:inbox and subject:maildir | notmuch_search_sanitize > EXPECTED
240 notmuch search --query=sexp '(and (tag inbox) (subject maildir))' | notmuch_search_sanitize > OUTPUT
241 test_expect_equal_file EXPECTED OUTPUT
242
243 test_begin_subtest "Search by 'thread'"
244 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
245 thread_id=$(notmuch search id:${gen_msg_id} | sed -e "s/thread:\([a-f0-9]*\).*/\1/")
246 output=$(notmuch search --query=sexp "(thread ${thread_id})" | notmuch_search_sanitize)
247 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
248
249 test_begin_subtest "Search by 'to'"
250 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
251 output=$(notmuch search --query=sexp '(to searchbyto)' | notmuch_search_sanitize)
252 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
253
254 test_begin_subtest "Search by 'to' (address)"
255 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
256 output=$(notmuch search --query=sexp '(to searchbyto@example.com)' | notmuch_search_sanitize)
257 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
258
259 test_begin_subtest "Search by 'to' (name)"
260 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
261 output=$(notmuch search --query=sexp '(to "Search By To Name")' | notmuch_search_sanitize)
262 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
263
264 test_begin_subtest "Search by 'to' (name and address)"
265 output=$(notmuch search --query=sexp '(to "Search By To Name <test@example.com>")' | notmuch_search_sanitize)
266 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
267
268 test_begin_subtest "starts-with, no prefix"
269 output=$(notmuch search --query=sexp '(starts-with prelim)' | notmuch_search_sanitize)
270 test_expect_equal "$output" "thread:XXX   2009-11-17 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] preliminary FreeBSD support (attachment inbox unread)"
271
272 test_begin_subtest "starts-with, case-insensitive"
273 notmuch search --query=sexp '(starts-with FreeB)' | notmuch_search_sanitize > OUTPUT
274 cat <<EOF > EXPECTED
275 thread:XXX   2009-11-18 [3/4] Alexander Botero-Lowry, Jjgod Jiang; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
276 thread:XXX   2009-11-17 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] preliminary FreeBSD support (attachment inbox unread)
277 EOF
278 test_expect_equal_file EXPECTED OUTPUT
279
280 test_begin_subtest "starts-with, no prefix, all messages"
281 notmuch search --query=sexp '(starts-with "")' | notmuch_search_sanitize > OUTPUT
282 notmuch search '*' | notmuch_search_sanitize > EXPECTED
283 test_expect_equal_file EXPECTED OUTPUT
284
285 test_begin_subtest "starts-with, attachment"
286 output=$(notmuch search --query=sexp '(attachment (starts-with not))' | notmuch_search_sanitize)
287 test_expect_equal "$output" 'thread:XXX   2009-11-18 [2/2] Lars Kellogg-Stedman; [notmuch] "notmuch help" outputs to stderr? (attachment inbox signed unread)'
288
289 test_begin_subtest "starts-with, folder"
290 notmuch search --output=files --query=sexp '(folder (starts-with bad))' | notmuch_dir_sanitize > OUTPUT
291 cat <<EOF > EXPECTED
292 MAIL_DIR/bad/msg-010
293 MAIL_DIR/bad/news/msg-012
294 MAIL_DIR/duplicate/bad/news/msg-012
295 EOF
296 test_expect_equal_file EXPECTED OUTPUT
297
298 test_begin_subtest "starts-with, from"
299 notmuch search --query=sexp '(from (starts-with Mik))' | notmuch_search_sanitize > OUTPUT
300 cat <<EOF > EXPECTED
301 thread:XXX   2009-11-17 [1/1] Mikhail Gusarov; [notmuch] [PATCH] Handle rename of message file (inbox unread)
302 thread:XXX   2009-11-17 [2/7] Mikhail Gusarov| Lars Kellogg-Stedman, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread)
303 thread:XXX   2009-11-17 [2/5] Mikhail Gusarov| Carl Worth, Keith Packard; [notmuch] [PATCH 2/2] Include <stdint.h> to get uint32_t in C++ file with gcc 4.4 (inbox unread)
304 EOF
305 test_expect_equal_file EXPECTED OUTPUT
306
307 test_begin_subtest "starts-with, id"
308 notmuch search --query=sexp --output=messages '(id (starts-with 877))' > OUTPUT
309 cat <<EOF > EXPECTED
310 id:877h1wv7mg.fsf@inf-8657.int-evry.fr
311 id:877htoqdbo.fsf@yoom.home.cworth.org
312 EOF
313 test_expect_equal_file EXPECTED OUTPUT
314
315 test_begin_subtest "starts-with, is"
316 output=$(notmuch search --query=sexp '(is (starts-with searchby))' | notmuch_search_sanitize)
317 test_expect_equal "$output" 'thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)'
318
319 test_begin_subtest "starts-with, mid"
320 notmuch search --query=sexp --output=messages '(mid (starts-with 877))' > OUTPUT
321 cat <<EOF > EXPECTED
322 id:877h1wv7mg.fsf@inf-8657.int-evry.fr
323 id:877htoqdbo.fsf@yoom.home.cworth.org
324 EOF
325 test_expect_equal_file EXPECTED OUTPUT
326
327 test_begin_subtest "starts-with, mimetype"
328 notmuch search --query=sexp '(mimetype (starts-with sig))' | notmuch_search_sanitize > OUTPUT
329 cat <<EOF > EXPECTED
330 thread:XXX   2009-11-18 [2/2] Lars Kellogg-Stedman; [notmuch] "notmuch help" outputs to stderr? (attachment inbox signed unread)
331 thread:XXX   2009-11-18 [4/7] Lars Kellogg-Stedman, Mikhail Gusarov| Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread)
332 thread:XXX   2009-11-17 [1/3] Adrian Perez de Castro| Keith Packard, Carl Worth; [notmuch] Introducing myself (inbox signed unread)
333 EOF
334 test_expect_equal_file EXPECTED OUTPUT
335
336 add_message '[subject]="message with properties"'
337 notmuch restore <<EOF
338 #= ${gen_msg_id} foo=bar
339 EOF
340
341 test_begin_subtest "starts-with, property"
342 notmuch search --query=sexp '(property (starts-with foo=))' | notmuch_search_sanitize > OUTPUT
343 cat <<EOF > EXPECTED
344 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; message with properties (inbox unread)
345 EOF
346 test_expect_equal_file EXPECTED OUTPUT
347
348 test_begin_subtest "starts-with, subject"
349 notmuch search --query=sexp '(subject (starts-with FreeB))' | notmuch_search_sanitize > OUTPUT
350 cat <<EOF > EXPECTED
351 thread:XXX   2009-11-17 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] preliminary FreeBSD support (attachment inbox unread)
352 EOF
353 test_expect_equal_file EXPECTED OUTPUT
354
355 test_begin_subtest "starts-with, tag"
356 output=$(notmuch search --query=sexp '(tag (starts-with searchby))' | notmuch_search_sanitize)
357 test_expect_equal "$output" 'thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)'
358
359 add_message '[subject]="no tags"'
360 notag_mid=${gen_msg_id}
361 notmuch tag -unread -inbox id:${notag_mid}
362
363 test_begin_subtest "negated starts-with, tag"
364 output=$(notmuch search --query=sexp '(tag (not (starts-with in)))' | notmuch_search_sanitize)
365 test_expect_equal "$output" 'thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; no tags ()'
366
367 test_begin_subtest "negated starts-with, tag 2"
368 output=$(notmuch search --query=sexp '(not (tag (starts-with in)))' | notmuch_search_sanitize)
369 test_expect_equal "$output" 'thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; no tags ()'
370
371 test_begin_subtest "negated starts-with, tag 3"
372 output=$(notmuch search --query=sexp '(not (tag (starts-with "")))' | notmuch_search_sanitize)
373 test_expect_equal "$output" 'thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; no tags ()'
374
375 test_begin_subtest "starts-with, thread"
376 notmuch search --query=sexp '(thread (starts-with "00"))' > OUTPUT
377 notmuch search '*' > EXPECTED
378 test_expect_equal_file EXPECTED OUTPUT
379
380 test_begin_subtest "starts-with, to"
381 notmuch search --query=sexp '(to (starts-with "search"))' | notmuch_search_sanitize > OUTPUT
382 cat <<EOF > EXPECTED
383 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
384 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
385 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
386 EOF
387 test_expect_equal_file EXPECTED OUTPUT
388
389 test_begin_subtest "Unbalanced parens"
390 # A code 1 indicates the error was handled (a crash will return e.g. 139).
391 test_expect_code 1 "notmuch search --query=sexp '('"
392
393 test_begin_subtest "Unbalanced parens, error message"
394 notmuch search --query=sexp '(' >OUTPUT 2>&1
395 cat <<EOF > EXPECTED
396 notmuch search: Syntax error in query
397 invalid s-expression: '('
398 EOF
399 test_expect_equal_file EXPECTED OUTPUT
400
401 test_begin_subtest "unknown prefix"
402 notmuch search --query=sexp '(foo)' >OUTPUT 2>&1
403 cat <<EOF > EXPECTED
404 notmuch search: Syntax error in query
405 unknown prefix 'foo'
406 EOF
407 test_expect_equal_file EXPECTED OUTPUT
408
409 test_begin_subtest "list as prefix"
410 notmuch search --query=sexp '((foo))' >OUTPUT 2>&1
411 cat <<EOF > EXPECTED
412 notmuch search: Syntax error in query
413 unexpected list in field/operation position
414 EOF
415 test_expect_equal_file EXPECTED OUTPUT
416
417 test_begin_subtest "illegal nesting"
418 notmuch search --query=sexp '(subject (subject foo))' >OUTPUT 2>&1
419 cat <<EOF > EXPECTED
420 notmuch search: Syntax error in query
421 nested field: 'subject' inside 'subject'
422 EOF
423 test_expect_equal_file EXPECTED OUTPUT
424
425 test_begin_subtest "starts-with, no argument"
426 notmuch search --query=sexp '(starts-with)' >OUTPUT 2>&1
427 cat <<EOF > EXPECTED
428 notmuch search: Syntax error in query
429 'starts-with' expects single atom as argument
430 EOF
431 test_expect_equal_file EXPECTED OUTPUT
432
433 test_begin_subtest "starts-with, list argument"
434 notmuch search --query=sexp '(starts-with (stuff))' >OUTPUT 2>&1
435 cat <<EOF > EXPECTED
436 notmuch search: Syntax error in query
437 'starts-with' expects single atom as argument
438 EOF
439 test_expect_equal_file EXPECTED OUTPUT
440
441 test_begin_subtest "starts-with, too many arguments"
442 notmuch search --query=sexp '(starts-with a b c)' >OUTPUT 2>&1
443 cat <<EOF > EXPECTED
444 notmuch search: Syntax error in query
445 'starts-with' expects single atom as argument
446 EOF
447 test_expect_equal_file EXPECTED OUTPUT
448
449 test_begin_subtest "starts-with, illegal field"
450 notmuch search --query=sexp '(body (starts-with foo))' >OUTPUT 2>&1
451 cat <<EOF > EXPECTED
452 notmuch search: Syntax error in query
453 'body' does not support wildcard queries
454 EOF
455 test_expect_equal_file EXPECTED OUTPUT
456
457 test_done