]> 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 . ./test-lib.sh || exit 1
4
5 add_email_corpus
6
7
8 if [ $NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR -eq 0 ]; then
9     test_done
10 fi
11
12 notmuch search --output=messages from:cworth > cworth.msg-ids
13
14 # these headers will generate no document terms
15 add_message '[from]="-" [subject]="empty from"'
16 add_message '[subject]="-"'
17
18 test_begin_subtest "null from: search"
19 notmuch search 'from:""' | notmuch_search_sanitize > OUTPUT
20 cat <<EOF > EXPECTED
21 thread:XXX   2001-01-05 [1/1] -; empty from (inbox unread)
22 EOF
23 test_expect_equal_file EXPECTED OUTPUT
24
25 test_begin_subtest "null subject: search"
26 notmuch search 'subject:""' | notmuch_search_sanitize > OUTPUT
27 cat <<EOF > EXPECTED
28 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; - (inbox unread)
29 EOF
30 test_expect_equal_file EXPECTED OUTPUT
31
32 test_begin_subtest "xapian wildcard search for from:"
33 notmuch search --output=messages 'from:cwo*' > OUTPUT
34 test_expect_equal_file cworth.msg-ids OUTPUT
35
36 test_begin_subtest "xapian wildcard search for subject:"
37 test_expect_equal $(notmuch count 'subject:count*') 1
38
39 test_begin_subtest "regexp from search, case sensitive"
40 notmuch search --output=messages from:/carl/ > OUTPUT
41 test_expect_equal_file /dev/null OUTPUT
42
43 test_begin_subtest "empty regexp or query"
44 notmuch search --output=messages from:/carl/ or from:/cworth/ > OUTPUT
45 test_expect_equal_file cworth.msg-ids OUTPUT
46
47 test_begin_subtest "non-empty regexp and query"
48 notmuch search  from:/cworth@cworth.org/ and subject:patch | notmuch_search_sanitize > OUTPUT
49 cat <<EOF > EXPECTED
50 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)
51 thread:XXX   2009-11-18 [1/2] Carl Worth| Ingmar Vanhassel; [notmuch] [PATCH] Typsos (inbox unread)
52 thread:XXX   2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
53 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)
54 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)
55 EOF
56 test_expect_equal_file EXPECTED OUTPUT
57
58 test_begin_subtest "regexp from search, duplicate term search"
59 notmuch search --output=messages from:/cworth/ > OUTPUT
60 test_expect_equal_file cworth.msg-ids OUTPUT
61
62 test_begin_subtest "long enough regexp matches only desired senders"
63 notmuch search --output=messages 'from:"/C.* Wo/"' > OUTPUT
64 test_expect_equal_file cworth.msg-ids OUTPUT
65
66 test_begin_subtest "shorter regexp matches one more sender"
67 notmuch search --output=messages 'from:"/C.* W/"' > OUTPUT
68 { echo id:1258544095-16616-1-git-send-email-chris@chris-wilson.co.uk; cat cworth.msg-ids; } > EXPECTED
69 test_expect_equal_file EXPECTED OUTPUT
70
71 test_begin_subtest "regexp subject search, non-ASCII"
72 notmuch search --output=messages subject:/accentuĂ©/ > OUTPUT
73 echo id:877h1wv7mg.fsf@inf-8657.int-evry.fr > EXPECTED
74 test_expect_equal_file EXPECTED OUTPUT
75
76 test_begin_subtest "regexp subject search, punctuation"
77 notmuch search subject:/\'X\'/ | notmuch_search_sanitize > OUTPUT
78 cat <<EOF > EXPECTED
79 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)
80 EOF
81 test_expect_equal_file EXPECTED OUTPUT
82
83 test_begin_subtest "regexp subject search, no punctuation"
84 notmuch search  subject:/X/ | notmuch_search_sanitize > OUTPUT
85 cat <<EOF > EXPECTED
86 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)
87 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
88 EOF
89 test_expect_equal_file EXPECTED OUTPUT
90
91 test_begin_subtest "combine regexp from and subject"
92 notmuch search  subject:/-C/ and from:/.an.k/ | notmuch_search_sanitize > OUTPUT
93 cat <<EOF > EXPECTED
94 thread:XXX   2009-11-17 [1/2] Jan Janak| Carl Worth; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
95 EOF
96 test_expect_equal_file EXPECTED OUTPUT
97
98 test_begin_subtest "regexp error reporting"
99 notmuch search 'from:/unbalanced[/' 1>OUTPUT 2>&1
100 cat <<EOF > EXPECTED
101 notmuch search: A Xapian exception occurred
102 A Xapian exception occurred parsing query: Invalid regular expression
103 Query string was: from:/unbalanced[/
104 EOF
105 test_expect_equal_file EXPECTED OUTPUT
106
107 test_done