]> git.notmuchmail.org Git - notmuch/blob - test/T050-new.sh
lib: drop the deprecation message for single-message mbox files
[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)
7 test_expect_equal "$output" "No new mail."
8
9
10 test_begin_subtest "Single new message"
11 generate_message
12 output=$(NOTMUCH_NEW)
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)
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)
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)
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)
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)
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)
67 test_expect_equal "$output" "No new mail. Detected 1 file rename."
68
69
70 test_begin_subtest "Deleted message"
71
72 rm "${gen_msg_filename}"-renamed
73 output=$(NOTMUCH_NEW)
74 test_expect_equal "$output" "No new mail. Removed 1 message."
75
76
77 test_begin_subtest "Renamed directory"
78
79 generate_message [dir]=dir
80 generate_message [dir]=dir
81 generate_message [dir]=dir
82
83 notmuch new > /dev/null
84
85 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
86
87 output=$(NOTMUCH_NEW)
88 test_expect_equal "$output" "No new mail. Detected 3 file renames."
89
90
91 test_begin_subtest "Deleted directory"
92
93 rm -rf "${MAIL_DIR}"/dir-renamed
94
95 output=$(NOTMUCH_NEW)
96 test_expect_equal "$output" "No new mail. Removed 3 messages."
97
98
99 test_begin_subtest "New directory (at end of list)"
100
101 generate_message [dir]=zzz
102 generate_message [dir]=zzz
103 generate_message [dir]=zzz
104
105 output=$(NOTMUCH_NEW)
106 test_expect_equal "$output" "Added 3 new messages to the database."
107
108
109 test_begin_subtest "Deleted directory (end of list)"
110
111 rm -rf "${MAIL_DIR}"/zzz
112
113 output=$(NOTMUCH_NEW)
114 test_expect_equal "$output" "No new mail. Removed 3 messages."
115
116
117 test_begin_subtest "New symlink to directory"
118
119 rm -rf "${MAIL_DIR}"/.notmuch
120 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
121
122 mkdir "${MAIL_DIR}"
123 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
124
125 output=$(NOTMUCH_NEW)
126 test_expect_equal "$output" "Added 1 new message to the database."
127
128
129 test_begin_subtest "New symlink to a file"
130 generate_message
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."
137
138
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
145 No new mail."
146 rm "${MAIL_DIR}/broken"
147
148
149 test_begin_subtest "New two-level directory"
150
151 generate_message [dir]=two/levels
152 generate_message [dir]=two/levels
153 generate_message [dir]=two/levels
154
155 output=$(NOTMUCH_NEW)
156 test_expect_equal "$output" "Added 3 new messages to the database."
157
158
159 test_begin_subtest "Deleted two-level directory"
160
161 rm -rf "${MAIL_DIR}"/two
162
163 output=$(NOTMUCH_NEW)
164 test_expect_equal "$output" "No new mail. Removed 3 messages."
165
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
172
173 Body.
174 EOF
175 output=$(NOTMUCH_NEW 2>&1)
176 test_expect_equal "$output" "Added 1 new message to the database."
177
178 # This test requires that notmuch new has been run at least once.
179 test_begin_subtest "Skip and report non-mail files"
180 generate_message
181 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
182 touch "${MAIL_DIR}"/ignored_file
183 touch "${MAIL_DIR}"/.ignored_hidden_file
184 cat > "${MAIL_DIR}"/mbox_file <<EOF
185 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
186 From: Notmuch Test Suite <test_suite@notmuchmail.org>
187 To: Notmuch Test Suite <test_suite@notmuchmail.org>
188 Subject: Test mbox message 1
189
190 Body.
191
192 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
193 From: Notmuch Test Suite <test_suite@notmuchmail.org>
194 To: Notmuch Test Suite <test_suite@notmuchmail.org>
195 Subject: Test mbox message 2
196
197 Body 2.
198 EOF
199 output=$(NOTMUCH_NEW 2>&1)
200 test_expect_equal "$output" \
201 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
202 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
203 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
204 Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file
205 Added 1 new message to the database."
206 rm "${MAIL_DIR}"/mbox_file
207
208 test_begin_subtest "Ignore files and directories specified in new.ignore"
209 generate_message
210 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
211 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
212 output=$(NOTMUCH_NEW 2>&1)
213 test_expect_equal "$output" "Added 1 new message to the database."
214
215 test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"
216 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
217 notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.
218 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
219 touch "${MAIL_DIR}"      # likewise for MAIL_DIR
220 mkdir -p "${MAIL_DIR}"/one/two/three/.git
221 touch "${MAIL_DIR}"/{one,one/two,one/two/three}/ignored_file
222 output=$(NOTMUCH_NEW --debug 2>&1 | sort)
223 test_expect_equal "$output" \
224 "(D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.git
225 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
226 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
227 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
228 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
229 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
230 (D) add_files_recursive, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
231 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.git
232 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
233 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
234 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
235 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
236 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
237 (D) add_files_recursive, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
238 No new mail."
239
240
241 test_begin_subtest "Don't stop for ignored broken symlinks"
242 notmuch config set new.ignore .git ignored_file .ignored_hidden_file broken_link
243 ln -s i_do_not_exist "${MAIL_DIR}"/broken_link
244 output=$(NOTMUCH_NEW 2>&1)
245 test_expect_equal "$output" "No new mail."
246
247 test_begin_subtest "Quiet: No new mail."
248 output=$(NOTMUCH_NEW --quiet)
249 test_expect_equal "$output" ""
250
251 test_begin_subtest "Quiet: new, removed and renamed messages."
252 # new
253 generate_message
254 # deleted
255 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
256 # moved
257 mkdir "${MAIL_DIR}"/moved_messages
258 notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0 -I {} mv {} "${MAIL_DIR}"/moved_messages
259 output=$(NOTMUCH_NEW --quiet)
260 test_expect_equal "$output" ""
261
262 OLDCONFIG=$(notmuch config get new.tags)
263
264 test_begin_subtest "Empty tags in new.tags are forbidden"
265 notmuch config set new.tags "foo;;bar"
266 output=$(NOTMUCH_NEW 2>&1)
267 test_expect_equal "$output" "Error: tag '' in new.tags: empty tag forbidden"
268
269 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
270 notmuch config set new.tags "-foo;bar"
271 output=$(NOTMUCH_NEW 2>&1)
272 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
273
274 test_expect_code 1 "Invalid tags set exit code" \
275     "NOTMUCH_NEW 2>&1"
276
277 notmuch config set new.tags $OLDCONFIG
278
279 test_done