2 test_description='Configuration of mail-root and database path'
3 . $(dirname "$0")/test-lib.sh || exit 1
5 test_require_external_prereq xapian-metdata
8 local test_name=$(basename $0 .sh)
9 cp ${NOTMUCH_CONFIG} notmuch-config-backup.${test_name}
13 local test_name=$(basename $0 .sh)
14 export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
21 cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
27 dir="$TMP_DIRECTORY/database.$test_count"
30 notmuch config set database.path $dir
31 notmuch config set database.mail_root $MAIL_DIR
33 XAPIAN_PATH="$dir/xapian"
39 dir="$TMP_DIRECTORY/link.$test_count"
41 notmuch config set database.path $dir
42 notmuch config set database.mail_root $MAIL_DIR
43 XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
53 notmuch config set database.path
54 notmuch config set database.mail_root
55 XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
59 maildir_env_config () {
62 dir="${HOME}/env_points_here"
65 notmuch config set database.path
66 notmuch config set database.mail_root
67 XAPIAN_PATH="${MAIL_DIR}/.notmuch/xapian"
73 local profile=${1:-default}
75 if [[ $profile != default ]]; then
76 export NOTMUCH_PROFILE=$profile
80 DATABASE_PATH="${HOME}/.local/share/notmuch/${profile}"
82 mkdir -p $DATABASE_PATH
84 config_dir="${HOME}/.config/notmuch/${profile}"
85 mkdir -p ${config_dir}
86 CONFIG_PATH=$config_dir/config
87 mv ${NOTMUCH_CONFIG} $CONFIG_PATH
90 XAPIAN_PATH="${DATABASE_PATH}/xapian"
91 notmuch --config=${CONFIG_PATH} config set database.mail_root ${TMP_DIRECTORY}/mail
92 notmuch --config=${CONFIG_PATH} config set database.path
95 mailroot_only_config () {
99 notmuch config set database.mail_root ${TMP_DIRECTORY}/mail
100 notmuch config set database.path
101 DATABASE_PATH="${HOME}/.local/share/notmuch/default"
102 rm -rf $DATABASE_PATH
103 mkdir -p $DATABASE_PATH
104 XAPIAN_PATH="${DATABASE_PATH}/xapian"
105 mv mail/.notmuch/xapian $DATABASE_PATH
108 for config in traditional split XDG XDG+profile symlink home_mail maildir_env mailroot_only; do
109 #start each set of tests with an known set of messages
115 XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
119 mv mail/.notmuch/xapian $DATABASE_PATH
123 mv mail/.notmuch/xapian $DATABASE_PATH
127 mv mail/.notmuch/xapian $DATABASE_PATH
143 test_begin_subtest "count ($config)"
144 output=$(notmuch count '*')
145 test_expect_equal "$output" '52'
147 test_begin_subtest "count+tag ($config)"
149 notmuch tag +$tag '*'
150 output=$(notmuch count tag:$tag)
151 notmuch tag -$tag '*'
152 test_expect_equal "$output" '52'
154 test_begin_subtest "address ($config)"
155 notmuch address --deduplicate=no --sort=newest-first --output=sender --output=recipients path:foo >OUTPUT
157 Carl Worth <cworth@cworth.org>
158 notmuch@notmuchmail.org
160 test_expect_equal_file EXPECTED OUTPUT
162 test_begin_subtest "dump ($config)"
163 notmuch dump is:attachment and is:signed | sort > OUTPUT
165 #notmuch-dump batch-tag:3 config,properties,tags
166 +attachment +inbox +signed +unread -- id:20091118005829.GB25380@dottiness.seas.harvard.edu
167 +attachment +inbox +signed +unread -- id:20091118010116.GC25380@dottiness.seas.harvard.edu
169 test_expect_equal_file EXPECTED OUTPUT
171 test_begin_subtest "dump + tag + restore ($config)"
172 notmuch dump '*' > EXPECTED
173 notmuch tag -inbox '*'
174 notmuch restore < EXPECTED
175 notmuch dump > OUTPUT
176 test_expect_equal_file_nonempty EXPECTED OUTPUT
178 test_begin_subtest "reindex ($config)"
179 notmuch search --output=messages '*' > EXPECTED
181 notmuch search --output=messages '*' > OUTPUT
182 test_expect_equal_file_nonempty EXPECTED OUTPUT
184 test_begin_subtest "use existing database ($config)"
185 output=$(notmuch new)
186 test_expect_equal "$output" 'No new mail.'
188 test_begin_subtest "create database ($config)"
189 rm -rf $DATABASE_PATH/{.notmuch,}/xapian
191 output=$(notmuch count '*')
192 test_expect_equal "$output" '52'
194 test_begin_subtest "detect new files ($config)"
198 output=$(notmuch count '*')
199 test_expect_equal "$output" '54'
201 test_begin_subtest "Show a raw message ($config)"
203 notmuch show --format=raw id:$gen_msg_id > OUTPUT
204 test_expect_equal_file_nonempty $gen_msg_filename OUTPUT
205 rm -f $gen_msg_filename
207 test_begin_subtest "reply ($config)"
208 add_message '[from]="Sender <sender@example.com>"' \
209 [to]=test_suite@notmuchmail.org \
210 [subject]=notmuch-reply-test \
211 '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
212 '[body]="basic reply test"'
213 notmuch reply id:${gen_msg_id} 2>&1 > OUTPUT
215 From: Notmuch Test Suite <test_suite@notmuchmail.org>
216 Subject: Re: notmuch-reply-test
217 To: Sender <sender@example.com>
218 In-Reply-To: <${gen_msg_id}>
219 References: <${gen_msg_id}>
221 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
224 test_expect_equal_file EXPECTED OUTPUT
226 test_begin_subtest "insert+search ($config)"
228 "[subject]=\"insert-subject\"" \
229 "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
230 "[body]=\"insert-message\""
231 mkdir -p "$MAIL_DIR"/{cur,new,tmp}
232 notmuch insert < "$gen_msg_filename"
233 cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
234 test_expect_equal_file_nonempty "$cur_msg_filename" "$gen_msg_filename"
236 test_begin_subtest "compact+search ($config)"
237 notmuch search --output=messages '*' | sort > EXPECTED
239 notmuch search --output=messages '*' | sort > OUTPUT
240 test_expect_equal_file_nonempty EXPECTED OUTPUT
242 test_begin_subtest "upgrade backup ($config)"
243 features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
244 xapian-metadata set $XAPIAN_PATH features "$features"
245 output=$(notmuch new | grep Welcome)
248 "Welcome to a new version of notmuch! Your database will now be upgraded."
250 test_begin_subtest "notmuch +config -database suggests notmuch new ($config)"
251 mv "$XAPIAN_PATH" "${XAPIAN_PATH}.bak"
254 Notmuch is configured, but no database was found.
255 You probably want to run "notmuch new" now to create a database.
257 Note that the first run of "notmuch new" can take a very long time
258 and that the resulting database will use roughly the same amount of
259 storage space as the email being indexed.
262 mv "${XAPIAN_PATH}.bak" "$XAPIAN_PATH"
264 test_expect_equal_file EXPECTED OUTPUT
266 test_begin_subtest "Set config value ($config)"
269 notmuch config set test${test_count}.${name} ${value}
270 output=$(notmuch config get test${test_count}.${name})
271 notmuch config set test${test_count}.${name}
272 output2=$(notmuch config get test${test_count}.${name})
273 test_expect_equal "${output}+${output2}" "${value}+"
275 test_begin_subtest "Set config value in database ($config)"
278 notmuch config set --database test${test_count}.${name} ${value}
279 output=$(notmuch config get test${test_count}.${name})
280 notmuch config set --database test${test_count}.${name}
281 output2=$(notmuch config get test${test_count}.${name})
282 test_expect_equal "${output}+${output2}" "${value}+"
284 test_begin_subtest "Config list ($config)"
285 notmuch config list | notmuch_config_sanitize | \
286 sed -e "s/^database.backup_dir=.*$/database.backup_dir/" \
287 -e "s/^database.hook_dir=.*$/database.hook_dir/" \
288 -e "s/^database.path=.*$/database.path/" \
289 -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \
290 -e "s,^database.mail_root=CWD/home/env_points_here,database.mail_root=MAIL_DIR," \
293 built_with.compact=something
294 built_with.field_processor=something
295 built_with.retry_lock=something
296 built_with.sexp_queries=something
297 database.autocommit=8000
300 database.mail_root=MAIL_DIR
303 maildir.synchronize_flags=true
305 new.tags=unread;inbox
307 user.name=Notmuch Test Suite
308 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
309 user.primary_email=test_suite@notmuchmail.org
311 test_expect_equal_file EXPECTED OUTPUT
313 test_begin_subtest "Config list from python ($config)"
314 test_python <<EOF > OUTPUT
315 from notmuch2 import Database
316 db=Database(config=Database.CONFIG.SEARCH)
317 for key in list(db.config):
326 maildir.synchronize_flags
332 test_expect_equal_file EXPECTED OUTPUT
336 test_begin_subtest "Set shadowed config value in database ($config)"
339 key=test${test_count}.${name}
340 notmuch config set --database ${key} ${value}
341 notmuch config set ${key} shadow${value}
342 output=$(notmuch --config='' config get ${key})
343 notmuch config set --database ${key}
344 output2=$(notmuch --config='' config get ${key})
345 notmuch config set ${key}
346 test_expect_equal "${output}+${output2}" "${value}+"
349 test_begin_subtest "'to' header does not crash (python-cffi) ($config)"
350 echo 'notmuch@notmuchmail.org' > EXPECTED
352 from notmuch2 import Database
353 db=Database(config=Database.CONFIG.SEARCH)
354 m=db.find('20091117232137.GA7669@griffis1.net')
358 test_expect_equal_file EXPECTED OUTPUT
360 test_begin_subtest ".notmuch not ignored in split config ($config)"
361 test_subtest_known_broken
362 generate_message '[dir]=.notmuch/cur' '[subject]="Do not ignore, very important"'
364 notmuch search subject:Do-not-ignore | notmuch_search_sanitize >> OUTPUT
366 Added 1 new message to the database.
367 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Do not ignore, very important (inbox unread)
369 test_expect_equal_file EXPECTED OUTPUT
372 test_begin_subtest "create database parent dir ($config)"
373 rm -r ${DATABASE_PATH}
375 test_expect_equal "$(xapian-metadata get ${XAPIAN_PATH} version)" 3
379 test_begin_subtest ".notmuch without xapian/ handled gracefully ($config)"
381 test_expect_success "notmuch new"