1 Return-Path: <bremner@tesseract.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id EF9D0431E62
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:25:35 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=2.438 tagged_above=-999 required=5
\r
12 tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=unavailable
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id FBiLkZnDlQ7k for <notmuch@notmuchmail.org>;
\r
16 Tue, 24 Mar 2015 06:25:35 -0700 (PDT)
\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net
\r
19 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 726E5429E30
\r
22 for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:25:32 -0700 (PDT)
\r
23 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim
\r
24 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
25 id 1YaOp8-0000s6-AJ; Tue, 24 Mar 2015 13:24:50 +0000
\r
26 Received: (nullmailer pid 2680 invoked by uid 1000); Tue, 24 Mar 2015
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
\r
30 Subject: [Patch v5 3/8] test: add error reporting tests
\r
31 Date: Tue, 24 Mar 2015 09:24:06 -0400
\r
32 Message-Id: <1427203451-1540-4-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 2.1.4
\r
34 In-Reply-To: <1427203451-1540-1-git-send-email-david@tethera.net>
\r
35 References: <1426352554-4383-10-git-send-email-david@tethera.net>
\r
36 <1427203451-1540-1-git-send-email-david@tethera.net>
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Tue, 24 Mar 2015 13:25:37 -0000
\r
51 This includes tests for all of the error fprintfs in the library I
\r
52 could figure out how to test without using gdb scripts. It boils down
\r
53 to errors opening files and exceptions caused by corrupted Xapian
\r
56 test/T560-lib-error.sh | 250 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
57 1 file changed, 250 insertions(+)
\r
58 create mode 100755 test/T560-lib-error.sh
\r
60 diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
\r
61 new file mode 100755
\r
62 index 0000000..c2964cb
\r
64 +++ b/test/T560-lib-error.sh
\r
66 +#!/usr/bin/env bash
\r
67 +test_description="error reporting for library"
\r
71 +backup_database (){
\r
72 + rm -rf notmuch-dir-backup
\r
73 + cp -a ${MAIL_DIR}/.notmuch notmuch-dir-backup
\r
75 +restore_database (){
\r
76 + rm -rf ${MAIL_DIR}/.notmuch
\r
77 + cp -a notmuch-dir-backup ${MAIL_DIR}/.notmuch
\r
83 +test_expect_success "building database" "NOTMUCH_NEW"
\r
85 +test_begin_subtest "Open null pointer"
\r
88 +#include <notmuch.h>
\r
89 +int main (int argc, char** argv)
\r
91 + notmuch_database_t *db;
\r
92 + notmuch_status_t stat;
\r
93 + stat = notmuch_database_open (NULL, 0, 0);
\r
96 +cat <<EOF >EXPECTED
\r
99 +Error: Cannot open a database for a NULL path.
\r
101 +test_expect_equal_file EXPECTED OUTPUT
\r
103 +test_begin_subtest "Open nonexistent database"
\r
105 +#include <stdio.h>
\r
106 +#include <notmuch.h>
\r
107 +int main (int argc, char** argv)
\r
109 + notmuch_database_t *db;
\r
110 + notmuch_status_t stat;
\r
111 + stat = notmuch_database_open ("/nonexistent/foo", 0, 0);
\r
114 +cat <<EOF >EXPECTED
\r
117 +Error opening database at /nonexistent/foo/.notmuch: No such file or directory
\r
119 +test_expect_equal_file EXPECTED OUTPUT
\r
121 +test_begin_subtest "Write to read-only database"
\r
122 +test_C ${MAIL_DIR} <<EOF
\r
123 +#include <stdio.h>
\r
124 +#include <notmuch.h>
\r
125 +int main (int argc, char** argv)
\r
127 + notmuch_database_t *db;
\r
128 + notmuch_status_t stat;
\r
129 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
\r
130 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
131 + fprintf (stderr, "error opening database: %d\n", stat);
\r
133 + stat = notmuch_database_add_message (db, "/dev/null", NULL);
\r
136 +cat <<EOF >EXPECTED
\r
139 +Cannot write to a read-only database.
\r
141 +test_expect_equal_file EXPECTED OUTPUT
\r
143 +test_begin_subtest "Add non-existent file"
\r
144 +test_C ${MAIL_DIR} <<EOF
\r
145 +#include <stdio.h>
\r
146 +#include <notmuch.h>
\r
147 +int main (int argc, char** argv)
\r
149 + notmuch_database_t *db;
\r
150 + notmuch_status_t stat;
\r
151 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
\r
152 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
153 + fprintf (stderr, "error opening database: %d\n", stat);
\r
155 + stat = notmuch_database_add_message (db, "/nonexistent", NULL);
\r
157 + fputs (notmuch_database_status_string (db), stderr);
\r
161 +cat <<EOF >EXPECTED
\r
164 +Error opening /nonexistent: No such file or directory
\r
166 +test_expect_equal_file EXPECTED OUTPUT
\r
168 +test_begin_subtest "compact, overwriting existing backup"
\r
169 +test_C ${MAIL_DIR} <<EOF
\r
170 +#include <stdio.h>
\r
171 +#include <notmuch.h>
\r
173 +status_cb (const char *msg, void *closure)
\r
175 + printf ("%s\n", msg);
\r
177 +int main (int argc, char** argv)
\r
179 + notmuch_database_t *db;
\r
180 + notmuch_status_t stat;
\r
181 + stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
\r
184 +cat <<EOF >EXPECTED
\r
187 +Path already exists: CWD/mail
\r
189 +test_expect_equal_file EXPECTED OUTPUT
\r
191 +cat <<EOF > head.c
\r
192 +#include <stdio.h>
\r
193 +#include <sys/types.h>
\r
194 +#include <sys/stat.h>
\r
195 +#include <fcntl.h>
\r
196 +#include <talloc.h>
\r
197 +#include <notmuch.h>
\r
199 +int main (int argc, char** argv)
\r
201 + notmuch_database_t *db;
\r
202 + notmuch_status_t stat;
\r
206 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
\r
207 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
208 + fprintf (stderr, "error opening database: %d\n", stat);
\r
210 + path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]);
\r
211 + fd = open(path,O_WRONLY|O_TRUNC);
\r
213 + fprintf (stderr, "error opening %s\n");
\r
215 +cat <<EOF > tail.c
\r
217 + const char *stat_str = notmuch_database_status_string (db);
\r
219 + fputs (stat_str, stderr);
\r
226 +test_begin_subtest "Xapian exception finding message"
\r
227 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
229 + notmuch_message_t *message = NULL;
\r
230 + stat = notmuch_database_find_message (db, "id:nonexistant", &message);
\r
233 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
234 +cat <<EOF >EXPECTED
\r
237 +A Xapian exception occurred finding message
\r
239 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
243 +test_begin_subtest "Xapian exception getting tags"
\r
244 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
246 + notmuch_tags_t *tags = NULL;
\r
247 + tags = notmuch_database_get_all_tags (db);
\r
248 + stat = (tags == NULL);
\r
251 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
252 +cat <<EOF >EXPECTED
\r
255 +A Xapian exception occurred getting tags
\r
257 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
261 +test_begin_subtest "Xapian exception creating directory"
\r
262 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
264 + notmuch_directory_t *directory = NULL;
\r
265 + stat = notmuch_database_get_directory (db, "none/existing", &directory);
\r
268 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
269 +cat <<EOF >EXPECTED
\r
272 +A Xapian exception occurred creating a directory
\r
274 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
278 +test_begin_subtest "Xapian exception searching messages"
\r
279 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
281 + notmuch_messages_t *messages = NULL;
\r
282 + notmuch_query_t *query=notmuch_query_create (db, "*");
\r
283 + stat = notmuch_query_search_messages_st (query, &messages);
\r
286 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
287 +cat <<EOF >EXPECTED
\r
290 +A Xapian exception occurred performing query
\r
291 +Query string was: *
\r
293 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
297 +test_begin_subtest "Xapian exception counting messages"
\r
298 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
300 + notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
\r
301 + int count = notmuch_query_count_messages (query);
\r
302 + stat = (count == 0);
\r
305 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
306 +cat <<EOF >EXPECTED
\r
309 +A Xapian exception occurred performing query
\r
310 +Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
\r
312 +test_expect_equal_file EXPECTED OUTPUT.clean
\r