From: David Bremner Date: Sat, 28 Mar 2015 23:24:38 +0000 (+0100) Subject: test: add more error reporting tests X-Git-Tag: 0.20~21 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=6a99505625785022d490207bdf6e3e29ed156c6a test: add more error reporting tests This second half of the error reporting tests actually uses the function notmuch_database_status_string to retrieve the last logged error --- diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh index 70d6097b..67a5e8df 100755 --- a/test/T560-lib-error.sh +++ b/test/T560-lib-error.sh @@ -113,6 +113,31 @@ Cannot write to a read-only database. EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "Add non-existent file" +test_C ${MAIL_DIR} <<'EOF' +#include +#include +int main (int argc, char** argv) +{ + notmuch_database_t *db; + notmuch_status_t stat; + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db); + if (stat != NOTMUCH_STATUS_SUCCESS) { + fprintf (stderr, "error opening database: %d\n", stat); + } + stat = notmuch_database_add_message (db, "/nonexistent", NULL); + if (stat) + fputs (notmuch_database_status_string (db), stderr); + +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +Error opening /nonexistent: No such file or directory +EOF +test_expect_equal_file EXPECTED OUTPUT + test_begin_subtest "compact, overwriting existing backup" test_C ${MAIL_DIR} <<'EOF' #include @@ -137,4 +162,128 @@ Path already exists: CWD/mail EOF test_expect_equal_file EXPECTED OUTPUT +cat <<'EOF' > c_head +#include +#include +#include +#include +#include +#include + +int main (int argc, char** argv) +{ + notmuch_database_t *db; + notmuch_status_t stat; + char *path; + int fd; + + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db); + if (stat != NOTMUCH_STATUS_SUCCESS) { + fprintf (stderr, "error opening database: %d\n", stat); + } + path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]); + fd = open(path,O_WRONLY|O_TRUNC); + if (fd < 0) + fprintf (stderr, "error opening %s\n"); +EOF +cat <<'EOF' > c_tail + if (stat) { + const char *stat_str = notmuch_database_status_string (db); + if (stat_str) + fputs (stat_str, stderr); + } + +} +EOF + +backup_database +test_begin_subtest "Xapian exception finding message" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + { + notmuch_message_t *message = NULL; + stat = notmuch_database_find_message (db, "id:nonexistant", &message); + } +EOF +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +A Xapian exception occurred finding message +EOF +test_expect_equal_file EXPECTED OUTPUT.clean +restore_database + +backup_database +test_begin_subtest "Xapian exception getting tags" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + { + notmuch_tags_t *tags = NULL; + tags = notmuch_database_get_all_tags (db); + stat = (tags == NULL); + } +EOF +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +A Xapian exception occurred getting tags +EOF +test_expect_equal_file EXPECTED OUTPUT.clean +restore_database + +backup_database +test_begin_subtest "Xapian exception creating directory" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + { + notmuch_directory_t *directory = NULL; + stat = notmuch_database_get_directory (db, "none/existing", &directory); + } +EOF +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +A Xapian exception occurred creating a directory +EOF +test_expect_equal_file EXPECTED OUTPUT.clean +restore_database + +backup_database +test_begin_subtest "Xapian exception searching messages" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + { + notmuch_messages_t *messages = NULL; + notmuch_query_t *query=notmuch_query_create (db, "*"); + stat = notmuch_query_search_messages_st (query, &messages); + } +EOF +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +A Xapian exception occurred performing query +Query string was: * +EOF +test_expect_equal_file EXPECTED OUTPUT.clean +restore_database + +backup_database +test_begin_subtest "Xapian exception counting messages" +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + { + notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org"); + int count = notmuch_query_count_messages (query); + stat = (count == 0); + } +EOF +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +A Xapian exception occurred performing query +Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org +EOF +test_expect_equal_file EXPECTED OUTPUT.clean +restore_database + test_done