]> git.cworth.org Git - notmuch/blob - test/T100-search-by-folder.sh
lib: drop trailing slash for path and folder searches (infix)
[notmuch] / test / T100-search-by-folder.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch search" by folder: and path: (with variations)'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
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"
10
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"'
14
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)"
20
21 test_begin_subtest "Top level folder"
22 output=$(notmuch search folder:'""' | notmuch_search_sanitize)
23 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Top level (inbox unread)"
24
25 test_begin_subtest "Two-word path to narrow results to one"
26 output=$(notmuch search folder:bad/news | notmuch_search_sanitize)
27 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)"
28
29 test_begin_subtest "Folder search with --output=files"
30 output=$(notmuch search --output=files folder:bad/news | notmuch_search_files_sanitize)
31 test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX
32 MAIL_DIR/duplicate/bad/news/msg-XXX"
33
34 test_begin_subtest "Folder search with --output=files (trailing /)"
35 output=$(notmuch search --output=files folder:bad/news/ | notmuch_search_files_sanitize)
36 test_expect_equal "$output" "MAIL_DIR/bad/news/msg-XXX
37 MAIL_DIR/duplicate/bad/news/msg-XXX"
38
39 test_begin_subtest "After removing duplicate instance of matching path"
40 rm -r "${MAIL_DIR}/bad/news"
41 notmuch new
42 output=$(notmuch search folder:bad/news | notmuch_search_sanitize)
43 test_expect_equal "$output" ""
44
45 test_begin_subtest "Folder search with --output=files part #2"
46 output=$(notmuch search --output=files folder:duplicate/bad/news | notmuch_search_files_sanitize)
47 test_expect_equal "$output" "MAIL_DIR/duplicate/bad/news/msg-XXX"
48
49 test_begin_subtest "After removing duplicate instance of matching path part #2"
50 output=$(notmuch search folder:duplicate/bad/news | notmuch_search_sanitize)
51 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Bears (inbox unread)"
52
53 test_begin_subtest "After rename, old path returns nothing"
54 mv "${MAIL_DIR}/duplicate/bad/news" "${MAIL_DIR}/duplicate/bad/olds"
55 notmuch new
56 output=$(notmuch search folder:duplicate/bad/news | notmuch_search_sanitize)
57 test_expect_equal "$output" ""
58
59 test_begin_subtest "After rename, new path returns result"
60 output=$(notmuch search folder:duplicate/bad/olds | notmuch_search_sanitize)
61 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Bears (inbox unread)"
62
63 # folder: and path: searches with full corpus
64 add_email_corpus
65
66 # add some more dupes
67 cp $MAIL_DIR/foo/new/03:2, $MAIL_DIR/new
68 cp $MAIL_DIR/bar/baz/05:2, $MAIL_DIR/foo
69 notmuch new >/dev/null
70
71 test_begin_subtest "folder: search"
72 output=$(notmuch search --output=files folder:foo | notmuch_search_files_sanitize | sort)
73 # bar/baz/05:2, is a duplicate of foo/05:2,
74 # new/03:2, is a duplicate of foo/new/03:2,
75 test_expect_equal "$output" "MAIL_DIR/bar/baz/05:2,
76 MAIL_DIR/foo/05:2,
77 MAIL_DIR/foo/06:2,
78 MAIL_DIR/foo/cur/07:2,
79 MAIL_DIR/foo/cur/08:2,
80 MAIL_DIR/foo/new/03:2,
81 MAIL_DIR/foo/new/09:2,
82 MAIL_DIR/foo/new/10:2,
83 MAIL_DIR/new/03:2,"
84
85 test_begin_subtest "top level folder: search"
86 output=$(notmuch search --output=files folder:'""' | notmuch_search_files_sanitize | sort)
87 # bar/18:2, is a duplicate of cur/51:2,
88 # foo/new/03:2, is a duplicate of new/03:2,
89 test_expect_equal "$output" "MAIL_DIR/01:2,
90 MAIL_DIR/02:2,
91 MAIL_DIR/bar/18:2,
92 MAIL_DIR/cur/29:2,
93 MAIL_DIR/cur/30:2,
94 MAIL_DIR/cur/31:2,
95 MAIL_DIR/cur/32:2,
96 MAIL_DIR/cur/33:2,
97 MAIL_DIR/cur/34:2,
98 MAIL_DIR/cur/35:2,
99 MAIL_DIR/cur/36:2,
100 MAIL_DIR/cur/37:2,
101 MAIL_DIR/cur/38:2,
102 MAIL_DIR/cur/39:2,
103 MAIL_DIR/cur/40:2,
104 MAIL_DIR/cur/41:2,
105 MAIL_DIR/cur/42:2,
106 MAIL_DIR/cur/43:2,
107 MAIL_DIR/cur/44:2,
108 MAIL_DIR/cur/45:2,
109 MAIL_DIR/cur/46:2,
110 MAIL_DIR/cur/47:2,
111 MAIL_DIR/cur/48:2,
112 MAIL_DIR/cur/49:2,
113 MAIL_DIR/cur/50:2,
114 MAIL_DIR/cur/51:2,
115 MAIL_DIR/cur/52:2,
116 MAIL_DIR/cur/53:2,
117 MAIL_DIR/foo/new/03:2,
118 MAIL_DIR/new/03:2,
119 MAIL_DIR/new/04:2,"
120
121 test_begin_subtest "path: search"
122 output=$(notmuch search --output=files path:"bar" | notmuch_search_files_sanitize | sort)
123 # cur/51:2, is a duplicate of bar/18:2,
124 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
125 MAIL_DIR/bar/18:2,
126 MAIL_DIR/cur/51:2,"
127
128 test_begin_subtest "path: search (trailing /)"
129 output=$(notmuch search --output=files path:"bar/" | notmuch_search_files_sanitize | sort)
130 # cur/51:2, is a duplicate of bar/18:2,
131 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
132 MAIL_DIR/bar/18:2,
133 MAIL_DIR/cur/51:2,"
134
135 test_begin_subtest "top level path: search"
136 output=$(notmuch search --output=files path:'""' | notmuch_search_files_sanitize | sort)
137 test_expect_equal "$output" "MAIL_DIR/01:2,
138 MAIL_DIR/02:2,"
139
140 test_begin_subtest "recursive path: search"
141 output=$(notmuch search --output=files path:"bar/**" | notmuch_search_files_sanitize | sort)
142 # cur/51:2, is a duplicate of bar/18:2,
143 # foo/05:2, is a duplicate of bar/baz/05:2,
144 test_expect_equal "$output" "MAIL_DIR/bar/17:2,
145 MAIL_DIR/bar/18:2,
146 MAIL_DIR/bar/baz/05:2,
147 MAIL_DIR/bar/baz/23:2,
148 MAIL_DIR/bar/baz/24:2,
149 MAIL_DIR/bar/baz/cur/25:2,
150 MAIL_DIR/bar/baz/cur/26:2,
151 MAIL_DIR/bar/baz/new/27:2,
152 MAIL_DIR/bar/baz/new/28:2,
153 MAIL_DIR/bar/cur/19:2,
154 MAIL_DIR/bar/cur/20:2,
155 MAIL_DIR/bar/new/21:2,
156 MAIL_DIR/bar/new/22:2,
157 MAIL_DIR/cur/51:2,
158 MAIL_DIR/foo/05:2,"
159
160 test_done