2 test_description='"notmuch search" by folder: and path: (with variations)'
3 . $(dirname "$0")/test-lib.sh || exit 1
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"
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"'
15 test_begin_subtest "Single-world folder: specification (multiple results)"
16 output=$(notmuch search folder:bad folder:bad/news folder:things/bad | notmuch_search_sanitize)
17 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)
18 thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)
19 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)"
21 test_begin_subtest "search by path: specification (multiple)"
22 output=$(notmuch search path:bad path:bad/news path:things/bad | notmuch_search_sanitize)
23 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)
24 thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)
25 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)"
27 test_begin_subtest "Top level folder"
28 output=$(notmuch search folder:'""' | notmuch_search_sanitize)
29 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Top level (inbox unread)"
31 test_begin_subtest "Two-word path to narrow results to one"
32 output=$(notmuch search folder:bad/news | notmuch_search_sanitize)
33 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)"
35 test_begin_subtest "Folder search with --output=files"
36 output=$(notmuch search --output=files folder:bad/news | notmuch_search_files_sanitize)
37 test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX
38 MAIL_DIR/duplicate/bad/news/msg-XXX"
40 test_begin_subtest "Folder search with --output=files (trailing /)"
41 output=$(notmuch search --output=files folder:bad/news/ | notmuch_search_files_sanitize)
42 test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX
43 MAIL_DIR/duplicate/bad/news/msg-XXX"
45 test_begin_subtest "After removing duplicate instance of matching path"
46 rm -r "${MAIL_DIR}/bad/news"
48 output=$(notmuch search folder:bad/news | notmuch_search_sanitize)
49 test_expect_equal "$output" ""
51 test_begin_subtest "Folder search with --output=files part #2"
52 output=$(notmuch search --output=files folder:duplicate/bad/news | notmuch_search_files_sanitize)
53 test_expect_equal "$output" "MAIL_DIR/duplicate/bad/news/msg-XXX"
55 test_begin_subtest "After removing duplicate instance of matching path part #2"
56 output=$(notmuch search folder:duplicate/bad/news | notmuch_search_sanitize)
57 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Bears (inbox unread)"
59 test_begin_subtest "After rename, old path returns nothing"
60 mv "${MAIL_DIR}/duplicate/bad/news" "${MAIL_DIR}/duplicate/bad/olds"
62 output=$(notmuch search folder:duplicate/bad/news | notmuch_search_sanitize)
63 test_expect_equal "$output" ""
65 test_begin_subtest "After rename, new path returns result"
66 output=$(notmuch search folder:duplicate/bad/olds | notmuch_search_sanitize)
67 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Bears (inbox unread)"
69 # folder: and path: searches with full corpus
73 cp $MAIL_DIR/foo/new/03:2, $MAIL_DIR/new
74 cp $MAIL_DIR/bar/baz/05:2, $MAIL_DIR/foo
75 notmuch new >/dev/null
77 test_begin_subtest "folder: search"
78 output=$(notmuch search --output=files folder:foo | notmuch_search_files_sanitize | sort)
79 # bar/baz/05:2, is a duplicate of foo/05:2,
80 # new/03:2, is a duplicate of foo/new/03:2,
81 test_expect_equal "$output" "MAIL_DIR/bar/baz/05:2,
84 MAIL_DIR/foo/cur/07:2,
85 MAIL_DIR/foo/cur/08:2,
86 MAIL_DIR/foo/new/03:2,
87 MAIL_DIR/foo/new/09:2,
88 MAIL_DIR/foo/new/10:2,
91 test_begin_subtest "top level folder: search"
92 output=$(notmuch search --output=files folder:'""' | notmuch_search_files_sanitize | sort)
93 # bar/18:2, is a duplicate of cur/51:2,
94 # foo/new/03:2, is a duplicate of new/03:2,
95 test_expect_equal "$output" "MAIL_DIR/01:2,
123 MAIL_DIR/foo/new/03:2,
127 test_begin_subtest "path: search"
128 output=$(notmuch search --output=files path:"bar" | notmuch_search_files_sanitize | sort)
129 # cur/51:2, is a duplicate of bar/18:2,
130 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
134 test_begin_subtest "path: search (trailing /)"
135 output=$(notmuch search --output=files path:"bar/" | notmuch_search_files_sanitize | sort)
136 # cur/51:2, is a duplicate of bar/18:2,
137 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
141 test_begin_subtest "top level path: search"
142 output=$(notmuch search --output=files path:'""' | notmuch_search_files_sanitize | sort)
143 test_expect_equal "$output" "MAIL_DIR/01:2,
146 test_begin_subtest "recursive path: search"
147 output=$(notmuch search --output=files path:"bar/**" | notmuch_search_files_sanitize | sort)
148 # cur/51:2, is a duplicate of bar/18:2,
149 # foo/05:2, is a duplicate of bar/baz/05:2,
150 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
152 MAIL_DIR/bar/baz/05:2,
153 MAIL_DIR/bar/baz/23:2,
154 MAIL_DIR/bar/baz/24:2,
155 MAIL_DIR/bar/baz/cur/25:2,
156 MAIL_DIR/bar/baz/cur/26:2,
157 MAIL_DIR/bar/baz/new/27:2,
158 MAIL_DIR/bar/baz/new/28:2,
159 MAIL_DIR/bar/cur/19:2,
160 MAIL_DIR/bar/cur/20:2,
161 MAIL_DIR/bar/new/21:2,
162 MAIL_DIR/bar/new/22:2,