2 test_description="error reporting for library"
7 rm -rf notmuch-dir-backup
8 cp -pR ${MAIL_DIR}/.notmuch notmuch-dir-backup
11 rm -rf ${MAIL_DIR}/.notmuch
12 cp -pR notmuch-dir-backup ${MAIL_DIR}/.notmuch
18 test_expect_success "building database" "NOTMUCH_NEW"
20 test_begin_subtest "Open null pointer"
24 int main (int argc, char** argv)
26 notmuch_database_t *db;
27 notmuch_status_t stat;
28 stat = notmuch_database_open (NULL, 0, 0);
34 Error: Cannot open a database for a NULL path.
36 test_expect_equal_file EXPECTED OUTPUT
38 test_begin_subtest "Open nonexistent database"
42 int main (int argc, char** argv)
44 notmuch_database_t *db;
45 notmuch_status_t stat;
46 stat = notmuch_database_open ("/nonexistent/foo", 0, 0);
52 Error opening database at /nonexistent/foo/.notmuch: No such file or directory
54 test_expect_equal_file EXPECTED OUTPUT
56 test_begin_subtest "create NULL path"
60 int main (int argc, char** argv)
62 notmuch_status_t stat;
63 stat = notmuch_database_create (NULL, NULL);
69 Error: Cannot create a database for a NULL path.
71 test_expect_equal_file EXPECTED OUTPUT
73 test_begin_subtest "Create database in non-existant directory"
77 int main (int argc, char** argv)
79 notmuch_database_t *db;
80 notmuch_status_t stat;
81 stat = notmuch_database_create ("/nonexistent/foo", &db);
87 Error: Cannot create database at /nonexistent/foo: No such file or directory.
89 test_expect_equal_file EXPECTED OUTPUT
91 test_begin_subtest "Write to read-only database"
92 test_C ${MAIL_DIR} <<'EOF'
95 int main (int argc, char** argv)
97 notmuch_database_t *db;
98 notmuch_status_t stat;
99 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
100 if (stat != NOTMUCH_STATUS_SUCCESS) {
101 fprintf (stderr, "error opening database: %d\n", stat);
103 stat = notmuch_database_add_message (db, "/dev/null", NULL);
105 fputs (notmuch_database_status_string (db), stderr);
109 cat <<'EOF' >EXPECTED
112 Cannot write to a read-only database.
114 test_expect_equal_file EXPECTED OUTPUT
116 test_begin_subtest "Add non-existent file"
117 test_C ${MAIL_DIR} <<'EOF'
120 int main (int argc, char** argv)
122 notmuch_database_t *db;
123 notmuch_status_t stat;
124 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
125 if (stat != NOTMUCH_STATUS_SUCCESS) {
126 fprintf (stderr, "error opening database: %d\n", stat);
128 stat = notmuch_database_add_message (db, "/nonexistent", NULL);
130 fputs (notmuch_database_status_string (db), stderr);
134 cat <<'EOF' >EXPECTED
137 Error opening /nonexistent: No such file or directory
139 test_expect_equal_file EXPECTED OUTPUT
141 test_begin_subtest "compact, overwriting existing backup"
142 test_C ${MAIL_DIR} <<'EOF'
146 status_cb (const char *msg, void *closure)
148 printf ("%s\n", msg);
150 int main (int argc, char** argv)
152 notmuch_database_t *db;
153 notmuch_status_t stat;
154 stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
157 cat <<'EOF' >EXPECTED
159 Path already exists: CWD/mail
163 test_expect_equal_file EXPECTED OUTPUT
167 #include <sys/types.h>
168 #include <sys/stat.h>
173 int main (int argc, char** argv)
175 notmuch_database_t *db;
176 notmuch_status_t stat;
180 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
181 if (stat != NOTMUCH_STATUS_SUCCESS) {
182 fprintf (stderr, "error opening database: %d\n", stat);
184 path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]);
185 fd = open(path,O_WRONLY|O_TRUNC);
187 fprintf (stderr, "error opening %s\n");
191 const char *stat_str = notmuch_database_status_string (db);
193 fputs (stat_str, stderr);
200 test_begin_subtest "Xapian exception finding message"
201 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
203 notmuch_message_t *message = NULL;
204 stat = notmuch_database_find_message (db, "id:nonexistant", &message);
207 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
208 cat <<'EOF' >EXPECTED
211 A Xapian exception occurred finding message
213 test_expect_equal_file EXPECTED OUTPUT.clean
217 test_begin_subtest "Xapian exception getting tags"
218 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
220 notmuch_tags_t *tags = NULL;
221 tags = notmuch_database_get_all_tags (db);
222 stat = (tags == NULL);
225 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
226 cat <<'EOF' >EXPECTED
229 A Xapian exception occurred getting tags
231 test_expect_equal_file EXPECTED OUTPUT.clean
235 test_begin_subtest "Xapian exception creating directory"
236 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
238 notmuch_directory_t *directory = NULL;
239 stat = notmuch_database_get_directory (db, "none/existing", &directory);
242 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
243 cat <<'EOF' >EXPECTED
246 A Xapian exception occurred creating a directory
248 test_expect_equal_file EXPECTED OUTPUT.clean
252 test_begin_subtest "Xapian exception searching messages"
253 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
255 notmuch_messages_t *messages = NULL;
256 notmuch_query_t *query=notmuch_query_create (db, "*");
257 stat = notmuch_query_search_messages_st (query, &messages);
260 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
261 cat <<'EOF' >EXPECTED
264 A Xapian exception occurred performing query
267 test_expect_equal_file EXPECTED OUTPUT.clean
271 test_begin_subtest "Xapian exception counting messages"
272 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
274 notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
275 int count = notmuch_query_count_messages (query);
279 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
280 cat <<'EOF' >EXPECTED
283 A Xapian exception occurred performing query
284 Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
286 test_expect_equal_file EXPECTED OUTPUT.clean