--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\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 6BE91431FC0\r
+ for <notmuch@notmuchmail.org>; Wed, 25 Mar 2015 09:20:10 -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 gvRZLH0GKIUi for <notmuch@notmuchmail.org>;\r
+ Wed, 25 Mar 2015 09:20:07 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 40B91431FBC\r
+ for <notmuch@notmuchmail.org>; Wed, 25 Mar 2015 09:20:07 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 47261100086;\r
+ Wed, 25 Mar 2015 18:19:42 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, David Bremner <david@tethera.net>,\r
+ notmuch@notmuchmail.org\r
+Subject: Re: [Patch v5 3/8] test: add error reporting tests\r
+In-Reply-To: <1427203451-1540-4-git-send-email-david@tethera.net>\r
+References: <1426352554-4383-10-git-send-email-david@tethera.net>\r
+ <1427203451-1540-1-git-send-email-david@tethera.net>\r
+ <1427203451-1540-4-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.19+92~g402df12 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Wed, 25 Mar 2015 18:19:42 +0200\r
+Message-ID: <m2egoduk0x.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Wed, 25 Mar 2015 16:20:10 -0000\r
+\r
+On Tue, Mar 24 2015, David Bremner <david@tethera.net> wrote:\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 | 250 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+> 1 file changed, 250 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..c2964cb\r
+> --- /dev/null\r
+> +++ b/test/T560-lib-error.sh\r
+> @@ -0,0 +1,250 @@\r
+> +#!/usr/bin/env bash\r
+> +test_description="error reporting for library"\r
+> +\r
+> +. ./test-lib.sh\r
+> +\r
+> +backup_database (){\r
+\r
+missing space: backup_database () {\r
+\r
+( fgrep '()' test/* shows consistent style there )\r
+\r
+> + rm -rf notmuch-dir-backup\r
+> + cp -a ${MAIL_DIR}/.notmuch notmuch-dir-backup\r
+\r
+cp -a is not solaris compatible (it is freebsd 10.1)\r
+cp -pR would be more portable option\r
+\r
+> +}\r
+> +restore_database (){\r
+\r
+missing space\r
+\r
+> + rm -rf ${MAIL_DIR}/.notmuch\r
+> + cp -a notmuch-dir-backup ${MAIL_DIR}/.notmuch\r
+\r
+cp -a ...\r
+\r
+\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
+\r
+Like discussed in IRC, test_C <<'EOF' would be mode convenient to \r
+reviewer when there is nothing to be interpolated -- so reviewer\r
+can ignore checking potential interpolations (e.g. $... and `...`:s)\r
+\r
+grep '<<.*EOF' test/* doesn't show that this is ever user, though :/\r
+\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 "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 > head.c\r
+\r
+One usually expects *.c files to be "complete" source files; as an\r
+alternative I suggest filenames\r
+\r
+c_head and c_tail\r
+\r
+\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 > tail.c\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 head.c - tail.c <<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
+\r
+(I was going to suggest sed 's/...' OUTPUT > OUTPUT.clean (i.e remove '<'\r
+but I actually cannot determine which would be better :D)\r
+\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 head.c - tail.c <<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 head.c - tail.c <<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 head.c - tail.c <<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 head.c - tail.c <<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