test: Fix the search and dump-restore tests to operator on non-empty mail store.

We do this with a new add_email_corpus function that establishes a
mail store with 50 messages from the notmuch mailing list.
This commit is contained in:
Carl Worth 2010-09-20 16:40:35 -07:00
parent d805866ec5
commit 5497b01c27
6 changed files with 27 additions and 4 deletions

1
test/.gitignore vendored
View file

@ -1 +1,2 @@
test-results test-results
corpus.mail

View file

@ -52,7 +52,7 @@ test_expect_code 2 'failure to clean up causes the test to fail' '
# Ensure that all tests are being run # Ensure that all tests are being run
test_begin_subtest 'Ensure that all available tests will be run by notmuch-test' test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
tests_in_suite=$(grep TESTS= ../notmuch-test | sed -e "s/TESTS=\"\(.*\)\"/\1/" | tr " " "\n" | sort) tests_in_suite=$(grep TESTS= ../notmuch-test | sed -e "s/TESTS=\"\(.*\)\"/\1/" | tr " " "\n" | sort)
available=$(ls -1 ../ | grep -v -E "^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test|README|test-lib.sh|test-results|tmp.*|valgrind)" | sort) available=$(ls -1 ../ | grep -v -E "^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test|README|test-lib.sh|test-results|tmp.*|valgrind|corpus*)" | sort)
test_expect_equal "$tests_in_suite" "$available" test_expect_equal "$tests_in_suite" "$available"
################################################################ ################################################################

View file

@ -2,6 +2,8 @@
test_description="\"notmuch dump\" and \"notmuch restore\"" test_description="\"notmuch dump\" and \"notmuch restore\""
. ./test-lib.sh . ./test-lib.sh
add_email_corpus
test_expect_success "Dumping all tags" "generate_message && test_expect_success "Dumping all tags" "generate_message &&
notmuch new && notmuch new &&
notmuch dump dump.expected" notmuch dump dump.expected"

View file

@ -22,4 +22,4 @@ done
./aggregate-results.sh test-results/* ./aggregate-results.sh test-results/*
# Clean up # Clean up
rm -r test-results rm -r test-results corpus.mail

View file

@ -2,6 +2,8 @@
test_description='"notmuch search" in several variations' test_description='"notmuch search" in several variations'
. ./test-lib.sh . ./test-lib.sh
add_email_corpus
test_begin_subtest "Search body" test_begin_subtest "Search body"
add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
output=$(notmuch search bodysearchtest | notmuch_search_sanitize) output=$(notmuch search bodysearchtest | notmuch_search_sanitize)

View file

@ -354,7 +354,7 @@ EOF
increment_mtime "$(dirname "${gen_msg_filename}")" increment_mtime "$(dirname "${gen_msg_filename}")"
} }
# Generate a new message and add it to the index. # Generate a new message and add it to the database.
# #
# All of the arguments and return values supported by generate_message # All of the arguments and return values supported by generate_message
# are also supported here, so see that function for details. # are also supported here, so see that function for details.
@ -364,6 +364,24 @@ add_message ()
notmuch new > /dev/null notmuch new > /dev/null
} }
# Generate a corpus of email and add it to the database.
#
# This corpus is fixed, (it happens to be 50 messages from early in
# the history of the notmuch mailing list), which allows for reliably
# testing commands that need to operate on a not-totally-trivial
# number of messages.
add_email_corpus ()
{
rm -rf ${MAIL_DIR}
if [ -d ../corpus.mail ]; then
cp -a ../corpus.mail ${MAIL_DIR}
else
cp -a ../corpus ${MAIL_DIR}
notmuch new
cp -a ${MAIL_DIR} ../corpus.mail
fi
}
test_begin_subtest () test_begin_subtest ()
{ {
test_subtest_name="$1" test_subtest_name="$1"
@ -801,7 +819,7 @@ MAIL_DIR="${TMP_DIRECTORY}/mail"
export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config" export NOTMUCH_CONFIG="${TMP_DIRECTORY}/notmuch-config"
mkdir -p "${test}" mkdir -p "${test}"
mkdir "$MAIL_DIR" mkdir -p "${MAIL_DIR}"
cat <<EOF >"${NOTMUCH_CONFIG}" cat <<EOF >"${NOTMUCH_CONFIG}"
[database] [database]