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}" "$PWD"/actual_maildir
123 ln -s "$PWD"/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="$PWD"/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 "New two-level directory"
141 generate_message [dir]=two/levels
142 generate_message [dir]=two/levels
143 generate_message [dir]=two/levels
145 output=$(NOTMUCH_NEW)
146 test_expect_equal "$output" "Added 3 new messages to the database."
149 test_begin_subtest "Deleted two-level directory"
151 rm -rf "${MAIL_DIR}"/two
153 output=$(NOTMUCH_NEW)
154 test_expect_equal "$output" "No new mail. Removed 3 messages."
156 # This test requires that notmuch new has been run at least once.
157 test_begin_subtest "Skip and report non-mail files"
159 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
160 touch "${MAIL_DIR}"/ignored_file
161 touch "${MAIL_DIR}"/.ignored_hidden_file
162 output=$(NOTMUCH_NEW 2>&1)
163 test_expect_equal "$output" \
164 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
165 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
166 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
167 Added 1 new message to the database."
169 test_begin_subtest "Ignore files and directories specified in new.ignore"
171 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
172 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
173 output=$(NOTMUCH_NEW 2>&1)
174 test_expect_equal "$output" "Added 1 new message to the database."