From: David Bremner Date: Tue, 24 Mar 2015 13:24:06 +0000 (+2000) Subject: [Patch v5 3/8] test: add error reporting tests X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bb5235b1453bda938ed10dcb117911f16a156159;p=notmuch-archives.git [Patch v5 3/8] test: add error reporting tests --- diff --git a/46/7f40da0850932411657b18bb09f3cb92c6005c b/46/7f40da0850932411657b18bb09f3cb92c6005c new file mode 100644 index 000000000..93e9ab142 --- /dev/null +++ b/46/7f40da0850932411657b18bb09f3cb92c6005c @@ -0,0 +1,318 @@ +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 EF9D0431E62 + for ; Tue, 24 Mar 2015 06:25:35 -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=unavailable +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 FBiLkZnDlQ7k for ; + Tue, 24 Mar 2015 06:25:35 -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 726E5429E30 + for ; Tue, 24 Mar 2015 06:25:32 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YaOp8-0000s6-AJ; Tue, 24 Mar 2015 13:24:50 +0000 +Received: (nullmailer pid 2680 invoked by uid 1000); Tue, 24 Mar 2015 + 13:24:25 -0000 +From: David Bremner +To: David Bremner , notmuch@notmuchmail.org +Subject: [Patch v5 3/8] test: add error reporting tests +Date: Tue, 24 Mar 2015 09:24:06 -0400 +Message-Id: <1427203451-1540-4-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1427203451-1540-1-git-send-email-david@tethera.net> +References: <1426352554-4383-10-git-send-email-david@tethera.net> + <1427203451-1540-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: Tue, 24 Mar 2015 13:25:37 -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 | 250 +++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 250 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..c2964cb +--- /dev/null ++++ b/test/T560-lib-error.sh +@@ -0,0 +1,250 @@ ++#!/usr/bin/env bash ++test_description="error reporting for library" ++ ++. ./test-lib.sh ++ ++backup_database (){ ++ rm -rf notmuch-dir-backup ++ cp -a ${MAIL_DIR}/.notmuch notmuch-dir-backup ++} ++restore_database (){ ++ rm -rf ${MAIL_DIR}/.notmuch ++ cp -a notmuch-dir-backup ${MAIL_DIR}/.notmuch ++} ++ ++ ++add_email_corpus ++ ++test_expect_success "building database" "NOTMUCH_NEW" ++ ++test_begin_subtest "Open null pointer" ++test_C < ++#include ++int main (int argc, char** argv) ++{ ++ notmuch_database_t *db; ++ notmuch_status_t stat; ++ stat = notmuch_database_open (NULL, 0, 0); ++} ++EOF ++cat <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 < ++#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 <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 "Write to read-only database" ++test_C ${MAIL_DIR} < ++#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 <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} < ++#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 <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} < ++#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 <EXPECTED ++== stdout == ++== stderr == ++Path already exists: CWD/mail ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ ++cat < head.c ++#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 < tail.c ++ 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 head.c - tail.c < OUTPUT.clean ++cat <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 head.c - tail.c < OUTPUT.clean ++cat <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 head.c - tail.c < OUTPUT.clean ++cat <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 head.c - tail.c < OUTPUT.clean ++cat <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 head.c - tail.c < OUTPUT.clean ++cat <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 +