From: David Bremner Date: Fri, 27 Mar 2015 22:11:55 +0000 (+0100) Subject: [Patch v6 3/8] test: add error reporting tests X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7acc42e26e0520a0eb7c1b63e0d09fed138213c0;p=notmuch-archives.git [Patch v6 3/8] test: add error reporting tests --- diff --git a/73/bf27d4372b8f6c1c4f82a63b222c3f67a45477 b/73/bf27d4372b8f6c1c4f82a63b222c3f67a45477 new file mode 100644 index 000000000..6863e5c7c --- /dev/null +++ b/73/bf27d4372b8f6c1c4f82a63b222c3f67a45477 @@ -0,0 +1,352 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id DD807429E28 + for ; Fri, 27 Mar 2015 15:14:01 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.438 +X-Spam-Level: ** +X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Z89IAR3c7jBM for ; + Fri, 27 Mar 2015 15:14:00 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 046AF429E26 + for ; Fri, 27 Mar 2015 15:14:00 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YbcV9-0000Et-L1; Fri, 27 Mar 2015 22:13:15 +0000 +Received: (nullmailer pid 1811 invoked by uid 1000); Fri, 27 Mar 2015 + 22:12:15 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [Patch v6 3/8] test: add error reporting tests +Date: Fri, 27 Mar 2015 23:11:55 +0100 +Message-Id: <1427494320-1483-4-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1427494320-1483-1-git-send-email-david@tethera.net> +References: <1427494320-1483-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 27 Mar 2015 22:14:02 -0000 + +This includes tests for all of the error fprintfs in the library I +could figure out how to test without using gdb scripts. It boils down +to errors opening files and exceptions caused by corrupted Xapian +databases. +--- + test/T560-lib-error.sh | 285 +++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 285 insertions(+) + create mode 100755 test/T560-lib-error.sh + +diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh +new file mode 100755 +index 0000000..f1ca543 +--- /dev/null ++++ b/test/T560-lib-error.sh +@@ -0,0 +1,285 @@ ++#!/usr/bin/env bash ++test_description="error reporting for library" ++ ++. ./test-lib.sh ++ ++backup_database () { ++ rm -rf notmuch-dir-backup ++ cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup ++} ++restore_database () { ++ rm -rf ${MAIL_DIR}/.notmuch ++ cp -pR notmuch-dir-backup ${MAIL_DIR}/.notmuch ++} ++ ++ ++add_email_corpus ++ ++test_expect_success "building database" "NOTMUCH_NEW" ++ ++test_begin_subtest "Open null pointer" ++test_C <<'EOF' ++#include ++#include ++int main (int argc, char** argv) ++{ ++ notmuch_database_t *db; ++ notmuch_status_t stat; ++ stat = notmuch_database_open (NULL, 0, 0); ++} ++EOF ++cat <<'EOF' >EXPECTED ++== stdout == ++== stderr == ++Error: Cannot open a database for a NULL path. ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ ++test_begin_subtest "Open nonexistent database" ++test_C <<'EOF' ++#include ++#include ++int main (int argc, char** argv) ++{ ++ notmuch_database_t *db; ++ notmuch_status_t stat; ++ stat = notmuch_database_open ("/nonexistent/foo", 0, 0); ++} ++EOF ++cat <<'EOF' >EXPECTED ++== stdout == ++== stderr == ++Error opening database at /nonexistent/foo/.notmuch: No such file or directory ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ ++test_begin_subtest "create NULL path" ++test_C <<'EOF' ++#include ++#include ++int main (int argc, char** argv) ++{ ++ notmuch_status_t stat; ++ stat = notmuch_database_create (NULL, NULL); ++} ++EOF ++cat <<'EOF' >EXPECTED ++== stdout == ++== stderr == ++Error: Cannot create a database for a NULL path. ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ ++test_begin_subtest "Create database in non-existant directory" ++test_C <<'EOF' ++#include ++#include ++int main (int argc, char** argv) ++{ ++ notmuch_database_t *db; ++ notmuch_status_t stat; ++ stat = notmuch_database_create ("/nonexistent/foo", &db); ++} ++EOF ++cat <<'EOF' >EXPECTED ++== stdout == ++== stderr == ++Error: Cannot create database at /nonexistent/foo: No such file or directory. ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ ++test_begin_subtest "Write to read-only database" ++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_ONLY, &db); ++ if (stat != NOTMUCH_STATUS_SUCCESS) { ++ fprintf (stderr, "error opening database: %d\n", stat); ++ } ++ stat = notmuch_database_add_message (db, "/dev/null", NULL); ++} ++EOF ++cat <<'EOF' >EXPECTED ++== stdout == ++== stderr == ++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 ++#include ++static void ++status_cb (const char *msg, void *closure) ++{ ++ printf ("%s\n", msg); ++} ++int main (int argc, char** argv) ++{ ++ notmuch_database_t *db; ++ notmuch_status_t stat; ++ stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL); ++} ++EOF ++cat <<'EOF' >EXPECTED ++== stdout == ++== stderr == ++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 +-- +2.1.4 +