]> git.notmuchmail.org Git - notmuch/blob - test/t0002-search.sh
test: Fix test suite to integrate with our non-recursive Makefile system.
[notmuch] / test / t0002-search.sh
1 #!/bin/bash
2 test_description="\"notmuch search\" in several variations"
3 . ./test-lib.sh
4
5 test_expect_success "Search body" '
6 add_message "[subject]=\"body search\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" [body]=bodysearchtest &&
7 output=$($NOTMUCH search bodysearchtest | notmuch_search_sanitize) &&
8 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
9
10 '
11 test_expect_success "Search by from:" '
12 add_message "[subject]=\"search by from\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" [from]=searchbyfrom &&
13 output=$($NOTMUCH search from:searchbyfrom | notmuch_search_sanitize) &&
14 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
15
16 '
17 test_expect_success "Search by to:" '
18 add_message "[subject]=\"search by to\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" [to]=searchbyto &&
19 output=$($NOTMUCH search to:searchbyto | notmuch_search_sanitize) &&
20 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
21
22 '
23 test_expect_success "Search by subject:" '
24 add_message [subject]=subjectsearchtest "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" &&
25 output=$($NOTMUCH search subject:subjectsearchtest | notmuch_search_sanitize) &&
26 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
27
28 '
29 test_expect_success "Search by id:" '
30 add_message "[subject]=\"search by id\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" &&
31 output=$($NOTMUCH search id:${gen_msg_id} | notmuch_search_sanitize) &&
32 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
33
34 '
35 test_expect_success "Search by tag:" '
36 add_message "[subject]=\"search by tag\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" &&
37 $NOTMUCH tag +searchbytag id:${gen_msg_id} &&
38 output=$($NOTMUCH search tag:searchbytag | notmuch_search_sanitize) &&
39 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
40
41 '
42 test_expect_success "Search by thread:" '
43 add_message "[subject]=\"search by thread\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" &&
44 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e "s/thread:\([a-f0-9]*\).*/\1/") &&
45 output=$($NOTMUCH search thread:${thread_id} | notmuch_search_sanitize) &&
46 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
47
48 '
49 test_expect_success "Search body (phrase)" '
50 add_message "[subject]=\"body search (phrase)\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"body search (phrase)\"" &&
51 add_message "[subject]=\"negative result\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"This phrase should not match the body search\"" &&
52 output=$($NOTMUCH search "\"body search (phrase)\"" | notmuch_search_sanitize) &&
53 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
54
55 '
56 test_expect_success "Search by from: (address)" '
57 add_message "[subject]=\"search by from (address)\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" [from]=searchbyfrom@example.com &&
58 output=$($NOTMUCH search from:searchbyfrom@example.com | notmuch_search_sanitize) &&
59 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
60
61 '
62 test_expect_success "Search by from: (name)" '
63 add_message "[subject]=\"search by from (name)\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[from]=\"Search By From Name <test@example.com>\"" &&
64 output=$($NOTMUCH search from:"Search By From Name" | notmuch_search_sanitize) &&
65 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
66
67 '
68 test_expect_success "Search by to: (address)" '
69 add_message "[subject]=\"search by to (address)\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" [to]=searchbyto@example.com &&
70 output=$($NOTMUCH search to:searchbyto@example.com | notmuch_search_sanitize) &&
71 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
72
73 '
74 test_expect_success "Search by to: (name)" '
75 add_message "[subject]=\"search by to (name)\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[to]=\"Search By To Name <test@example.com>\"" &&
76 output=$($NOTMUCH search to:"Search By To Name" | notmuch_search_sanitize) &&
77 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
78
79 '
80 test_expect_success "Search by subject: (phrase)" '
81 add_message "[subject]=\"subject search test (phrase)\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" &&
82 add_message "[subject]=\"this phrase should not match the subject search test\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" &&
83 output=$($NOTMUCH search "subject:\"subject search test (phrase)\"" | notmuch_search_sanitize) &&
84 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
85
86 '
87 test_expect_success "Search for all messages (\"*\"):" '
88 output=$($NOTMUCH search "*" | notmuch_search_sanitize) &&
89 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)
90 thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)
91 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
92 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
93 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)
94 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)
95 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)
96 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)
97 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; negative result (inbox unread)
98 thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)
99 thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)
100 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
101 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
102 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
103 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
104
105 '
106 test_expect_success "Search body (utf-8):" '
107 add_message "[subject]=\"utf8-message-body-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"message body utf8: bödý\"" &&
108 output=$($NOTMUCH search "bödý" | notmuch_search_sanitize) &&
109 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
110 '
111 test_done