2 test_description='"notmuch new" in several variations'
3 . ./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."
16 test_begin_subtest "Multiple new messages"
19 output=$(NOTMUCH_NEW --debug)
20 test_expect_equal "$output" "Added 2 new messages to the database."
23 test_begin_subtest "No new messages (non-empty DB)"
24 output=$(NOTMUCH_NEW --debug)
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
34 output=$(NOTMUCH_NEW --debug)
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
45 output=$(NOTMUCH_NEW --debug)
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"
57 output=$(NOTMUCH_NEW --debug)
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
66 output=$(NOTMUCH_NEW --debug)
67 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed file ${gen_msg_filename} for deletion from database
68 No new mail. Detected 1 file rename."
71 test_begin_subtest "Deleted message"
73 rm "${gen_msg_filename}"-renamed
74 output=$(NOTMUCH_NEW --debug)
75 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover file ${gen_msg_filename}-renamed for deletion from database
76 No new mail. Removed 1 message."
80 test_begin_subtest "Renamed directory"
82 generate_message [dir]=dir
83 generate_message [dir]=dir
84 generate_message [dir]=dir
86 notmuch new > /dev/null
88 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
90 output=$(NOTMUCH_NEW --debug)
91 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed directory ${MAIL_DIR}/dir for deletion from database
92 No new mail. Detected 3 file renames."
95 test_begin_subtest "Deleted directory"
96 rm -rf "${MAIL_DIR}"/dir-renamed
98 output=$(NOTMUCH_NEW --debug)
99 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed directory ${MAIL_DIR}/dir-renamed for deletion from database
100 No new mail. Removed 3 messages."
103 test_begin_subtest "New directory (at end of list)"
105 generate_message [dir]=zzz
106 generate_message [dir]=zzz
107 generate_message [dir]=zzz
109 output=$(NOTMUCH_NEW --debug)
110 test_expect_equal "$output" "Added 3 new messages to the database."
113 test_begin_subtest "Deleted directory (end of list)"
115 rm -rf "${MAIL_DIR}"/zzz
117 output=$(NOTMUCH_NEW --debug)
118 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory ${MAIL_DIR}/zzz for deletion from database
119 No new mail. Removed 3 messages."
122 test_begin_subtest "New symlink to directory"
124 rm -rf "${MAIL_DIR}"/.notmuch
125 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
128 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
130 output=$(NOTMUCH_NEW --debug)
131 test_expect_equal "$output" "Added 1 new message to the database."
134 test_begin_subtest "New symlink to a file"
136 external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename")"
137 mkdir -p "$(dirname "$external_msg_filename")"
138 mv "$gen_msg_filename" "$external_msg_filename"
139 ln -s "$external_msg_filename" "$gen_msg_filename"
140 output=$(NOTMUCH_NEW --debug)
141 test_expect_equal "$output" "Added 1 new message to the database."
144 test_begin_subtest "Broken symlink aborts"
145 ln -s does-not-exist "${MAIL_DIR}/broken"
146 output=$(NOTMUCH_NEW --debug 2>&1)
147 test_expect_equal "$output" \
148 "Error reading file ${MAIL_DIR}/broken: No such file or directory
149 Note: A fatal error was encountered: Something went wrong trying to read or write a file
151 rm "${MAIL_DIR}/broken"
154 test_begin_subtest "New two-level directory"
156 generate_message [dir]=two/levels
157 generate_message [dir]=two/levels
158 generate_message [dir]=two/levels
160 output=$(NOTMUCH_NEW --debug)
161 test_expect_equal "$output" "Added 3 new messages to the database."
164 test_begin_subtest "Deleted two-level directory"
166 rm -rf "${MAIL_DIR}"/two
168 output=$(NOTMUCH_NEW --debug)
169 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory ${MAIL_DIR}/two for deletion from database
170 No new mail. Removed 3 messages."
172 test_begin_subtest "One character directory at top level"
173 test_subtest_known_broken
175 generate_message [dir]=A
176 generate_message [dir]=A/B
177 generate_message [dir]=A/B/C
179 output=$(NOTMUCH_NEW --debug)
180 test_expect_equal "$output" "Added 3 new messages to the database."
182 # clean up after the broken test to not mess up other tests
183 rm -rf "${MAIL_DIR}"/A
184 NOTMUCH_NEW 2>&1 > /dev/null
186 test_begin_subtest "Support single-message mbox"
187 cat > "${MAIL_DIR}"/mbox_file1 <<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
195 output=$(NOTMUCH_NEW --debug 2>&1)
196 test_expect_equal "$output" "Added 1 new message to the database."
198 # This test requires that notmuch new has been run at least once.
199 test_begin_subtest "Skip and report non-mail files"
201 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
202 touch "${MAIL_DIR}"/ignored_file
203 touch "${MAIL_DIR}"/.ignored_hidden_file
204 cat > "${MAIL_DIR}"/mbox_file <<EOF
205 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
206 From: Notmuch Test Suite <test_suite@notmuchmail.org>
207 To: Notmuch Test Suite <test_suite@notmuchmail.org>
208 Subject: Test mbox message 1
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 2
219 output=$(NOTMUCH_NEW --debug 2>&1)
220 test_expect_equal "$output" \
221 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
222 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
223 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
224 Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file
225 Added 1 new message to the database."
226 rm "${MAIL_DIR}"/mbox_file
228 test_begin_subtest "Ignore files and directories specified in new.ignore"
230 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
231 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
232 output=$(NOTMUCH_NEW 2>&1)
233 test_expect_equal "$output" "Added 1 new message to the database."
235 test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"
236 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
237 notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.
238 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
239 touch "${MAIL_DIR}" # likewise for MAIL_DIR
240 mkdir -p "${MAIL_DIR}"/one/two/three/.git
241 touch "${MAIL_DIR}"/{one,one/two,one/two/three}/ignored_file
242 output=$(NOTMUCH_NEW --debug 2>&1 | sort)
243 test_expect_equal "$output" \
244 "(D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.git
245 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
246 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
247 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
248 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
249 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
250 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
251 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.git
252 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
253 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
254 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
255 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
256 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
257 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
261 test_begin_subtest "Don't stop for ignored broken symlinks"
262 notmuch config set new.ignore .git ignored_file .ignored_hidden_file broken_link
263 ln -s i_do_not_exist "${MAIL_DIR}"/broken_link
264 output=$(NOTMUCH_NEW 2>&1)
265 test_expect_equal "$output" "No new mail."
267 test_begin_subtest "Quiet: No new mail."
268 output=$(NOTMUCH_NEW --quiet)
269 test_expect_equal "$output" ""
271 test_begin_subtest "Quiet: new, removed and renamed messages."
275 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
277 mkdir "${MAIL_DIR}"/moved_messages
278 notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0 -I {} mv {} "${MAIL_DIR}"/moved_messages
279 output=$(NOTMUCH_NEW --quiet)
280 test_expect_equal "$output" ""
282 OLDCONFIG=$(notmuch config get new.tags)
284 test_begin_subtest "Empty tags in new.tags are forbidden"
285 notmuch config set new.tags "foo;;bar"
286 output=$(NOTMUCH_NEW --debug 2>&1)
287 test_expect_equal "$output" "Error: tag '' in new.tags: empty tag forbidden"
289 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
290 notmuch config set new.tags "-foo;bar"
291 output=$(NOTMUCH_NEW --debug 2>&1)
292 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
294 test_expect_code 1 "Invalid tags set exit code" \
295 "NOTMUCH_NEW --debug 2>&1"
297 notmuch config set new.tags $OLDCONFIG
300 test_begin_subtest "Xapian exception: read only files"
301 chmod u-w ${MAIL_DIR}/.notmuch/xapian/*.${db_ending}
302 output=$(NOTMUCH_NEW --debug 2>&1 | sed 's/: .*$//' )
303 chmod u+w ${MAIL_DIR}/.notmuch/xapian/*.${db_ending}
304 test_expect_equal "$output" "A Xapian exception occurred opening database"