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 DD807429E28
\r
6 for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:14:01 -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=disabled
\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 Z89IAR3c7jBM for <notmuch@notmuchmail.org>;
\r
16 Fri, 27 Mar 2015 15:14:00 -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 046AF429E26
\r
22 for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:14:00 -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 1YbcV9-0000Et-L1; Fri, 27 Mar 2015 22:13:15 +0000
\r
26 Received: (nullmailer pid 1811 invoked by uid 1000); Fri, 27 Mar 2015
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [Patch v6 3/8] test: add error reporting tests
\r
31 Date: Fri, 27 Mar 2015 23:11:55 +0100
\r
32 Message-Id: <1427494320-1483-4-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 2.1.4
\r
34 In-Reply-To: <1427494320-1483-1-git-send-email-david@tethera.net>
\r
35 References: <1427494320-1483-1-git-send-email-david@tethera.net>
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.13
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Fri, 27 Mar 2015 22:14:02 -0000
\r
50 This includes tests for all of the error fprintfs in the library I
\r
51 could figure out how to test without using gdb scripts. It boils down
\r
52 to errors opening files and exceptions caused by corrupted Xapian
\r
55 test/T560-lib-error.sh | 285 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
56 1 file changed, 285 insertions(+)
\r
57 create mode 100755 test/T560-lib-error.sh
\r
59 diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
\r
60 new file mode 100755
\r
61 index 0000000..f1ca543
\r
63 +++ b/test/T560-lib-error.sh
\r
65 +#!/usr/bin/env bash
\r
66 +test_description="error reporting for library"
\r
70 +backup_database () {
\r
71 + rm -rf notmuch-dir-backup
\r
72 + cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup
\r
74 +restore_database () {
\r
75 + rm -rf ${MAIL_DIR}/.notmuch
\r
76 + cp -pR notmuch-dir-backup ${MAIL_DIR}/.notmuch
\r
82 +test_expect_success "building database" "NOTMUCH_NEW"
\r
84 +test_begin_subtest "Open null pointer"
\r
87 +#include <notmuch.h>
\r
88 +int main (int argc, char** argv)
\r
90 + notmuch_database_t *db;
\r
91 + notmuch_status_t stat;
\r
92 + stat = notmuch_database_open (NULL, 0, 0);
\r
95 +cat <<'EOF' >EXPECTED
\r
98 +Error: Cannot open a database for a NULL path.
\r
100 +test_expect_equal_file EXPECTED OUTPUT
\r
102 +test_begin_subtest "Open nonexistent database"
\r
104 +#include <stdio.h>
\r
105 +#include <notmuch.h>
\r
106 +int main (int argc, char** argv)
\r
108 + notmuch_database_t *db;
\r
109 + notmuch_status_t stat;
\r
110 + stat = notmuch_database_open ("/nonexistent/foo", 0, 0);
\r
113 +cat <<'EOF' >EXPECTED
\r
116 +Error opening database at /nonexistent/foo/.notmuch: No such file or directory
\r
118 +test_expect_equal_file EXPECTED OUTPUT
\r
120 +test_begin_subtest "create NULL path"
\r
122 +#include <stdio.h>
\r
123 +#include <notmuch.h>
\r
124 +int main (int argc, char** argv)
\r
126 + notmuch_status_t stat;
\r
127 + stat = notmuch_database_create (NULL, NULL);
\r
130 +cat <<'EOF' >EXPECTED
\r
133 +Error: Cannot create a database for a NULL path.
\r
135 +test_expect_equal_file EXPECTED OUTPUT
\r
137 +test_begin_subtest "Create database in non-existant directory"
\r
139 +#include <stdio.h>
\r
140 +#include <notmuch.h>
\r
141 +int main (int argc, char** argv)
\r
143 + notmuch_database_t *db;
\r
144 + notmuch_status_t stat;
\r
145 + stat = notmuch_database_create ("/nonexistent/foo", &db);
\r
148 +cat <<'EOF' >EXPECTED
\r
151 +Error: Cannot create database at /nonexistent/foo: No such file or directory.
\r
153 +test_expect_equal_file EXPECTED OUTPUT
\r
155 +test_begin_subtest "Write to read-only database"
\r
156 +test_C ${MAIL_DIR} <<'EOF'
\r
157 +#include <stdio.h>
\r
158 +#include <notmuch.h>
\r
159 +int main (int argc, char** argv)
\r
161 + notmuch_database_t *db;
\r
162 + notmuch_status_t stat;
\r
163 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
\r
164 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
165 + fprintf (stderr, "error opening database: %d\n", stat);
\r
167 + stat = notmuch_database_add_message (db, "/dev/null", NULL);
\r
170 +cat <<'EOF' >EXPECTED
\r
173 +Cannot write to a read-only database.
\r
175 +test_expect_equal_file EXPECTED OUTPUT
\r
177 +test_begin_subtest "Add non-existent file"
\r
178 +test_C ${MAIL_DIR} <<'EOF'
\r
179 +#include <stdio.h>
\r
180 +#include <notmuch.h>
\r
181 +int main (int argc, char** argv)
\r
183 + notmuch_database_t *db;
\r
184 + notmuch_status_t stat;
\r
185 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
\r
186 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
187 + fprintf (stderr, "error opening database: %d\n", stat);
\r
189 + stat = notmuch_database_add_message (db, "/nonexistent", NULL);
\r
191 + fputs (notmuch_database_status_string (db), stderr);
\r
195 +cat <<'EOF' >EXPECTED
\r
198 +Error opening /nonexistent: No such file or directory
\r
200 +test_expect_equal_file EXPECTED OUTPUT
\r
202 +test_begin_subtest "compact, overwriting existing backup"
\r
203 +test_C ${MAIL_DIR} <<'EOF'
\r
204 +#include <stdio.h>
\r
205 +#include <notmuch.h>
\r
207 +status_cb (const char *msg, void *closure)
\r
209 + printf ("%s\n", msg);
\r
211 +int main (int argc, char** argv)
\r
213 + notmuch_database_t *db;
\r
214 + notmuch_status_t stat;
\r
215 + stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
\r
218 +cat <<'EOF' >EXPECTED
\r
221 +Path already exists: CWD/mail
\r
223 +test_expect_equal_file EXPECTED OUTPUT
\r
225 +cat <<'EOF' > c_head
\r
226 +#include <stdio.h>
\r
227 +#include <sys/types.h>
\r
228 +#include <sys/stat.h>
\r
229 +#include <fcntl.h>
\r
230 +#include <talloc.h>
\r
231 +#include <notmuch.h>
\r
233 +int main (int argc, char** argv)
\r
235 + notmuch_database_t *db;
\r
236 + notmuch_status_t stat;
\r
240 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
\r
241 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
242 + fprintf (stderr, "error opening database: %d\n", stat);
\r
244 + path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]);
\r
245 + fd = open(path,O_WRONLY|O_TRUNC);
\r
247 + fprintf (stderr, "error opening %s\n");
\r
249 +cat <<'EOF' > c_tail
\r
251 + const char *stat_str = notmuch_database_status_string (db);
\r
253 + fputs (stat_str, stderr);
\r
260 +test_begin_subtest "Xapian exception finding message"
\r
261 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
263 + notmuch_message_t *message = NULL;
\r
264 + stat = notmuch_database_find_message (db, "id:nonexistant", &message);
\r
267 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
268 +cat <<'EOF' >EXPECTED
\r
271 +A Xapian exception occurred finding message
\r
273 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
277 +test_begin_subtest "Xapian exception getting tags"
\r
278 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
280 + notmuch_tags_t *tags = NULL;
\r
281 + tags = notmuch_database_get_all_tags (db);
\r
282 + stat = (tags == NULL);
\r
285 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
286 +cat <<'EOF' >EXPECTED
\r
289 +A Xapian exception occurred getting tags
\r
291 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
295 +test_begin_subtest "Xapian exception creating directory"
\r
296 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
298 + notmuch_directory_t *directory = NULL;
\r
299 + stat = notmuch_database_get_directory (db, "none/existing", &directory);
\r
302 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
303 +cat <<'EOF' >EXPECTED
\r
306 +A Xapian exception occurred creating a directory
\r
308 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
312 +test_begin_subtest "Xapian exception searching messages"
\r
313 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
315 + notmuch_messages_t *messages = NULL;
\r
316 + notmuch_query_t *query=notmuch_query_create (db, "*");
\r
317 + stat = notmuch_query_search_messages_st (query, &messages);
\r
320 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
321 +cat <<'EOF' >EXPECTED
\r
324 +A Xapian exception occurred performing query
\r
325 +Query string was: *
\r
327 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
331 +test_begin_subtest "Xapian exception counting messages"
\r
332 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
334 + notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
\r
335 + int count = notmuch_query_count_messages (query);
\r
336 + stat = (count == 0);
\r
339 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
340 +cat <<'EOF' >EXPECTED
\r
343 +A Xapian exception occurred performing query
\r
344 +Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
\r
346 +test_expect_equal_file EXPECTED OUTPUT.clean
\r