]> git.notmuchmail.org Git - notmuch/blob - test/T050-new.sh
test: add debugging output to notmuch-new tests, mark 5 as broken
[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 --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
16 test_begin_subtest "Multiple new messages"
17 generate_message
18 generate_message
19 output=$(NOTMUCH_NEW --debug)
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 --debug)
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 --debug)
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 --debug)
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 --debug)
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 --debug)
91 test_expect_equal "$output" "(D) add_files_recursive, pass 2: queuing passed directory ${MAIL_DIR}/dir for deletion from database
92 No new mail. Detected 3 file renames."
93
94
95 test_begin_subtest "Deleted directory"
96 test_subtest_known_broken
97 rm -rf "${MAIL_DIR}"/dir-renamed
98
99 output=$(NOTMUCH_NEW --debug)
100 test_expect_equal "$output" "(D) add_files_recursive, pass 2: queuing passed directory ${MAIL_DIR}/dir-renamed for deletion from database
101 No new mail. Removed 3 messages."
102
103
104 test_begin_subtest "New directory (at end of list)"
105 test_subtest_known_broken
106
107 generate_message [dir]=zzz
108 generate_message [dir]=zzz
109 generate_message [dir]=zzz
110
111 output=$(NOTMUCH_NEW --debug)
112 test_expect_equal "$output" "Added 3 new messages to the database."
113
114
115 test_begin_subtest "Deleted directory (end of list)"
116
117 test_subtest_known_broken
118 rm -rf "${MAIL_DIR}"/zzz
119
120 output=$(NOTMUCH_NEW --debug)
121 test_expect_equal "$output" "(D) add_files_recursive, pass 3: queuing leftover directory ${MAIL_DIR}/zzz for deletion from database
122 No new mail. Removed 3 messages."
123
124
125 test_begin_subtest "New symlink to directory"
126
127 rm -rf "${MAIL_DIR}"/.notmuch
128 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
129
130 mkdir "${MAIL_DIR}"
131 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
132
133 output=$(NOTMUCH_NEW --debug)
134 test_expect_equal "$output" "Added 1 new message to the database."
135
136
137 test_begin_subtest "New symlink to a file"
138 generate_message
139 external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename")"
140 mkdir -p "$(dirname "$external_msg_filename")"
141 mv "$gen_msg_filename" "$external_msg_filename"
142 ln -s "$external_msg_filename" "$gen_msg_filename"
143 output=$(NOTMUCH_NEW --debug)
144 test_expect_equal "$output" "Added 1 new message to the database."
145
146
147 test_begin_subtest "Broken symlink aborts"
148 ln -s does-not-exist "${MAIL_DIR}/broken"
149 output=$(NOTMUCH_NEW --debug 2>&1)
150 test_expect_equal "$output" \
151 "Error reading file ${MAIL_DIR}/broken: No such file or directory
152 Note: A fatal error was encountered: Something went wrong trying to read or write a file
153 No new mail."
154 rm "${MAIL_DIR}/broken"
155
156
157 test_begin_subtest "New two-level directory"
158
159 generate_message [dir]=two/levels
160 generate_message [dir]=two/levels
161 generate_message [dir]=two/levels
162
163 output=$(NOTMUCH_NEW --debug)
164 test_expect_equal "$output" "Added 3 new messages to the database."
165
166
167 test_begin_subtest "Deleted two-level directory"
168
169 rm -rf "${MAIL_DIR}"/two
170
171 output=$(NOTMUCH_NEW --debug)
172 test_expect_equal "$output" "(D) add_files_recursive, pass 3: queuing leftover directory ${MAIL_DIR}/two for deletion from database
173 No new mail. Removed 3 messages."
174
175 test_begin_subtest "Support single-message mbox"
176 test_subtest_known_broken
177 cat > "${MAIL_DIR}"/mbox_file1 <<EOF
178 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
179 From: Notmuch Test Suite <test_suite@notmuchmail.org>
180 To: Notmuch Test Suite <test_suite@notmuchmail.org>
181 Subject: Test mbox message 1
182
183 Body.
184 EOF
185 output=$(NOTMUCH_NEW --debug 2>&1)
186 test_expect_equal "$output" "Added 1 new message to the database."
187
188 # This test requires that notmuch new has been run at least once.
189 test_begin_subtest "Skip and report non-mail files"
190 test_subtest_known_broken
191 generate_message
192 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
193 touch "${MAIL_DIR}"/ignored_file
194 touch "${MAIL_DIR}"/.ignored_hidden_file
195 cat > "${MAIL_DIR}"/mbox_file <<EOF
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 1
200
201 Body.
202
203 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
204 From: Notmuch Test Suite <test_suite@notmuchmail.org>
205 To: Notmuch Test Suite <test_suite@notmuchmail.org>
206 Subject: Test mbox message 2
207
208 Body 2.
209 EOF
210 output=$(NOTMUCH_NEW --debug 2>&1)
211 test_expect_equal "$output" \
212 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
213 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
214 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
215 Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file
216 Added 1 new message to the database."
217 rm "${MAIL_DIR}"/mbox_file
218
219 test_begin_subtest "Ignore files and directories specified in new.ignore"
220 generate_message
221 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
222 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
223 output=$(NOTMUCH_NEW 2>&1)
224 test_expect_equal "$output" "Added 1 new message to the database."
225
226 test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"
227 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
228 notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.
229 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
230 touch "${MAIL_DIR}"      # likewise for MAIL_DIR
231 mkdir -p "${MAIL_DIR}"/one/two/three/.git
232 touch "${MAIL_DIR}"/{one,one/two,one/two/three}/ignored_file
233 output=$(NOTMUCH_NEW --debug 2>&1 | sort)
234 test_expect_equal "$output" \
235 "(D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.git
236 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
237 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
238 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
239 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
240 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
241 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
242 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.git
243 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
244 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
245 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
246 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
247 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
248 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
249 (D) add_files_recursive, pass 3: queuing leftover directory ${MAIL_DIR}/two for deletion from database
250 No new mail."
251
252
253 test_begin_subtest "Don't stop for ignored broken symlinks"
254 notmuch config set new.ignore .git ignored_file .ignored_hidden_file broken_link
255 ln -s i_do_not_exist "${MAIL_DIR}"/broken_link
256 output=$(NOTMUCH_NEW 2>&1)
257 test_expect_equal "$output" "No new mail."
258
259 test_begin_subtest "Quiet: No new mail."
260 output=$(NOTMUCH_NEW --quiet)
261 test_expect_equal "$output" ""
262
263 test_begin_subtest "Quiet: new, removed and renamed messages."
264 # new
265 generate_message
266 # deleted
267 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
268 # moved
269 mkdir "${MAIL_DIR}"/moved_messages
270 notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0 -I {} mv {} "${MAIL_DIR}"/moved_messages
271 output=$(NOTMUCH_NEW --quiet)
272 test_expect_equal "$output" ""
273
274 OLDCONFIG=$(notmuch config get new.tags)
275
276 test_begin_subtest "Empty tags in new.tags are forbidden"
277 notmuch config set new.tags "foo;;bar"
278 output=$(NOTMUCH_NEW --debug 2>&1)
279 test_expect_equal "$output" "Error: tag '' in new.tags: empty tag forbidden"
280
281 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
282 notmuch config set new.tags "-foo;bar"
283 output=$(NOTMUCH_NEW --debug 2>&1)
284 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
285
286 test_expect_code 1 "Invalid tags set exit code" \
287     "NOTMUCH_NEW --debug 2>&1"
288
289 notmuch config set new.tags $OLDCONFIG
290
291
292 test_begin_subtest "Xapian exception: read only files"
293 chmod u-w  ${MAIL_DIR}/.notmuch/xapian/*.DB
294 output=$(NOTMUCH_NEW --debug 2>&1 | sed 's/: .*$//' )
295 chmod u+w  ${MAIL_DIR}/.notmuch/xapian/*.DB
296 test_expect_equal "$output" "A Xapian exception occurred opening database"
297
298 test_done