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 C6889431E62
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:25:14 -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 F+XJB1qPsWwq for <notmuch@notmuchmail.org>;
\r
16 Tue, 24 Mar 2015 06:25:11 -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 26C44431FD2
\r
22 for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:25:11 -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 1YaOon-0000rq-Pd; Tue, 24 Mar 2015 13:24:29 +0000
\r
26 Received: (nullmailer pid 2634 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: Update to library logging, version 5
\r
31 Date: Tue, 24 Mar 2015 09:24:03 -0400
\r
32 Message-Id: <1427203451-1540-1-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 2.1.4
\r
34 In-Reply-To: <1426352554-4383-10-git-send-email-david@tethera.net>
\r
35 References: <1426352554-4383-10-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: Tue, 24 Mar 2015 13:25:15 -0000
\r
50 This takes into account (most of) Tomi's comments and adds a bunch
\r
51 more tests. We bikeshedded a bit about log_to_string on IRC, and
\r
52 eventually convered on eliminating it. I guess it might be necessary
\r
53 to add a compat version of asprintf for some environments (Solaris?)
\r
54 but this is easy enough using talloc_asprintf and strdup
\r
56 Here is the diff between the two versions
\r
58 diff --git a/lib/database.cc b/lib/database.cc
\r
59 index b5f3549..85054df 100644
\r
60 --- a/lib/database.cc
\r
61 +++ b/lib/database.cc
\r
62 @@ -348,35 +348,6 @@ notmuch_status_to_string (notmuch_status_t status)
\r
67 -vlog_to_string (void *ctx,
\r
68 - char **status_string,
\r
69 - const char *format,
\r
72 - if (!status_string)
\r
75 - if (*status_string)
\r
76 - talloc_free (*status_string);
\r
78 - *status_string = talloc_vasprintf (ctx, format, va_args);
\r
82 -log_to_string (char **str,
\r
83 - const char *format,
\r
88 - va_start (va_args, format);
\r
90 - vlog_to_string (NULL, str, format, va_args);
\r
96 _notmuch_database_log (notmuch_database_t *notmuch,
\r
98 @@ -386,7 +357,10 @@ _notmuch_database_log (notmuch_database_t *notmuch,
\r
100 va_start (va_args, format);
\r
102 - vlog_to_string (notmuch, ¬much->status_string, format, va_args);
\r
103 + if (notmuch->status_string)
\r
104 + talloc_free (notmuch->status_string);
\r
106 + notmuch->status_string = talloc_vasprintf (notmuch, format, va_args);
\r
110 @@ -667,22 +641,23 @@ notmuch_database_create_verbose (const char *path,
\r
113 if (path == NULL) {
\r
114 - log_to_string (&message, "Error: Cannot create a database for a NULL path.\n");
\r
115 + message = strdup ("Error: Cannot create a database for a NULL path.\n");
\r
116 status = NOTMUCH_STATUS_NULL_POINTER;
\r
120 err = stat (path, &st);
\r
122 - log_to_string (&message, "Error: Cannot create database at %s: %s.\n",
\r
123 - path, strerror (errno));
\r
124 + IGNORE_RESULT (asprintf (&message, "Error: Cannot create database at %s: %s.\n",
\r
125 + path, strerror (errno)));
\r
126 status = NOTMUCH_STATUS_FILE_ERROR;
\r
130 if (! S_ISDIR (st.st_mode)) {
\r
131 - log_to_string (&message, "Error: Cannot create database at %s: Not a directory.\n",
\r
133 + IGNORE_RESULT (asprintf (&message, "Error: Cannot create database at %s: "
\r
134 + "Not a directory.\n",
\r
136 status = NOTMUCH_STATUS_FILE_ERROR;
\r
139 @@ -692,8 +667,8 @@ notmuch_database_create_verbose (const char *path,
\r
140 err = mkdir (notmuch_path, 0755);
\r
143 - log_to_string (&message, "Error: Cannot create directory %s: %s.\n",
\r
144 - notmuch_path, strerror (errno));
\r
145 + IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n",
\r
146 + notmuch_path, strerror (errno)));
\r
147 status = NOTMUCH_STATUS_FILE_ERROR;
\r
150 @@ -720,7 +695,7 @@ notmuch_database_create_verbose (const char *path,
\r
151 talloc_free (notmuch_path);
\r
154 - *status_string = strdup(message);
\r
155 + *status_string = message;
\r
157 *database = notmuch;
\r
159 @@ -849,27 +824,27 @@ notmuch_database_open_verbose (const char *path,
\r
160 static int initialized = 0;
\r
162 if (path == NULL) {
\r
163 - log_to_string (&message, "Error: Cannot open a database for a NULL path.\n");
\r
164 + message = strdup ("Error: Cannot open a database for a NULL path.\n");
\r
165 status = NOTMUCH_STATUS_NULL_POINTER;
\r
169 if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
\r
170 - log_to_string (&message, "Out of memory\n");
\r
171 + message = strdup ("Out of memory\n");
\r
172 status = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
176 err = stat (notmuch_path, &st);
\r
178 - log_to_string (&message, "Error opening database at %s: %s\n",
\r
179 - notmuch_path, strerror (errno));
\r
180 + IGNORE_RESULT (asprintf (&message, "Error opening database at %s: %s\n",
\r
181 + notmuch_path, strerror (errno)));
\r
182 status = NOTMUCH_STATUS_FILE_ERROR;
\r
186 if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {
\r
187 - log_to_string (&message, "Out of memory\n");
\r
188 + message = strdup ("Out of memory\n");
\r
189 status = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
192 @@ -910,11 +885,11 @@ notmuch_database_open_verbose (const char *path,
\r
193 * means a dramatically incompatible change. */
\r
194 version = notmuch_database_get_version (notmuch);
\r
195 if (version > NOTMUCH_DATABASE_VERSION) {
\r
196 - log_to_string (&message,
\r
197 - "Error: Notmuch database at %s\n"
\r
198 - " has a newer database format version (%u) than supported by this\n"
\r
199 - " version of notmuch (%u).\n",
\r
200 - notmuch_path, version, NOTMUCH_DATABASE_VERSION);
\r
201 + IGNORE_RESULT (asprintf (&message,
\r
202 + "Error: Notmuch database at %s\n"
\r
203 + " has a newer database format version (%u) than supported by this\n"
\r
204 + " version of notmuch (%u).\n",
\r
205 + notmuch_path, version, NOTMUCH_DATABASE_VERSION));
\r
206 notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
\r
207 notmuch_database_destroy (notmuch);
\r
209 @@ -929,11 +904,11 @@ notmuch_database_open_verbose (const char *path,
\r
210 version, mode == NOTMUCH_DATABASE_MODE_READ_WRITE ? 'w' : 'r',
\r
211 &incompat_features);
\r
212 if (incompat_features) {
\r
213 - log_to_string (&message,
\r
214 - "Error: Notmuch database at %s\n"
\r
215 - " requires features (%s)\n"
\r
216 - " not supported by this version of notmuch.\n",
\r
217 - notmuch_path, incompat_features);
\r
218 + IGNORE_RESULT (asprintf (&message,
\r
219 + "Error: Notmuch database at %s\n"
\r
220 + " requires features (%s)\n"
\r
221 + " not supported by this version of notmuch.\n",
\r
222 + notmuch_path, incompat_features));
\r
223 notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
\r
224 notmuch_database_destroy (notmuch);
\r
226 @@ -979,8 +954,8 @@ notmuch_database_open_verbose (const char *path,
\r
227 notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);
\r
229 } catch (const Xapian::Error &error) {
\r
230 - log_to_string (&message, "A Xapian exception occurred opening database: %s\n",
\r
231 - error.get_msg().c_str());
\r
232 + IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
\r
233 + error.get_msg().c_str()));
\r
234 notmuch_database_destroy (notmuch);
\r
236 status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
237 @@ -990,7 +965,7 @@ notmuch_database_open_verbose (const char *path,
\r
238 talloc_free (local);
\r
240 if (status_string && message)
\r
241 - *status_string = strdup (message);
\r
242 + *status_string = message;
\r
245 *database = notmuch;
\r
246 diff --git a/lib/query.cc b/lib/query.cc
\r
247 index 7b59786..9cedb6a 100644
\r
250 @@ -296,9 +296,12 @@ notmuch_query_search_messages_st (notmuch_query_t *query,
\r
251 return NOTMUCH_STATUS_SUCCESS;
\r
253 } catch (const Xapian::Error &error) {
\r
254 - _notmuch_database_log (notmuch, "A Xapian exception occurred performing query: %s\n",
\r
255 - error.get_msg().c_str());
\r
256 - _notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);
\r
257 + _notmuch_database_log (notmuch,
\r
258 + "A Xapian exception occurred performing query: %s\n"
\r
259 + "Query string was: %s\n",
\r
260 + error.get_msg().c_str(),
\r
261 + query->query_string);
\r
263 notmuch->exception_reported = TRUE;
\r
264 talloc_free (messages);
\r
265 return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
266 @@ -597,9 +600,12 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
267 count = mset.get_matches_estimated();
\r
269 } catch (const Xapian::Error &error) {
\r
270 - _notmuch_database_log (notmuch, "A Xapian exception occurred: %s\n",
\r
271 - error.get_msg().c_str());
\r
272 - _notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);
\r
273 + _notmuch_database_log (notmuch,
\r
274 + "A Xapian exception occurred performing query: %s\n"
\r
275 + "Query string was: %s\n",
\r
276 + error.get_msg().c_str(),
\r
277 + query->query_string);
\r
282 diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
\r
283 index 7621e7f..ec7552a 100755
\r
284 --- a/test/T560-lib-error.sh
\r
285 +++ b/test/T560-lib-error.sh
\r
286 @@ -3,6 +3,16 @@ test_description="error reporting for library"
\r
290 +backup_database (){
\r
291 + rm -rf notmuch-dir-backup
\r
292 + cp -a ${MAIL_DIR}/.notmuch notmuch-dir-backup
\r
294 +restore_database (){
\r
295 + rm -rf ${MAIL_DIR}/.notmuch
\r
296 + cp -a notmuch-dir-backup ${MAIL_DIR}/.notmuch
\r
302 test_expect_success "building database" "NOTMUCH_NEW"
\r
303 @@ -68,6 +78,31 @@ Cannot write to a read-only database.
\r
305 test_expect_equal_file EXPECTED OUTPUT
\r
307 +test_begin_subtest "Add non-existent file"
\r
308 +test_C ${MAIL_DIR} <<EOF
\r
309 +#include <stdio.h>
\r
310 +#include <notmuch.h>
\r
311 +int main (int argc, char** argv)
\r
313 + notmuch_database_t *db;
\r
314 + notmuch_status_t stat;
\r
315 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
\r
316 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
317 + fprintf (stderr, "error opening database: %d\n", stat);
\r
319 + stat = notmuch_database_add_message (db, "/nonexistent", NULL);
\r
321 + fputs (notmuch_database_status_string (db), stderr);
\r
325 +cat <<EOF >EXPECTED
\r
328 +Error opening /nonexistent: No such file or directory
\r
330 +test_expect_equal_file EXPECTED OUTPUT
\r
332 test_begin_subtest "compact, overwriting existing backup"
\r
333 test_C ${MAIL_DIR} <<EOF
\r
335 @@ -92,4 +127,128 @@ Path already exists: CWD/mail
\r
337 test_expect_equal_file EXPECTED OUTPUT
\r
339 +cat <<EOF > head.c
\r
340 +#include <stdio.h>
\r
341 +#include <sys/types.h>
\r
342 +#include <sys/stat.h>
\r
343 +#include <fcntl.h>
\r
344 +#include <talloc.h>
\r
345 +#include <notmuch.h>
\r
347 +int main (int argc, char** argv)
\r
349 + notmuch_database_t *db;
\r
350 + notmuch_status_t stat;
\r
354 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
\r
355 + if (stat != NOTMUCH_STATUS_SUCCESS) {
\r
356 + fprintf (stderr, "error opening database: %d\n", stat);
\r
358 + path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]);
\r
359 + fd = open(path,O_WRONLY|O_TRUNC);
\r
361 + fprintf (stderr, "error opening %s\n");
\r
363 +cat <<EOF > tail.c
\r
365 + const char *stat_str = notmuch_database_status_string (db);
\r
367 + fputs (stat_str, stderr);
\r
374 +test_begin_subtest "Xapian exception finding message"
\r
375 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
377 + notmuch_message_t *message = NULL;
\r
378 + stat = notmuch_database_find_message (db, "id:nonexistant", &message);
\r
381 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
382 +cat <<EOF >EXPECTED
\r
385 +A Xapian exception occurred finding message
\r
387 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
391 +test_begin_subtest "Xapian exception getting tags"
\r
392 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
394 + notmuch_tags_t *tags = NULL;
\r
395 + tags = notmuch_database_get_all_tags (db);
\r
396 + stat = (tags == NULL);
\r
399 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
400 +cat <<EOF >EXPECTED
\r
403 +A Xapian exception occurred getting tags
\r
405 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
409 +test_begin_subtest "Xapian exception creating directory"
\r
410 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
412 + notmuch_directory_t *directory = NULL;
\r
413 + stat = notmuch_database_get_directory (db, "none/existing", &directory);
\r
416 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
417 +cat <<EOF >EXPECTED
\r
420 +A Xapian exception occurred creating a directory
\r
422 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
426 +test_begin_subtest "Xapian exception searching messages"
\r
427 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
429 + notmuch_messages_t *messages = NULL;
\r
430 + notmuch_query_t *query=notmuch_query_create (db, "*");
\r
431 + stat = notmuch_query_search_messages_st (query, &messages);
\r
434 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
435 +cat <<EOF >EXPECTED
\r
438 +A Xapian exception occurred performing query
\r
439 +Query string was: *
\r
441 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
445 +test_begin_subtest "Xapian exception counting messages"
\r
446 +cat head.c - tail.c <<EOF | test_C ${MAIL_DIR}
\r
448 + notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
\r
449 + int count = notmuch_query_count_messages (query);
\r
450 + stat = (count == 0);
\r
453 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
454 +cat <<EOF >EXPECTED
\r
457 +A Xapian exception occurred performing query
\r
458 +Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
\r
460 +test_expect_equal_file EXPECTED OUTPUT.clean
\r
464 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
465 index c7af003..fdb84ea 100644
\r
466 --- a/test/test-lib.sh
\r
467 +++ b/test/test-lib.sh
\r
468 @@ -1163,16 +1163,16 @@ test_python() {
\r
473 - test_file="test${test_count}.c"
\r
474 - exec_file=${test_file%%.c}
\r
476 + exec_file="test${test_count}"
\r
477 + test_file="${exec_file}.c"
\r
479 export LD_LIBRARY_PATH=${TEST_DIRECTORY}/../lib
\r
480 - ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch
\r
481 + ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
\r
482 echo "== stdout ==" > OUTPUT.stdout
\r
483 echo "== stderr ==" > OUTPUT.stderr
\r
484 ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
\r
485 - cat OUTPUT.stdout OUTPUT.stderr | sed "s,$(pwd),CWD," > OUTPUT
\r
486 + sed "s,$(pwd),CWD," OUTPUT.stdout OUTPUT.stderr > OUTPUT
\r