From 185d75134cf6c38a8bc60194e6d74cbe1359120c Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 14 Mar 2015 18:02:28 +0100 Subject: [PATCH] [Patch v4 3/9] test: add error reporting tests for lib/database.cc --- 34/3242098c7d91412c8d6c61606fd24b6cb8f1a2 | 156 ++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 34/3242098c7d91412c8d6c61606fd24b6cb8f1a2 diff --git a/34/3242098c7d91412c8d6c61606fd24b6cb8f1a2 b/34/3242098c7d91412c8d6c61606fd24b6cb8f1a2 new file mode 100644 index 000000000..eac228529 --- /dev/null +++ b/34/3242098c7d91412c8d6c61606fd24b6cb8f1a2 @@ -0,0 +1,156 @@ +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 69A08431FD9 + for ; Sat, 14 Mar 2015 10:04:34 -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 0mrH15wFt-kA for ; + Sat, 14 Mar 2015 10:04:32 -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 93086431FD7 + for ; Sat, 14 Mar 2015 10:04:32 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YWpTY-00027S-Cp; Sat, 14 Mar 2015 17:03:48 +0000 +Received: (nullmailer pid 4985 invoked by uid 1000); Sat, 14 Mar 2015 + 17:02:41 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [Patch v4 3/9] test: add error reporting tests for lib/database.cc +Date: Sat, 14 Mar 2015 18:02:28 +0100 +Message-Id: <1426352554-4383-4-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1426352554-4383-1-git-send-email-david@tethera.net> +References: <1426352554-4383-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: Sat, 14 Mar 2015 17:04:34 -0000 + +Unfortunately quite a few of the error handling paths here require +more sophisticated tests using e.g. gdb. +--- + test/T560-lib-error.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 91 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..dc2022f +--- /dev/null ++++ b/test/T560-lib-error.sh +@@ -0,0 +1,91 @@ ++#!/usr/bin/env bash ++test_description="error reporting for library" ++ ++. ./test-lib.sh ++ ++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 "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 ++ ++test_done +-- +2.1.4 + -- 2.26.2