]> git.notmuchmail.org Git - notmuch/blob - test/T050-new.sh
build: drop support for xapian versions less than 1.4
[notmuch] / test / T050-new.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch new" in several variations'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 test_begin_subtest "No new messages"
6 output=$(NOTMUCH_NEW --debug)
7 test_expect_equal "$output" "No new mail."
8
9
10 test_begin_subtest "Single new message"
11 generate_message
12 output=$(NOTMUCH_NEW --debug)
13 test_expect_equal "$output" "Added 1 new message to the database."
14
15 test_begin_subtest "Single message (full-scan)"
16 generate_message
17 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
18 test_expect_equal "$output" "Added 1 new message to the database."
19
20 test_begin_subtest "Multiple new messages"
21 generate_message
22 generate_message
23 output=$(NOTMUCH_NEW --debug)
24 test_expect_equal "$output" "Added 2 new messages to the database."
25
26 test_begin_subtest "Multiple new messages (full-scan)"
27 generate_message
28 generate_message
29 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
30 test_expect_equal "$output" "Added 2 new messages to the database."
31
32 test_begin_subtest "No new messages (non-empty DB)"
33 output=$(NOTMUCH_NEW --debug)
34 test_expect_equal "$output" "No new mail."
35
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."
39
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
45
46 output=$(NOTMUCH_NEW --debug)
47 test_expect_equal "$output" "Added 1 new message to the database."
48
49
50 test_begin_subtest "Alternate inode order"
51
52 rm -rf "${MAIL_DIR}"/.notmuch
53 mv "${MAIL_DIR}"/ghi "${MAIL_DIR}"/abc
54 rm "${MAIL_DIR}"/def/*
55 generate_message [dir]=abc
56
57 output=$(NOTMUCH_NEW --debug)
58 test_expect_equal "$output" "Added 1 new message to the database."
59
60
61 test_begin_subtest "Message moved in"
62 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
63 generate_message
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."
71
72
73 test_begin_subtest "Renamed message"
74
75 generate_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."
81
82
83 test_begin_subtest "Deleted message"
84
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."
89
90
91
92 test_begin_subtest "Renamed directory"
93
94 generate_message [dir]=dir
95 generate_message [dir]=dir
96 generate_message [dir]=dir
97
98 notmuch new > /dev/null
99
100 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
101
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."
105
106
107 test_begin_subtest "Deleted directory"
108 rm -rf "${MAIL_DIR}"/dir-renamed
109
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."
113
114
115 test_begin_subtest "New directory (at end of list)"
116
117 generate_message [dir]=zzz
118 generate_message [dir]=zzz
119 generate_message [dir]=zzz
120
121 output=$(NOTMUCH_NEW --debug)
122 test_expect_equal "$output" "Added 3 new messages to the database."
123
124
125 test_begin_subtest "Deleted directory (end of list)"
126
127 rm -rf "${MAIL_DIR}"/zzz
128
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."
132
133
134 test_begin_subtest "New symlink to directory"
135
136 rm -rf "${MAIL_DIR}"/.notmuch
137 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
138
139 mkdir "${MAIL_DIR}"
140 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
141
142 output=$(NOTMUCH_NEW --debug)
143 test_expect_equal "$output" "Added 1 new message to the database."
144
145
146 test_begin_subtest "New symlink to a file"
147 generate_message
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."
154
155
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
162 No new mail."
163 rm "${MAIL_DIR}/broken"
164
165
166 test_begin_subtest "New two-level directory"
167
168 generate_message [dir]=two/levels
169 generate_message [dir]=two/levels
170 generate_message [dir]=two/levels
171
172 output=$(NOTMUCH_NEW --debug)
173 test_expect_equal "$output" "Added 3 new messages to the database."
174
175
176 test_begin_subtest "Deleted two-level directory"
177
178 rm -rf "${MAIL_DIR}"/two
179
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."
183
184 test_begin_subtest "One character directory at top level"
185
186 generate_message [dir]=A
187 generate_message [dir]=A/B
188 generate_message [dir]=A/B/C
189
190 output=$(NOTMUCH_NEW --debug)
191 test_expect_equal "$output" "Added 3 new messages to the database."
192
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
199
200 Body.
201 EOF
202 output=$(NOTMUCH_NEW --debug 2>&1)
203 test_expect_equal "$output" "Added 1 new message to the database."
204
205 # This test requires that notmuch new has been run at least once.
206 test_begin_subtest "Skip and report non-mail files"
207 generate_message
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
216
217 Body.
218
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
223
224 Body 2.
225 EOF
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
234
235 test_begin_subtest "Ignore files and directories specified in new.ignore"
236 generate_message
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
240 cat <<EOF > EXPECTED
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.
248 EOF
249 test_expect_equal_file EXPECTED OUTPUT
250
251 test_begin_subtest "Ignore files and directories specified in new.ignore (full-scan)"
252 generate_message
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
257
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
279 No new mail."
280
281
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."
287
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
308 No new mail."
309
310 test_begin_subtest "Quiet: No new mail."
311 output=$(NOTMUCH_NEW --quiet)
312 test_expect_equal "$output" ""
313
314 test_begin_subtest "Quiet: new, removed and renamed messages."
315 # new
316 generate_message
317 # deleted
318 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
319 # moved
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" ""
324
325 OLDCONFIG=$(notmuch config get new.tags)
326
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"
331
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"
336
337 test_begin_subtest "Invalid tags set exit code"
338 test_expect_code 1 "NOTMUCH_NEW --debug 2>&1"
339
340 notmuch config set new.tags $OLDCONFIG
341
342
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"
348
349
350 test_begin_subtest "Handle files vanishing between scandir and add_file"
351
352 # A file for scandir to find. It won't get indexed, so can be empty.
353 touch ${MAIL_DIR}/vanish
354
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
359 set logging on
360 break notmuch_database_index_file
361 commands
362 shell rm -f ${MAIL_DIR}/vanish
363 continue
364 end
365 run
366 EOF
367
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
371
372 # Clean up the file in case gdb isn't available.
373 rm -f ${MAIL_DIR}/vanish
374
375 cat <<EOF > EXPECTED
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
379 exit status: 75
380 EOF
381 test_expect_equal_file EXPECTED OUTPUT
382
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"
386
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
390 cat <<EOF > EXPECTED
391 Date: Thu, 16 Jun 2016 22:14:41 -0400
392 Date: Fri, 17 Jun 2016 22:14:41 -0400
393 EOF
394 test_expect_equal_file EXPECTED OUTPUT
395
396 test_done