]> git.notmuchmail.org Git - notmuch/blob - test/T050-new.sh
66ea10fee3f064821a3328702f0908a25eeee6e3
[notmuch] / test / T050-new.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch new" in several variations'
3 . ./test-lib.sh
4
5 test_begin_subtest "No new messages"
6 output=$(NOTMUCH_NEW)
7 test_expect_equal "$output" "No new mail."
8
9
10 test_begin_subtest "Single new message"
11 generate_message
12 output=$(NOTMUCH_NEW)
13 test_expect_equal "$output" "Added 1 new message to the database."
14
15
16 test_begin_subtest "Multiple new messages"
17 generate_message
18 generate_message
19 output=$(NOTMUCH_NEW)
20 test_expect_equal "$output" "Added 2 new messages to the database."
21
22
23 test_begin_subtest "No new messages (non-empty DB)"
24 output=$(NOTMUCH_NEW)
25 test_expect_equal "$output" "No new mail."
26
27
28 test_begin_subtest "New directories"
29 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
30 mkdir "${MAIL_DIR}"/def
31 mkdir "${MAIL_DIR}"/ghi
32 generate_message [dir]=def
33
34 output=$(NOTMUCH_NEW)
35 test_expect_equal "$output" "Added 1 new message to the database."
36
37
38 test_begin_subtest "Alternate inode order"
39
40 rm -rf "${MAIL_DIR}"/.notmuch
41 mv "${MAIL_DIR}"/ghi "${MAIL_DIR}"/abc
42 rm "${MAIL_DIR}"/def/*
43 generate_message [dir]=abc
44
45 output=$(NOTMUCH_NEW)
46 test_expect_equal "$output" "Added 1 new message to the database."
47
48
49 test_begin_subtest "Message moved in"
50 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
51 generate_message
52 tmp_msg_filename=tmp/"$gen_msg_filename"
53 mkdir -p "$(dirname "$tmp_msg_filename")"
54 mv "$gen_msg_filename" "$tmp_msg_filename"
55 notmuch new > /dev/null
56 mv "$tmp_msg_filename" "$gen_msg_filename"
57 output=$(NOTMUCH_NEW)
58 test_expect_equal "$output" "Added 1 new message to the database."
59
60
61 test_begin_subtest "Renamed message"
62
63 generate_message
64 notmuch new > /dev/null
65 mv "$gen_msg_filename" "${gen_msg_filename}"-renamed
66 output=$(NOTMUCH_NEW --debug)
67 test_expect_equal "$output" "(D) add_files_recursive, pass 2: queuing passed file ${gen_msg_filename} for deletion from database
68 No new mail. Detected 1 file rename."
69
70
71 test_begin_subtest "Deleted message"
72
73 rm "${gen_msg_filename}"-renamed
74 output=$(NOTMUCH_NEW --debug)
75 test_expect_equal "$output" "(D) add_files_recursive, pass 3: queuing leftover file ${gen_msg_filename}-renamed for deletion from database
76 No new mail. Removed 1 message."
77
78
79
80 test_begin_subtest "Renamed directory"
81
82 generate_message [dir]=dir
83 generate_message [dir]=dir
84 generate_message [dir]=dir
85
86 notmuch new > /dev/null
87
88 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
89
90 output=$(NOTMUCH_NEW)
91 test_expect_equal "$output" "No new mail. Detected 3 file renames."
92
93
94 test_begin_subtest "Deleted directory"
95
96 rm -rf "${MAIL_DIR}"/dir-renamed
97
98 output=$(NOTMUCH_NEW)
99 test_expect_equal "$output" "No new mail. Removed 3 messages."
100
101
102 test_begin_subtest "New directory (at end of list)"
103
104 generate_message [dir]=zzz
105 generate_message [dir]=zzz
106 generate_message [dir]=zzz
107
108 output=$(NOTMUCH_NEW)
109 test_expect_equal "$output" "Added 3 new messages to the database."
110
111
112 test_begin_subtest "Deleted directory (end of list)"
113
114 rm -rf "${MAIL_DIR}"/zzz
115
116 output=$(NOTMUCH_NEW)
117 test_expect_equal "$output" "No new mail. Removed 3 messages."
118
119
120 test_begin_subtest "New symlink to directory"
121
122 rm -rf "${MAIL_DIR}"/.notmuch
123 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
124
125 mkdir "${MAIL_DIR}"
126 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
127
128 output=$(NOTMUCH_NEW)
129 test_expect_equal "$output" "Added 1 new message to the database."
130
131
132 test_begin_subtest "New symlink to a file"
133 generate_message
134 external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename")"
135 mkdir -p "$(dirname "$external_msg_filename")"
136 mv "$gen_msg_filename" "$external_msg_filename"
137 ln -s "$external_msg_filename" "$gen_msg_filename"
138 output=$(NOTMUCH_NEW)
139 test_expect_equal "$output" "Added 1 new message to the database."
140
141
142 test_begin_subtest "Broken symlink aborts"
143 ln -s does-not-exist "${MAIL_DIR}/broken"
144 output=$(NOTMUCH_NEW 2>&1)
145 test_expect_equal "$output" \
146 "Error reading file ${MAIL_DIR}/broken: No such file or directory
147 Note: A fatal error was encountered: Something went wrong trying to read or write a file
148 No new mail."
149 rm "${MAIL_DIR}/broken"
150
151
152 test_begin_subtest "New two-level directory"
153
154 generate_message [dir]=two/levels
155 generate_message [dir]=two/levels
156 generate_message [dir]=two/levels
157
158 output=$(NOTMUCH_NEW)
159 test_expect_equal "$output" "Added 3 new messages to the database."
160
161
162 test_begin_subtest "Deleted two-level directory"
163
164 rm -rf "${MAIL_DIR}"/two
165
166 output=$(NOTMUCH_NEW)
167 test_expect_equal "$output" "No new mail. Removed 3 messages."
168
169 test_begin_subtest "Support single-message mbox"
170 cat > "${MAIL_DIR}"/mbox_file1 <<EOF
171 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
172 From: Notmuch Test Suite <test_suite@notmuchmail.org>
173 To: Notmuch Test Suite <test_suite@notmuchmail.org>
174 Subject: Test mbox message 1
175
176 Body.
177 EOF
178 output=$(NOTMUCH_NEW 2>&1)
179 test_expect_equal "$output" "Added 1 new message to the database."
180
181 # This test requires that notmuch new has been run at least once.
182 test_begin_subtest "Skip and report non-mail files"
183 generate_message
184 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
185 touch "${MAIL_DIR}"/ignored_file
186 touch "${MAIL_DIR}"/.ignored_hidden_file
187 cat > "${MAIL_DIR}"/mbox_file <<EOF
188 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
189 From: Notmuch Test Suite <test_suite@notmuchmail.org>
190 To: Notmuch Test Suite <test_suite@notmuchmail.org>
191 Subject: Test mbox message 1
192
193 Body.
194
195 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
196 From: Notmuch Test Suite <test_suite@notmuchmail.org>
197 To: Notmuch Test Suite <test_suite@notmuchmail.org>
198 Subject: Test mbox message 2
199
200 Body 2.
201 EOF
202 output=$(NOTMUCH_NEW 2>&1)
203 test_expect_equal "$output" \
204 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
205 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
206 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
207 Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file
208 Added 1 new message to the database."
209 rm "${MAIL_DIR}"/mbox_file
210
211 test_begin_subtest "Ignore files and directories specified in new.ignore"
212 generate_message
213 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
214 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
215 output=$(NOTMUCH_NEW 2>&1)
216 test_expect_equal "$output" "Added 1 new message to the database."
217
218 test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"
219 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
220 notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.
221 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
222 touch "${MAIL_DIR}"      # likewise for MAIL_DIR
223 mkdir -p "${MAIL_DIR}"/one/two/three/.git
224 touch "${MAIL_DIR}"/{one,one/two,one/two/three}/ignored_file
225 output=$(NOTMUCH_NEW --debug 2>&1 | sort)
226 test_expect_equal "$output" \
227 "(D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.git
228 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
229 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
230 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
231 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
232 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
233 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
234 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.git
235 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
236 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
237 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
238 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
239 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
240 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
241 No new mail."
242
243
244 test_begin_subtest "Don't stop for ignored broken symlinks"
245 notmuch config set new.ignore .git ignored_file .ignored_hidden_file broken_link
246 ln -s i_do_not_exist "${MAIL_DIR}"/broken_link
247 output=$(NOTMUCH_NEW 2>&1)
248 test_expect_equal "$output" "No new mail."
249
250 test_begin_subtest "Quiet: No new mail."
251 output=$(NOTMUCH_NEW --quiet)
252 test_expect_equal "$output" ""
253
254 test_begin_subtest "Quiet: new, removed and renamed messages."
255 # new
256 generate_message
257 # deleted
258 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
259 # moved
260 mkdir "${MAIL_DIR}"/moved_messages
261 notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0 -I {} mv {} "${MAIL_DIR}"/moved_messages
262 output=$(NOTMUCH_NEW --quiet)
263 test_expect_equal "$output" ""
264
265 OLDCONFIG=$(notmuch config get new.tags)
266
267 test_begin_subtest "Empty tags in new.tags are forbidden"
268 notmuch config set new.tags "foo;;bar"
269 output=$(NOTMUCH_NEW 2>&1)
270 test_expect_equal "$output" "Error: tag '' in new.tags: empty tag forbidden"
271
272 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
273 notmuch config set new.tags "-foo;bar"
274 output=$(NOTMUCH_NEW 2>&1)
275 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
276
277 test_expect_code 1 "Invalid tags set exit code" \
278     "NOTMUCH_NEW 2>&1"
279
280 notmuch config set new.tags $OLDCONFIG
281
282
283 test_begin_subtest "Xapian exception: read only files"
284 chmod u-w  ${MAIL_DIR}/.notmuch/xapian/*.DB
285 output=$(NOTMUCH_NEW 2>&1 | sed 's/: .*$//' )
286 chmod u+w  ${MAIL_DIR}/.notmuch/xapian/*.DB
287 test_expect_equal "$output" "A Xapian exception occurred opening database"
288
289 test_done