]> git.notmuchmail.org Git - notmuch/blob - test/T650-regexp-query.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T650-regexp-query.sh
1 #!/usr/bin/env bash
2 test_description='regular expression searches'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_message '[dir]=bad' '[subject]="To the bone"'
6 add_message '[dir]=.' '[subject]="Top level"'
7 add_message '[dir]=bad/news' '[subject]="Bears"'
8 mkdir -p "${MAIL_DIR}/duplicate/bad/news"
9 cp "$gen_msg_filename" "${MAIL_DIR}/duplicate/bad/news"
10
11 add_message '[dir]=things' '[subject]="These are a few"'
12 add_message '[dir]=things/favorite' '[subject]="Raindrops, whiskers, kettles"'
13 add_message '[dir]=things/bad' '[subject]="Bites, stings, sad feelings"'
14
15 test_begin_subtest "empty path:// search"
16 notmuch search 'path:""' > EXPECTED
17 notmuch search 'path:/^$/' > OUTPUT
18 test_expect_equal_file EXPECTED OUTPUT
19
20 test_begin_subtest "empty folder:// search"
21 notmuch search 'folder:""' > EXPECTED
22 notmuch search 'folder:/^$/' > OUTPUT
23 test_expect_equal_file EXPECTED OUTPUT
24
25 test_begin_subtest "unanchored folder:// specification"
26 output=$(notmuch search folder:/bad/ | notmuch_search_sanitize)
27 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)
28 thread:XXX   2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)
29 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)"
30
31 test_begin_subtest "anchored folder:// search"
32 output=$(notmuch search 'folder:/^bad$/' | notmuch_search_sanitize)
33 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)"
34
35 test_begin_subtest "unanchored path:// specification"
36 output=$(notmuch search path:/bad/ | notmuch_search_sanitize)
37 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)
38 thread:XXX   2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)
39 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)"
40
41 test_begin_subtest "anchored path:// search"
42 output=$(notmuch search 'path:/^bad$/' | notmuch_search_sanitize)
43 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)"
44
45 # Use "standard" corpus from here on.
46 add_email_corpus
47
48 notmuch search --output=messages from:cworth > cworth.msg-ids
49
50 # these headers will generate no document terms
51 add_message '[from]="-" [subject]="empty from"'
52 add_message '[subject]="-"'
53
54 test_begin_subtest "null from: search"
55 notmuch search 'from:""' | notmuch_search_sanitize > OUTPUT
56 cat <<EOF > EXPECTED
57 thread:XXX   2001-01-05 [1/1] -; empty from (inbox unread)
58 EOF
59 test_expect_equal_file EXPECTED OUTPUT
60
61 test_begin_subtest "null subject: search"
62 notmuch search 'subject:""' | notmuch_search_sanitize > OUTPUT
63 cat <<EOF > EXPECTED
64 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; - (inbox unread)
65 EOF
66 test_expect_equal_file EXPECTED OUTPUT
67
68 test_begin_subtest "bracketed subject search (with dquotes)"
69 notmuch search subject:notmuch and subject:show > EXPECTED
70 notmuch search 'subject:"(show notmuch)"' > OUTPUT
71 test_expect_equal_file_nonempty EXPECTED OUTPUT
72
73 test_begin_subtest "bracketed subject search (with dquotes and operator 'or')"
74 notmuch search subject:notmuch or subject:show > EXPECTED
75 notmuch search 'subject:"(notmuch or show)"' > OUTPUT
76 test_expect_equal_file_nonempty EXPECTED OUTPUT
77
78 test_begin_subtest "bracketed subject search (with dquotes and operator 'and')"
79 notmuch search subject:notmuch and subject:show > EXPECTED
80 notmuch search 'subject:"(notmuch and show)"' > OUTPUT
81 test_expect_equal_file_nonempty EXPECTED OUTPUT
82
83 test_begin_subtest "bracketed subject search (with phrase, operator 'or')"
84 notmuch search 'subject:"mailing list"' or subject:FreeBSD > EXPECTED
85 notmuch search  'subject:"(""mailing list"" or FreeBSD)"' > OUTPUT
86 test_expect_equal_file_nonempty EXPECTED OUTPUT
87
88 test_begin_subtest "bracketed subject search (with phrase, operator 'and')"
89 notmuch search  search 'subject:"notmuch show"' and subject:commands > EXPECTED
90 notmuch search  'subject:"(""notmuch show"" and commands)"' > OUTPUT
91 test_expect_equal_file_nonempty EXPECTED OUTPUT
92
93 test_begin_subtest "xapian wildcard search for from:"
94 notmuch search --output=messages 'from:cwo*' > OUTPUT
95 test_expect_equal_file cworth.msg-ids OUTPUT
96
97 test_begin_subtest "xapian wildcard search for subject:"
98 test_expect_equal $(notmuch count 'subject:count*') 1
99
100 add_message '[from]="and"' '[subject]="and-and-and"'
101 printf "id:$gen_msg_id\n" > EXPECTED
102
103 test_begin_subtest "quoted xapian keyword search for from:"
104 notmuch search --output=messages 'from:"and"' > OUTPUT
105 test_expect_equal_file EXPECTED OUTPUT
106
107 test_begin_subtest "quoted xapian keyword search for subject:"
108 notmuch search --output=messages 'subject:"and-and-and"' > OUTPUT
109 test_expect_equal_file EXPECTED OUTPUT
110
111 test_begin_subtest "regexp from search, case sensitive"
112 notmuch search --output=messages from:/carl/ > OUTPUT
113 test_expect_equal_file /dev/null OUTPUT
114
115 test_begin_subtest "empty regexp or query"
116 notmuch search --output=messages from:/carl/ or from:/cworth/ > OUTPUT
117 test_expect_equal_file cworth.msg-ids OUTPUT
118
119 test_begin_subtest "non-empty regexp and query"
120 notmuch search  from:/cworth@cworth.org/ and subject:patch | notmuch_search_sanitize > OUTPUT
121 cat <<EOF > EXPECTED
122 thread:XXX   2009-11-18 [1/2] Carl Worth| Alex Botero-Lowry; [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)
123 thread:XXX   2009-11-18 [1/2] Carl Worth| Ingmar Vanhassel; [notmuch] [PATCH] Typsos (inbox unread)
124 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
125 thread:XXX   2009-11-18 [1/2] Carl Worth| Keith Packard; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
126 thread:XXX   2009-11-18 [2/5] Carl Worth| Mikhail Gusarov, Keith Packard; [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)
127 EOF
128 test_expect_equal_file EXPECTED OUTPUT
129
130 test_begin_subtest "regexp from search, duplicate term search"
131 notmuch search --output=messages from:/cworth/ > OUTPUT
132 test_expect_equal_file cworth.msg-ids OUTPUT
133
134 test_begin_subtest "long enough regexp matches only desired senders"
135 notmuch search --output=messages 'from:"/C.* Wo/"' > OUTPUT
136 test_expect_equal_file cworth.msg-ids OUTPUT
137
138 test_begin_subtest "shorter regexp matches one more sender"
139 notmuch search --output=messages 'from:"/C.* W/"' > OUTPUT
140 { echo id:1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk; cat cworth.msg-ids; } > EXPECTED
141 test_expect_equal_file EXPECTED OUTPUT
142
143 test_begin_subtest "regexp subject search, non-ASCII"
144 notmuch search --output=messages subject:/accentuĂ©/ > OUTPUT
145 echo id:877h1wv7mg.fsf@inf-8657.int-evry.fr > EXPECTED
146 test_expect_equal_file EXPECTED OUTPUT
147
148 test_begin_subtest "regexp subject search, punctuation"
149 notmuch search subject:/\'X\'/ | notmuch_search_sanitize > OUTPUT
150 cat <<EOF > EXPECTED
151 thread:XXX   2009-11-18 [2/2] Keith Packard, Carl Worth; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
152 EOF
153 test_expect_equal_file EXPECTED OUTPUT
154
155 test_begin_subtest "regexp subject search, no punctuation"
156 notmuch search  subject:/X/ | notmuch_search_sanitize > OUTPUT
157 cat <<EOF > EXPECTED
158 thread:XXX   2009-11-18 [2/2] Keith Packard, Carl Worth; [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)
159 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
160 EOF
161 test_expect_equal_file EXPECTED OUTPUT
162
163 test_begin_subtest "combine regexp from and subject"
164 notmuch search  subject:/-C/ and from:/.an.k/ | notmuch_search_sanitize > OUTPUT
165 cat <<EOF > EXPECTED
166 thread:XXX   2009-11-17 [1/2] Jan Janak| Carl Worth; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
167 EOF
168 test_expect_equal_file EXPECTED OUTPUT
169
170 test_begin_subtest "regexp error reporting"
171 notmuch search 'from:/unbalanced[/' 2>&1 | sed -e '/^A Xapian/ s/[^:]*$//' > OUTPUT
172 cat <<EOF > EXPECTED
173 notmuch search: A Xapian exception occurred
174 A Xapian exception occurred parsing query: Regexp error:
175 Query string was: from:/unbalanced[/
176 EOF
177 test_expect_equal_file EXPECTED OUTPUT
178
179 test_begin_subtest "empty mid search"
180 notmuch search --output=messages mid:yoom > OUTPUT
181 cp /dev/null EXPECTED
182 test_expect_equal_file EXPECTED OUTPUT
183
184 test_begin_subtest "non-empty mid regex search"
185 notmuch search --output=messages mid:/yoom/ > OUTPUT
186 test_expect_equal_file cworth.msg-ids OUTPUT
187
188 test_begin_subtest "combine regexp mid and subject"
189 notmuch search  subject:/-C/ and mid:/y..m/ | notmuch_search_sanitize > OUTPUT
190 cat <<EOF > EXPECTED
191 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
192 EOF
193 test_expect_equal_file EXPECTED OUTPUT
194
195 test_begin_subtest "unanchored tag search"
196 notmuch search tag:signed or tag:inbox > EXPECTED
197 notmuch search tag:/i/ > OUTPUT
198 test_expect_equal_file EXPECTED OUTPUT
199
200 notmuch tag +testsi '*'
201 test_begin_subtest "anchored tag search"
202 notmuch search tag:signed > EXPECTED
203 notmuch search tag:/^si/ > OUTPUT
204 test_expect_equal_file EXPECTED OUTPUT
205
206 test_done