]> git.cworth.org Git - notmuch/blob - test/T650-regexp-query.sh
Merge branch 'release'
[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 "xapian wildcard search for from:"
69 notmuch search --output=messages 'from:cwo*' > OUTPUT
70 test_expect_equal_file cworth.msg-ids OUTPUT
71
72 test_begin_subtest "xapian wildcard search for subject:"
73 test_expect_equal $(notmuch count 'subject:count*') 1
74
75 add_message '[from]="and"' '[subject]="and-and-and"'
76 printf "id:$gen_msg_id\n" > EXPECTED
77
78 test_begin_subtest "quoted xapian keyword search for from:"
79 notmuch search --output=messages 'from:"and"' > OUTPUT
80 test_expect_equal_file EXPECTED OUTPUT
81
82 test_begin_subtest "quoted xapian keyword search for subject:"
83 notmuch search --output=messages 'subject:"and-and-and"' > OUTPUT
84 test_expect_equal_file EXPECTED OUTPUT
85
86 test_begin_subtest "regexp from search, case sensitive"
87 notmuch search --output=messages from:/carl/ > OUTPUT
88 test_expect_equal_file /dev/null OUTPUT
89
90 test_begin_subtest "empty regexp or query"
91 notmuch search --output=messages from:/carl/ or from:/cworth/ > OUTPUT
92 test_expect_equal_file cworth.msg-ids OUTPUT
93
94 test_begin_subtest "non-empty regexp and query"
95 notmuch search  from:/cworth@cworth.org/ and subject:patch | notmuch_search_sanitize > OUTPUT
96 cat <<EOF > EXPECTED
97 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)
98 thread:XXX   2009-11-18 [1/2] Carl Worth| Ingmar Vanhassel; [notmuch] [PATCH] Typsos (inbox unread)
99 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
100 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)
101 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)
102 EOF
103 test_expect_equal_file EXPECTED OUTPUT
104
105 test_begin_subtest "regexp from search, duplicate term search"
106 notmuch search --output=messages from:/cworth/ > OUTPUT
107 test_expect_equal_file cworth.msg-ids OUTPUT
108
109 test_begin_subtest "long enough regexp matches only desired senders"
110 notmuch search --output=messages 'from:"/C.* Wo/"' > OUTPUT
111 test_expect_equal_file cworth.msg-ids OUTPUT
112
113 test_begin_subtest "shorter regexp matches one more sender"
114 notmuch search --output=messages 'from:"/C.* W/"' > OUTPUT
115 { echo id:1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk; cat cworth.msg-ids; } > EXPECTED
116 test_expect_equal_file EXPECTED OUTPUT
117
118 test_begin_subtest "regexp subject search, non-ASCII"
119 notmuch search --output=messages subject:/accentuĂ©/ > OUTPUT
120 echo id:877h1wv7mg.fsf@inf-8657.int-evry.fr > EXPECTED
121 test_expect_equal_file EXPECTED OUTPUT
122
123 test_begin_subtest "regexp subject search, punctuation"
124 notmuch search subject:/\'X\'/ | notmuch_search_sanitize > OUTPUT
125 cat <<EOF > EXPECTED
126 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)
127 EOF
128 test_expect_equal_file EXPECTED OUTPUT
129
130 test_begin_subtest "regexp subject search, no punctuation"
131 notmuch search  subject:/X/ | notmuch_search_sanitize > OUTPUT
132 cat <<EOF > EXPECTED
133 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)
134 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
135 EOF
136 test_expect_equal_file EXPECTED OUTPUT
137
138 test_begin_subtest "combine regexp from and subject"
139 notmuch search  subject:/-C/ and from:/.an.k/ | notmuch_search_sanitize > OUTPUT
140 cat <<EOF > EXPECTED
141 thread:XXX   2009-11-17 [1/2] Jan Janak| Carl Worth; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
142 EOF
143 test_expect_equal_file EXPECTED OUTPUT
144
145 test_begin_subtest "regexp error reporting"
146 notmuch search 'from:/unbalanced[/' 2>&1 | sed -e '/^A Xapian/ s/[^:]*$//' > OUTPUT
147 cat <<EOF > EXPECTED
148 notmuch search: A Xapian exception occurred
149 A Xapian exception occurred parsing query: Regexp error:
150 Query string was: from:/unbalanced[/
151 EOF
152 test_expect_equal_file EXPECTED OUTPUT
153
154 test_begin_subtest "empty mid search"
155 notmuch search --output=messages mid:yoom > OUTPUT
156 cp /dev/null EXPECTED
157 test_expect_equal_file EXPECTED OUTPUT
158
159 test_begin_subtest "non-empty mid regex search"
160 notmuch search --output=messages mid:/yoom/ > OUTPUT
161 test_expect_equal_file cworth.msg-ids OUTPUT
162
163 test_begin_subtest "combine regexp mid and subject"
164 notmuch search  subject:/-C/ and mid:/y..m/ | notmuch_search_sanitize > OUTPUT
165 cat <<EOF > EXPECTED
166 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [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 "unanchored tag search"
171 notmuch search tag:signed or tag:inbox > EXPECTED
172 notmuch search tag:/i/ > OUTPUT
173 test_expect_equal_file EXPECTED OUTPUT
174
175 notmuch tag +testsi '*'
176 test_begin_subtest "anchored tag search"
177 notmuch search tag:signed > EXPECTED
178 notmuch search tag:/^si/ > OUTPUT
179 test_expect_equal_file EXPECTED OUTPUT
180
181 test_done