]> git.notmuchmail.org Git - notmuch/blob - test/T650-regexp-query.sh
cli: implement structured output version 4
[notmuch] / test / T650-regexp-query.sh
1 #!/usr/bin/env bash
2 test_description='regular expression searches'
3 . ./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] 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] 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 rm -rf $MAIL_DIR
51 add_email_corpus
52
53 notmuch search --output=messages from:cworth > cworth.msg-ids
54
55 # these headers will generate no document terms
56 add_message '[from]="-" [subject]="empty from"'
57 add_message '[subject]="-"'
58
59 test_begin_subtest "null from: search"
60 notmuch search 'from:""' | notmuch_search_sanitize > OUTPUT
61 cat <<EOF > EXPECTED
62 thread:XXX   2001-01-05 [1/1] -; empty from (inbox unread)
63 EOF
64 test_expect_equal_file EXPECTED OUTPUT
65
66 test_begin_subtest "null subject: search"
67 notmuch search 'subject:""' | notmuch_search_sanitize > OUTPUT
68 cat <<EOF > EXPECTED
69 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; - (inbox unread)
70 EOF
71 test_expect_equal_file EXPECTED OUTPUT
72
73 test_begin_subtest "xapian wildcard search for from:"
74 notmuch search --output=messages 'from:cwo*' > OUTPUT
75 test_expect_equal_file cworth.msg-ids OUTPUT
76
77 test_begin_subtest "xapian wildcard search for subject:"
78 test_expect_equal $(notmuch count 'subject:count*') 1
79
80 test_begin_subtest "regexp from search, case sensitive"
81 notmuch search --output=messages from:/carl/ > OUTPUT
82 test_expect_equal_file /dev/null OUTPUT
83
84 test_begin_subtest "empty regexp or query"
85 notmuch search --output=messages from:/carl/ or from:/cworth/ > OUTPUT
86 test_expect_equal_file cworth.msg-ids OUTPUT
87
88 test_begin_subtest "non-empty regexp and query"
89 notmuch search  from:/cworth@cworth.org/ and subject:patch | notmuch_search_sanitize > OUTPUT
90 cat <<EOF > EXPECTED
91 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)
92 thread:XXX   2009-11-18 [1/2] Carl Worth| Ingmar Vanhassel; [notmuch] [PATCH] Typsos (inbox unread)
93 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
94 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)
95 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)
96 EOF
97 test_expect_equal_file EXPECTED OUTPUT
98
99 test_begin_subtest "regexp from search, duplicate term search"
100 notmuch search --output=messages from:/cworth/ > OUTPUT
101 test_expect_equal_file cworth.msg-ids OUTPUT
102
103 test_begin_subtest "long enough regexp matches only desired senders"
104 notmuch search --output=messages 'from:"/C.* Wo/"' > OUTPUT
105 test_expect_equal_file cworth.msg-ids OUTPUT
106
107 test_begin_subtest "shorter regexp matches one more sender"
108 notmuch search --output=messages 'from:"/C.* W/"' > OUTPUT
109 { echo id:1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk; cat cworth.msg-ids; } > EXPECTED
110 test_expect_equal_file EXPECTED OUTPUT
111
112 test_begin_subtest "regexp subject search, non-ASCII"
113 notmuch search --output=messages subject:/accentuĂ©/ > OUTPUT
114 echo id:877h1wv7mg.fsf@inf-8657.int-evry.fr > EXPECTED
115 test_expect_equal_file EXPECTED OUTPUT
116
117 test_begin_subtest "regexp subject search, punctuation"
118 notmuch search subject:/\'X\'/ | notmuch_search_sanitize > OUTPUT
119 cat <<EOF > EXPECTED
120 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)
121 EOF
122 test_expect_equal_file EXPECTED OUTPUT
123
124 test_begin_subtest "regexp subject search, no punctuation"
125 notmuch search  subject:/X/ | notmuch_search_sanitize > OUTPUT
126 cat <<EOF > EXPECTED
127 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)
128 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
129 EOF
130 test_expect_equal_file EXPECTED OUTPUT
131
132 test_begin_subtest "combine regexp from and subject"
133 notmuch search  subject:/-C/ and from:/.an.k/ | notmuch_search_sanitize > OUTPUT
134 cat <<EOF > EXPECTED
135 thread:XXX   2009-11-17 [1/2] Jan Janak| Carl Worth; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
136 EOF
137 test_expect_equal_file EXPECTED OUTPUT
138
139 test_begin_subtest "regexp error reporting"
140 notmuch search 'from:/unbalanced[/' 1>OUTPUT 2>&1
141 cat <<EOF > EXPECTED
142 notmuch search: A Xapian exception occurred
143 A Xapian exception occurred parsing query: Invalid regular expression
144 Query string was: from:/unbalanced[/
145 EOF
146 test_expect_equal_file EXPECTED OUTPUT
147
148 test_begin_subtest "empty mid search"
149 notmuch search --output=messages mid:yoom > OUTPUT
150 cp /dev/null EXPECTED
151 test_expect_equal_file EXPECTED OUTPUT
152
153 test_begin_subtest "non-empty mid regex search"
154 notmuch search --output=messages mid:/yoom/ > OUTPUT
155 test_expect_equal_file cworth.msg-ids OUTPUT
156
157 test_begin_subtest "combine regexp mid and subject"
158 notmuch search  subject:/-C/ and mid:/y..m/ | notmuch_search_sanitize > OUTPUT
159 cat <<EOF > EXPECTED
160 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
161 EOF
162 test_expect_equal_file EXPECTED OUTPUT
163
164 test_begin_subtest "unanchored tag search"
165 notmuch search tag:signed or tag:inbox > EXPECTED
166 notmuch search tag:/i/ > OUTPUT
167 test_expect_equal_file EXPECTED OUTPUT
168
169 notmuch tag +testsi '*'
170 test_begin_subtest "anchored tag search"
171 notmuch search tag:signed > EXPECTED
172 notmuch search tag:/^si/ > OUTPUT
173 test_expect_equal_file EXPECTED OUTPUT
174
175 test_done