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