2 test_description='"notmuch new" in several variations'
5 test_begin_subtest "No new messages"
7 test_expect_equal "$output" "No new mail."
10 test_begin_subtest "Single new message"
13 test_expect_equal "$output" "Added 1 new message to the database."
16 test_begin_subtest "Multiple new messages"
20 test_expect_equal "$output" "Added 2 new messages to the database."
23 test_begin_subtest "No new messages (non-empty DB)"
25 test_expect_equal "$output" "No new mail."
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
35 test_expect_equal "$output" "Added 1 new message to the database."
38 test_begin_subtest "Alternate inode order"
40 rm -rf "${MAIL_DIR}"/.notmuch
41 mv "${MAIL_DIR}"/ghi "${MAIL_DIR}"/abc
42 rm "${MAIL_DIR}"/def/*
43 generate_message [dir]=abc
46 test_expect_equal "$output" "Added 1 new message to the database."
49 test_begin_subtest "Message moved in"
50 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
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"
58 test_expect_equal "$output" "Added 1 new message to the database."
61 test_begin_subtest "Renamed message"
64 notmuch new > /dev/null
65 mv "$gen_msg_filename" "${gen_msg_filename}"-renamed
67 test_expect_equal "$output" "No new mail. Detected 1 file rename."
70 test_begin_subtest "Deleted message"
72 rm "${gen_msg_filename}"-renamed
74 test_expect_equal "$output" "No new mail. Removed 1 message."
77 test_begin_subtest "Renamed directory"
79 generate_message [dir]=dir
80 generate_message [dir]=dir
81 generate_message [dir]=dir
83 notmuch new > /dev/null
85 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
88 test_expect_equal "$output" "No new mail. Detected 3 file renames."
91 test_begin_subtest "Deleted directory"
93 rm -rf "${MAIL_DIR}"/dir-renamed
96 test_expect_equal "$output" "No new mail. Removed 3 messages."
99 test_begin_subtest "New directory (at end of list)"
101 generate_message [dir]=zzz
102 generate_message [dir]=zzz
103 generate_message [dir]=zzz
105 output=$(NOTMUCH_NEW)
106 test_expect_equal "$output" "Added 3 new messages to the database."
109 test_begin_subtest "Deleted directory (end of list)"
111 rm -rf "${MAIL_DIR}"/zzz
113 output=$(NOTMUCH_NEW)
114 test_expect_equal "$output" "No new mail. Removed 3 messages."
117 test_begin_subtest "New symlink to directory"
119 rm -rf "${MAIL_DIR}"/.notmuch
120 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
123 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
125 output=$(NOTMUCH_NEW)
126 test_expect_equal "$output" "Added 1 new message to the database."
129 test_begin_subtest "New symlink to a file"
131 external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename")"
132 mkdir -p "$(dirname "$external_msg_filename")"
133 mv "$gen_msg_filename" "$external_msg_filename"
134 ln -s "$external_msg_filename" "$gen_msg_filename"
135 output=$(NOTMUCH_NEW)
136 test_expect_equal "$output" "Added 1 new message to the database."
139 test_begin_subtest "Broken symlink aborts"
140 ln -s does-not-exist "${MAIL_DIR}/broken"
141 output=$(NOTMUCH_NEW 2>&1)
142 test_expect_equal "$output" \
143 "Error reading file ${MAIL_DIR}/broken: No such file or directory
144 Note: A fatal error was encountered: Something went wrong trying to read or write a file
146 rm "${MAIL_DIR}/broken"
149 test_begin_subtest "New two-level directory"
151 generate_message [dir]=two/levels
152 generate_message [dir]=two/levels
153 generate_message [dir]=two/levels
155 output=$(NOTMUCH_NEW)
156 test_expect_equal "$output" "Added 3 new messages to the database."
159 test_begin_subtest "Deleted two-level directory"
161 rm -rf "${MAIL_DIR}"/two
163 output=$(NOTMUCH_NEW)
164 test_expect_equal "$output" "No new mail. Removed 3 messages."
166 test_begin_subtest "Support single-message mbox (deprecated)"
167 cat > "${MAIL_DIR}"/mbox_file1 <<EOF
168 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
169 From: Notmuch Test Suite <test_suite@notmuchmail.org>
170 To: Notmuch Test Suite <test_suite@notmuchmail.org>
171 Subject: Test mbox message 1
175 output=$(NOTMUCH_NEW 2>&1)
176 test_expect_equal "$output" \
177 "Warning: ${MAIL_DIR}/mbox_file1 is an mbox containing a single message,
178 likely caused by misconfigured mail delivery. Support for single-message
179 mboxes is deprecated and may be removed in the future.
180 Added 1 new message to the database."
182 # This test requires that notmuch new has been run at least once.
183 test_begin_subtest "Skip and report non-mail files"
185 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
186 touch "${MAIL_DIR}"/ignored_file
187 touch "${MAIL_DIR}"/.ignored_hidden_file
188 cat > "${MAIL_DIR}"/mbox_file <<EOF
189 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
190 From: Notmuch Test Suite <test_suite@notmuchmail.org>
191 To: Notmuch Test Suite <test_suite@notmuchmail.org>
192 Subject: Test mbox message 1
196 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
197 From: Notmuch Test Suite <test_suite@notmuchmail.org>
198 To: Notmuch Test Suite <test_suite@notmuchmail.org>
199 Subject: Test mbox message 2
203 output=$(NOTMUCH_NEW 2>&1)
204 test_expect_equal "$output" \
205 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
206 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
207 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
208 Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file
209 Added 1 new message to the database."
210 rm "${MAIL_DIR}"/mbox_file
212 test_begin_subtest "Ignore files and directories specified in new.ignore"
214 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
215 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
216 output=$(NOTMUCH_NEW 2>&1)
217 test_expect_equal "$output" "Added 1 new message to the database."
219 test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"
220 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
221 notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.
222 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
223 touch "${MAIL_DIR}" # likewise for MAIL_DIR
224 mkdir -p "${MAIL_DIR}"/one/two/three/.git
225 touch "${MAIL_DIR}"/{one,one/two,one/two/three}/ignored_file
226 output=$(NOTMUCH_NEW --debug 2>&1 | sort)
227 test_expect_equal "$output" \
228 "(D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.git
229 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
230 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
231 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
232 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
233 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
234 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
235 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.git
236 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
237 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
238 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
239 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
240 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
241 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
245 test_begin_subtest "Don't stop for ignored broken symlinks"
246 notmuch config set new.ignore .git ignored_file .ignored_hidden_file broken_link
247 ln -s i_do_not_exist "${MAIL_DIR}"/broken_link
248 output=$(NOTMUCH_NEW 2>&1)
249 test_expect_equal "$output" "No new mail."
251 test_begin_subtest "Quiet: No new mail."
252 output=$(NOTMUCH_NEW --quiet)
253 test_expect_equal "$output" ""
255 test_begin_subtest "Quiet: new, removed and renamed messages."
259 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
261 mkdir "${MAIL_DIR}"/moved_messages
262 notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0 -I {} mv {} "${MAIL_DIR}"/moved_messages
263 output=$(NOTMUCH_NEW --quiet)
264 test_expect_equal "$output" ""
266 OLDCONFIG=$(notmuch config get new.tags)
268 test_begin_subtest "Empty tags in new.tags are forbidden"
269 notmuch config set new.tags "foo;;bar"
270 output=$(NOTMUCH_NEW 2>&1)
271 test_expect_equal "$output" "Error: tag '' in new.tags: empty tag forbidden"
273 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
274 notmuch config set new.tags "-foo;bar"
275 output=$(NOTMUCH_NEW 2>&1)
276 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
278 test_expect_code 1 "Invalid tags set exit code" \
281 notmuch config set new.tags $OLDCONFIG