--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id DD807429E28\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:14:01 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.438\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id Z89IAR3c7jBM for <notmuch@notmuchmail.org>;\r
+ Fri, 27 Mar 2015 15:14:00 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 046AF429E26\r
+ for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:14:00 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YbcV9-0000Et-L1; Fri, 27 Mar 2015 22:13:15 +0000\r
+Received: (nullmailer pid 1811 invoked by uid 1000); Fri, 27 Mar 2015\r
+ 22:12:15 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v6 3/8] test: add error reporting tests\r
+Date: Fri, 27 Mar 2015 23:11:55 +0100\r
+Message-Id: <1427494320-1483-4-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1427494320-1483-1-git-send-email-david@tethera.net>\r
+References: <1427494320-1483-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 27 Mar 2015 22:14:02 -0000\r
+\r
+This includes tests for all of the error fprintfs in the library I\r
+could figure out how to test without using gdb scripts. It boils down\r
+to errors opening files and exceptions caused by corrupted Xapian\r
+databases.\r
+---\r
+ test/T560-lib-error.sh | 285 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 285 insertions(+)\r
+ create mode 100755 test/T560-lib-error.sh\r
+\r
+diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh\r
+new file mode 100755\r
+index 0000000..f1ca543\r
+--- /dev/null\r
++++ b/test/T560-lib-error.sh\r
+@@ -0,0 +1,285 @@\r
++#!/usr/bin/env bash\r
++test_description="error reporting for library"\r
++\r
++. ./test-lib.sh\r
++\r
++backup_database () {\r
++ rm -rf notmuch-dir-backup\r
++ cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup\r
++}\r
++restore_database () {\r
++ rm -rf ${MAIL_DIR}/.notmuch\r
++ cp -pR notmuch-dir-backup ${MAIL_DIR}/.notmuch\r
++}\r
++\r
++\r
++add_email_corpus\r
++\r
++test_expect_success "building database" "NOTMUCH_NEW"\r
++\r
++test_begin_subtest "Open null pointer"\r
++test_C <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_open (NULL, 0, 0);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Error: Cannot open a database for a NULL path.\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "Open nonexistent database"\r
++test_C <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_open ("/nonexistent/foo", 0, 0);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Error opening database at /nonexistent/foo/.notmuch: No such file or directory\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "create NULL path"\r
++test_C <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_create (NULL, NULL);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Error: Cannot create a database for a NULL path.\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "Create database in non-existant directory"\r
++test_C <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_create ("/nonexistent/foo", &db);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Error: Cannot create database at /nonexistent/foo: No such file or directory.\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "Write to read-only database"\r
++test_C ${MAIL_DIR} <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);\r
++ if (stat != NOTMUCH_STATUS_SUCCESS) {\r
++ fprintf (stderr, "error opening database: %d\n", stat);\r
++ }\r
++ stat = notmuch_database_add_message (db, "/dev/null", NULL);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Cannot write to a read-only database.\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "Add non-existent file"\r
++test_C ${MAIL_DIR} <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);\r
++ if (stat != NOTMUCH_STATUS_SUCCESS) {\r
++ fprintf (stderr, "error opening database: %d\n", stat);\r
++ }\r
++ stat = notmuch_database_add_message (db, "/nonexistent", NULL);\r
++ if (stat)\r
++ fputs (notmuch_database_status_string (db), stderr);\r
++\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Error opening /nonexistent: No such file or directory\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "compact, overwriting existing backup"\r
++test_C ${MAIL_DIR} <<'EOF'\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++static void\r
++status_cb (const char *msg, void *closure)\r
++{\r
++ printf ("%s\n", msg);\r
++}\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++Path already exists: CWD/mail\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++cat <<'EOF' > c_head\r
++#include <stdio.h>\r
++#include <sys/types.h>\r
++#include <sys/stat.h>\r
++#include <fcntl.h>\r
++#include <talloc.h>\r
++#include <notmuch.h>\r
++\r
++int main (int argc, char** argv)\r
++{\r
++ notmuch_database_t *db;\r
++ notmuch_status_t stat;\r
++ char *path;\r
++ int fd;\r
++\r
++ stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);\r
++ if (stat != NOTMUCH_STATUS_SUCCESS) {\r
++ fprintf (stderr, "error opening database: %d\n", stat);\r
++ }\r
++ path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]);\r
++ fd = open(path,O_WRONLY|O_TRUNC);\r
++ if (fd < 0)\r
++ fprintf (stderr, "error opening %s\n");\r
++EOF\r
++cat <<'EOF' > c_tail\r
++ if (stat) {\r
++ const char *stat_str = notmuch_database_status_string (db);\r
++ if (stat_str)\r
++ fputs (stat_str, stderr);\r
++ }\r
++\r
++}\r
++EOF\r
++\r
++backup_database\r
++test_begin_subtest "Xapian exception finding message"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++ {\r
++ notmuch_message_t *message = NULL;\r
++ stat = notmuch_database_find_message (db, "id:nonexistant", &message);\r
++ }\r
++EOF\r
++sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++A Xapian exception occurred finding message\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT.clean\r
++restore_database\r
++\r
++backup_database\r
++test_begin_subtest "Xapian exception getting tags"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++ {\r
++ notmuch_tags_t *tags = NULL;\r
++ tags = notmuch_database_get_all_tags (db);\r
++ stat = (tags == NULL);\r
++ }\r
++EOF\r
++sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++A Xapian exception occurred getting tags\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT.clean\r
++restore_database\r
++\r
++backup_database\r
++test_begin_subtest "Xapian exception creating directory"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++ {\r
++ notmuch_directory_t *directory = NULL;\r
++ stat = notmuch_database_get_directory (db, "none/existing", &directory);\r
++ }\r
++EOF\r
++sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++A Xapian exception occurred creating a directory\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT.clean\r
++restore_database\r
++\r
++backup_database\r
++test_begin_subtest "Xapian exception searching messages"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++ {\r
++ notmuch_messages_t *messages = NULL;\r
++ notmuch_query_t *query=notmuch_query_create (db, "*");\r
++ stat = notmuch_query_search_messages_st (query, &messages);\r
++ }\r
++EOF\r
++sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++A Xapian exception occurred performing query\r
++Query string was: *\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT.clean\r
++restore_database\r
++\r
++backup_database\r
++test_begin_subtest "Xapian exception counting messages"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++ {\r
++ notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");\r
++ int count = notmuch_query_count_messages (query);\r
++ stat = (count == 0);\r
++ }\r
++EOF\r
++sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++== stderr ==\r
++A Xapian exception occurred performing query\r
++Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT.clean\r
++restore_database\r
++\r
++test_done\r
+-- \r
+2.1.4\r
+\r