2 test_description='"notmuch new" in several variations'
3 . $(dirname "$0")/test-lib.sh || exit 1
5 test_begin_subtest "No new messages"
6 output=$(NOTMUCH_NEW --debug)
7 test_expect_equal "$output" "No new mail."
10 test_begin_subtest "Single new message"
12 output=$(NOTMUCH_NEW --debug)
13 test_expect_equal "$output" "Added 1 new message to the database."
15 test_begin_subtest "Single message (full-scan)"
17 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
18 test_expect_equal "$output" "Added 1 new message to the database."
20 test_begin_subtest "Multiple new messages"
23 output=$(NOTMUCH_NEW --debug)
24 test_expect_equal "$output" "Added 2 new messages to the database."
26 test_begin_subtest "Multiple new messages (full-scan)"
29 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
30 test_expect_equal "$output" "Added 2 new messages to the database."
32 test_begin_subtest "No new messages (non-empty DB)"
33 output=$(NOTMUCH_NEW --debug)
34 test_expect_equal "$output" "No new mail."
36 test_begin_subtest "No new messages (full-scan)"
37 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
38 test_expect_equal "$output" "No new mail."
40 test_begin_subtest "New directories"
41 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
42 mkdir "${MAIL_DIR}"/def
43 mkdir "${MAIL_DIR}"/ghi
44 generate_message [dir]=def
46 output=$(NOTMUCH_NEW --debug)
47 test_expect_equal "$output" "Added 1 new message to the database."
50 test_begin_subtest "Alternate inode order"
52 rm -rf "${MAIL_DIR}"/.notmuch
53 mv "${MAIL_DIR}"/ghi "${MAIL_DIR}"/abc
54 rm "${MAIL_DIR}"/def/*
55 generate_message [dir]=abc
57 output=$(NOTMUCH_NEW --debug)
58 test_expect_equal "$output" "Added 1 new message to the database."
61 test_begin_subtest "Message moved in"
62 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
64 tmp_msg_filename=tmp/"$gen_msg_filename"
65 mkdir -p "$(dirname "$tmp_msg_filename")"
66 mv "$gen_msg_filename" "$tmp_msg_filename"
67 notmuch new > /dev/null
68 mv "$tmp_msg_filename" "$gen_msg_filename"
69 output=$(NOTMUCH_NEW --debug)
70 test_expect_equal "$output" "Added 1 new message to the database."
73 test_begin_subtest "Renamed message"
76 notmuch new > /dev/null
77 mv "$gen_msg_filename" "${gen_msg_filename}"-renamed
78 output=$(NOTMUCH_NEW --debug)
79 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed file ${gen_msg_filename} for deletion from database
80 No new mail. Detected 1 file rename."
83 test_begin_subtest "Deleted message"
85 rm "${gen_msg_filename}"-renamed
86 output=$(NOTMUCH_NEW --debug)
87 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover file ${gen_msg_filename}-renamed for deletion from database
88 No new mail. Removed 1 message."
92 test_begin_subtest "Renamed directory"
94 generate_message [dir]=dir
95 generate_message [dir]=dir
96 generate_message [dir]=dir
98 notmuch new > /dev/null
100 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
102 output=$(NOTMUCH_NEW --debug --full-scan)
103 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed directory ${MAIL_DIR}/dir for deletion from database
104 No new mail. Detected 3 file renames."
107 test_begin_subtest "Deleted directory"
108 rm -rf "${MAIL_DIR}"/dir-renamed
110 output=$(NOTMUCH_NEW --debug --full-scan)
111 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed directory ${MAIL_DIR}/dir-renamed for deletion from database
112 No new mail. Removed 3 messages."
115 test_begin_subtest "New directory (at end of list)"
117 generate_message [dir]=zzz
118 generate_message [dir]=zzz
119 generate_message [dir]=zzz
121 output=$(NOTMUCH_NEW --debug)
122 test_expect_equal "$output" "Added 3 new messages to the database."
125 test_begin_subtest "Deleted directory (end of list)"
127 rm -rf "${MAIL_DIR}"/zzz
129 output=$(NOTMUCH_NEW --debug --full-scan)
130 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory ${MAIL_DIR}/zzz for deletion from database
131 No new mail. Removed 3 messages."
134 test_begin_subtest "New symlink to directory"
136 rm -rf "${MAIL_DIR}"/.notmuch
137 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
140 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
142 output=$(NOTMUCH_NEW --debug)
143 test_expect_equal "$output" "Added 1 new message to the database."
146 test_begin_subtest "New symlink to a file"
148 external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename")"
149 mkdir -p "$(dirname "$external_msg_filename")"
150 mv "$gen_msg_filename" "$external_msg_filename"
151 ln -s "$external_msg_filename" "$gen_msg_filename"
152 output=$(NOTMUCH_NEW --debug)
153 test_expect_equal "$output" "Added 1 new message to the database."
156 test_begin_subtest "Broken symlink aborts"
157 ln -s does-not-exist "${MAIL_DIR}/broken"
158 output=$(NOTMUCH_NEW --debug 2>&1)
159 test_expect_equal "$output" \
160 "Error reading file ${MAIL_DIR}/broken: No such file or directory
161 Note: A fatal error was encountered: Something went wrong trying to read or write a file
163 rm "${MAIL_DIR}/broken"
166 test_begin_subtest "New two-level directory"
168 generate_message [dir]=two/levels
169 generate_message [dir]=two/levels
170 generate_message [dir]=two/levels
172 output=$(NOTMUCH_NEW --debug)
173 test_expect_equal "$output" "Added 3 new messages to the database."
176 test_begin_subtest "Deleted two-level directory"
178 rm -rf "${MAIL_DIR}"/two
180 output=$(NOTMUCH_NEW --debug --full-scan)
181 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory ${MAIL_DIR}/two for deletion from database
182 No new mail. Removed 3 messages."
184 test_begin_subtest "One character directory at top level"
186 generate_message [dir]=A
187 generate_message [dir]=A/B
188 generate_message [dir]=A/B/C
190 output=$(NOTMUCH_NEW --debug)
191 test_expect_equal "$output" "Added 3 new messages to the database."
193 test_begin_subtest "Support single-message mbox"
194 cat > "${MAIL_DIR}"/mbox_file1 <<EOF
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 1
202 output=$(NOTMUCH_NEW --debug 2>&1)
203 test_expect_equal "$output" "Added 1 new message to the database."
205 # This test requires that notmuch new has been run at least once.
206 test_begin_subtest "Skip and report non-mail files"
208 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
209 touch "${MAIL_DIR}"/ignored_file
210 touch "${MAIL_DIR}"/.ignored_hidden_file
211 cat > "${MAIL_DIR}"/mbox_file <<EOF
212 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
213 From: Notmuch Test Suite <test_suite@notmuchmail.org>
214 To: Notmuch Test Suite <test_suite@notmuchmail.org>
215 Subject: Test mbox message 1
219 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
220 From: Notmuch Test Suite <test_suite@notmuchmail.org>
221 To: Notmuch Test Suite <test_suite@notmuchmail.org>
222 Subject: Test mbox message 2
226 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
227 test_expect_equal "$output" \
228 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
229 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
230 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
231 Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file
232 Added 1 new message to the database."
233 rm "${MAIL_DIR}"/mbox_file
235 test_begin_subtest "Ignore files and directories specified in new.ignore"
237 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
238 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
239 NOTMUCH_NEW --debug 2>&1 | sort > OUTPUT
241 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.git
242 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
243 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
244 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.git
245 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
246 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
247 Added 1 new message to the database.
249 test_expect_equal_file EXPECTED OUTPUT
251 test_begin_subtest "Ignore files and directories specified in new.ignore (full-scan)"
253 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
254 NOTMUCH_NEW --debug --full-scan 2>&1 | sort > OUTPUT
255 # reuse EXPECTED from previous test
256 test_expect_equal_file EXPECTED OUTPUT
258 test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"
259 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
260 notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.
261 mkdir -p "${MAIL_DIR}"/one/two/three/.git
262 touch "${MAIL_DIR}"/{one,one/two,one/two/three}/ignored_file
263 output=$(NOTMUCH_NEW --debug --full-scan 2>&1 | sort)
264 test_expect_equal "$output" \
265 "(D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.git
266 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
267 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
268 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
269 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
270 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
271 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
272 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.git
273 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
274 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
275 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
276 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
277 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
278 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
282 test_begin_subtest "Don't stop for ignored broken symlinks"
283 notmuch config set new.ignore .git ignored_file .ignored_hidden_file broken_link
284 ln -s i_do_not_exist "${MAIL_DIR}"/broken_link
285 output=$(NOTMUCH_NEW 2>&1)
286 test_expect_equal "$output" "No new mail."
288 test_begin_subtest "Ignore files and directories specified in new.ignore (regexp)"
289 notmuch config set new.ignore ".git" "/^bro.*ink\$/" "/ignored.*file/"
290 output=$(NOTMUCH_NEW --debug --full-scan 2>&1 | sort)
291 test_expect_equal "$output" \
292 "(D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.git
293 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
294 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/broken_link
295 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
296 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
297 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
298 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
299 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
300 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.git
301 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
302 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/broken_link
303 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
304 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
305 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
306 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
307 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
310 test_begin_subtest "Quiet: No new mail."
311 output=$(NOTMUCH_NEW --quiet)
312 test_expect_equal "$output" ""
314 test_begin_subtest "Quiet: new, removed and renamed messages."
318 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
320 mkdir "${MAIL_DIR}"/moved_messages
321 notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0 -I {} mv {} "${MAIL_DIR}"/moved_messages
322 output=$(NOTMUCH_NEW --quiet)
323 test_expect_equal "$output" ""
325 OLDCONFIG=$(notmuch config get new.tags)
327 test_begin_subtest "Empty tags in new.tags are forbidden"
328 notmuch config set new.tags "foo;;bar"
329 output=$(NOTMUCH_NEW --debug 2>&1)
330 test_expect_equal "$output" "Error: tag '' in new.tags: empty tag forbidden"
332 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
333 notmuch config set new.tags "-foo;bar"
334 output=$(NOTMUCH_NEW --debug 2>&1)
335 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
337 test_begin_subtest "Invalid tags set exit code"
338 test_expect_code 1 "NOTMUCH_NEW --debug 2>&1"
340 notmuch config set new.tags $OLDCONFIG
343 test_begin_subtest "Xapian exception: read only files"
344 chmod u-w ${MAIL_DIR}/.notmuch/xapian/*.${db_ending}
345 output=$(NOTMUCH_NEW --debug 2>&1 | sed 's/: .*$//' )
346 chmod u+w ${MAIL_DIR}/.notmuch/xapian/*.${db_ending}
347 test_expect_equal "$output" "A Xapian exception occurred opening database"
350 test_begin_subtest "Handle files vanishing between scandir and add_file"
352 # A file for scandir to find. It won't get indexed, so can be empty.
353 touch ${MAIL_DIR}/vanish
355 # Breakpoint to remove the file before indexing
356 cat <<EOF > notmuch-new-vanish.gdb
357 set breakpoint pending on
358 set logging file notmuch-new-vanish-gdb.log
360 break notmuch_database_index_file
362 shell rm -f ${MAIL_DIR}/vanish
368 ${TEST_GDB} --batch-silent --return-child-result -x notmuch-new-vanish.gdb \
369 --args notmuch new 2>OUTPUT 1>/dev/null
370 echo "exit status: $?" >> OUTPUT
372 # Clean up the file in case gdb isn't available.
373 rm -f ${MAIL_DIR}/vanish
376 Unexpected error with file ${MAIL_DIR}/vanish
377 add_file: Something went wrong trying to read or write a file
378 Error opening ${MAIL_DIR}/vanish: No such file or directory
381 test_expect_equal_file EXPECTED OUTPUT
383 add_email_corpus broken
384 test_begin_subtest "reference loop does not crash"
385 test_expect_code 0 "notmuch show --format=json id:mid-loop-12@example.org id:mid-loop-21@example.org > OUTPUT"
387 test_begin_subtest "reference loop ordered by date"
388 threadid=$(notmuch search --output=threads id:mid-loop-12@example.org)
389 notmuch show --format=mbox $threadid | grep '^Date' > OUTPUT
391 Date: Thu, 16 Jun 2016 22:14:41 -0400
392 Date: Fri, 17 Jun 2016 22:14:41 -0400
394 test_expect_equal_file EXPECTED OUTPUT