+ test_begin_subtest "insert+search ($config)"
+ generate_message \
+ "[subject]=\"insert-subject\"" \
+ "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
+ "[body]=\"insert-message\""
+ mkdir -p "$MAIL_DIR"/{cur,new,tmp}
+ notmuch insert < "$gen_msg_filename"
+ cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
+ test_expect_equal_file_nonempty "$cur_msg_filename" "$gen_msg_filename"
+
+ test_begin_subtest "compact+search ($config)"
+ notmuch search --output=messages '*' | sort > EXPECTED
+ notmuch compact
+ notmuch search --output=messages '*' | sort > OUTPUT
+ test_expect_equal_file_nonempty EXPECTED OUTPUT
+
+ test_begin_subtest "upgrade backup ($config)"
+ features=$(xapian-metadata get $XAPIAN_PATH features | grep -v "^relative directory paths")
+ xapian-metadata set $XAPIAN_PATH features "$features"
+ output=$(notmuch new | grep Welcome)
+ test_expect_equal \
+ "$output" \
+ "Welcome to a new version of notmuch! Your database will now be upgraded."
+
+ test_begin_subtest "notmuch +config -database suggests notmuch new ($config)"
+ mv "$XAPIAN_PATH" "${XAPIAN_PATH}.bak"
+ notmuch > OUTPUT
+cat <<EOF > EXPECTED
+Notmuch is configured, but no database was found.
+You probably want to run "notmuch new" now to create a database.
+
+Note that the first run of "notmuch new" can take a very long time
+and that the resulting database will use roughly the same amount of
+storage space as the email being indexed.
+
+EOF
+ mv "${XAPIAN_PATH}.bak" "$XAPIAN_PATH"
+
+ test_expect_equal_file EXPECTED OUTPUT
+
+ test_begin_subtest "Set config value ($config)"
+ name=${RANDOM}
+ value=${RANDOM}
+ notmuch config set test${test_count}.${name} ${value}
+ output=$(notmuch config get test${test_count}.${name})
+ notmuch config set test${test_count}.${name}
+ output2=$(notmuch config get test${test_count}.${name})
+ test_expect_equal "${output}+${output2}" "${value}+"
+
+ test_begin_subtest "Set config value in database ($config)"
+ name=${RANDOM}
+ value=${RANDOM}
+ notmuch config set --database test${test_count}.${name} ${value}
+ output=$(notmuch config get test${test_count}.${name})
+ notmuch config set --database test${test_count}.${name}
+ output2=$(notmuch config get test${test_count}.${name})
+ test_expect_equal "${output}+${output2}" "${value}+"
+
+ test_begin_subtest "Config list ($config)"
+ notmuch config list | notmuch_config_sanitize | \
+ sed -e "s/^database.backup_dir=.*$/database.backup_dir/" \
+ -e "s/^database.hook_dir=.*$/database.hook_dir/" \
+ -e "s/^database.path=.*$/database.path/" \
+ -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \
+ -e "s,^database.mail_root=CWD/home/env_points_here,database.mail_root=MAIL_DIR," \
+ > OUTPUT
+ cat <<EOF > EXPECTED
+built_with.compact=something
+built_with.field_processor=something
+built_with.retry_lock=something
+built_with.sexp_queries=something
+database.autocommit=8000
+database.backup_dir
+database.hook_dir
+database.mail_root=MAIL_DIR
+database.path
+maildir.synchronize_flags=true
+new.ignore=
+new.tags=unread;inbox
+search.exclude_tags=
+user.name=Notmuch Test Suite
+user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
+user.primary_email=test_suite@notmuchmail.org
+EOF
+ test_expect_equal_file EXPECTED OUTPUT
+
+ test_begin_subtest "Config list from python ($config)"
+ test_python <<EOF > OUTPUT
+from notmuch2 import Database
+db=Database(config=Database.CONFIG.SEARCH)
+for key in list(db.config):
+ print(key)
+EOF
+ cat <<EOF > EXPECTED
+database.autocommit
+database.backup_dir
+database.hook_dir
+database.mail_root
+database.path
+maildir.synchronize_flags
+new.tags
+user.name
+user.other_email
+user.primary_email
+EOF
+ test_expect_equal_file EXPECTED OUTPUT
+ case $config in
+ XDG*)
+ test_begin_subtest "Set shadowed config value in database ($config)"
+ name=${RANDOM}
+ value=${RANDOM}
+ key=test${test_count}.${name}
+ notmuch config set --database ${key} ${value}
+ notmuch config set ${key} shadow${value}
+ output=$(notmuch --config='' config get ${key})
+ notmuch config set --database ${key}
+ output2=$(notmuch --config='' config get ${key})
+ notmuch config set ${key}
+ test_expect_equal "${output}+${output2}" "${value}+"
+ ;&
+ split)
+ test_begin_subtest "'to' header does not crash (python-cffi) ($config)"
+ echo 'notmuch@notmuchmail.org' > EXPECTED
+ test_python <<EOF
+from notmuch2 import Database
+db=Database(config=Database.CONFIG.SEARCH)
+m=db.find('20091117232137.GA7669@griffis1.net')
+to=m.header('To')
+print(to)
+EOF
+ test_expect_equal_file EXPECTED OUTPUT
+
+ test_begin_subtest ".notmuch not ignored in split config ($config)"
+ test_subtest_known_broken
+ generate_message '[dir]=.notmuch/cur' '[subject]="Do not ignore, very important"'
+ NOTMUCH_NEW > OUTPUT
+ notmuch search subject:Do-not-ignore | notmuch_search_sanitize >> OUTPUT
+ cat <<EOF > EXPECTED
+Added 1 new message to the database.
+thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Do not ignore, very important (inbox unread)
+EOF
+ test_expect_equal_file EXPECTED OUTPUT
+ ;;
+ *)
+ backup_database
+ test_begin_subtest ".notmuch without xapian/ handled gracefully ($config)"
+ rm -r $XAPIAN_PATH
+ test_expect_success "notmuch new"
+ restore_database
+ ;;
+ esac
+
+ case $config in
+ split|XDG*)
+ esac
+ restore_config
+ rm -rf home/.local
+ rm -rf home/.config