2 test_description="error reporting for library"
4 . $(dirname "$0")/test-lib.sh || exit 1
8 test_begin_subtest "building database"
9 test_expect_success "NOTMUCH_NEW"
11 test_begin_subtest "Open null pointer"
15 int main (int argc, char** argv)
17 notmuch_database_t *db;
18 notmuch_status_t stat;
20 stat = notmuch_database_open_with_config (NULL,
21 NOTMUCH_DATABASE_MODE_READ_ONLY,
23 if (msg) fputs (msg, stderr);
29 Error: could not locate database.
31 test_expect_equal_file EXPECTED OUTPUT
33 test_begin_subtest "Open relative path"
37 int main (int argc, char** argv)
39 notmuch_database_t *db;
40 notmuch_status_t stat;
42 stat = notmuch_database_open_with_config ("./nonexistent/foo",
43 NOTMUCH_DATABASE_MODE_READ_ONLY,
45 if (msg) fputs (msg, stderr);
51 Error: Database path must be absolute.
53 test_expect_equal_file EXPECTED OUTPUT
55 test_begin_subtest "Create database in relative path"
59 int main (int argc, char** argv)
61 notmuch_database_t *db;
62 notmuch_status_t stat;
65 stat = notmuch_database_create_with_config ("./nonexistent/foo", "", NULL, &db, &msg);
66 if (msg) fputs (msg, stderr);
72 Error: Database path must be absolute.
74 test_expect_equal_file EXPECTED OUTPUT
76 test_begin_subtest "Open nonexistent database"
77 test_C ${PWD}/nonexistent/foo <<'EOF'
80 int main (int argc, char** argv)
82 notmuch_database_t *db;
83 notmuch_status_t stat;
85 stat = notmuch_database_open_with_config (argv[1],
86 NOTMUCH_DATABASE_MODE_READ_ONLY,
88 if (msg) fputs (msg, stderr);
94 Error: Cannot open database at CWD/nonexistent/foo: No such file or directory.
96 test_expect_equal_file EXPECTED OUTPUT
98 test_begin_subtest "create NULL path"
102 int main (int argc, char** argv)
104 notmuch_status_t stat;
107 stat = notmuch_database_create_with_config (NULL, "", NULL, NULL, &msg);
108 if (msg) fputs (msg, stderr);
111 cat <<'EOF' >EXPECTED
114 Error: could not locate database.
116 test_expect_equal_file EXPECTED OUTPUT
118 test_begin_subtest "Create database in nonexistent directory"
119 test_C ${PWD}/nonexistent/foo<<'EOF'
122 int main (int argc, char** argv)
124 notmuch_database_t *db;
125 notmuch_status_t stat;
128 stat = notmuch_database_create_with_config (argv[1], "", NULL, &db, &msg);
129 if (msg) fputs (msg, stderr);
132 cat <<'EOF' >EXPECTED
135 Error: Cannot open database at CWD/nonexistent/foo: No such file or directory.
137 test_expect_equal_file EXPECTED OUTPUT
139 test_begin_subtest "Write to read-only database"
140 test_C ${MAIL_DIR} <<'EOF'
143 int main (int argc, char** argv)
145 notmuch_database_t *db;
146 notmuch_status_t stat;
148 stat = notmuch_database_open_with_config (argv[1],
149 NOTMUCH_DATABASE_MODE_READ_ONLY,
150 "", NULL, &db, &msg);
151 if (msg) fputs (msg, stderr);
152 if (stat != NOTMUCH_STATUS_SUCCESS) {
153 fprintf (stderr, "error opening database: %d\n", stat);
155 stat = notmuch_database_index_file (db, "/dev/null", NULL, NULL);
157 fputs (notmuch_database_status_string (db), stderr);
161 cat <<'EOF' >EXPECTED
164 Cannot write to a read-only database.
166 test_expect_equal_file EXPECTED OUTPUT
168 test_begin_subtest "Add non-existent file"
169 test_C ${MAIL_DIR} <<'EOF'
172 int main (int argc, char** argv)
174 notmuch_database_t *db;
175 notmuch_status_t stat;
176 stat = notmuch_database_open_with_config (argv[1],
177 NOTMUCH_DATABASE_MODE_READ_WRITE,
178 "", NULL, &db, NULL);
179 if (stat != NOTMUCH_STATUS_SUCCESS) {
180 fprintf (stderr, "error opening database: %d\n", stat);
182 stat = notmuch_database_index_file (db, "./nonexistent", NULL, NULL);
184 char *status_string = notmuch_database_status_string (db);
185 if (status_string) fputs (status_string, stderr);
189 cat <<'EOF' >EXPECTED
192 Error opening ./nonexistent: No such file or directory
194 test_expect_equal_file EXPECTED OUTPUT
196 test_begin_subtest "compact, overwriting existing backup"
197 test_C ${MAIL_DIR} <<'EOF'
201 status_cb (const char *msg, void *closure)
203 printf ("%s\n", msg);
205 int main (int argc, char** argv)
207 notmuch_database_t *db;
208 notmuch_status_t stat;
209 stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
212 cat <<'EOF' >EXPECTED
214 Path already exists: MAIL_DIR
218 test_expect_equal_file EXPECTED OUTPUT
222 #include <sys/types.h>
223 #include <sys/stat.h>
228 int main (int argc, char** argv)
230 notmuch_database_t *db;
231 notmuch_status_t stat;
236 stat = notmuch_database_open_with_config (argv[1],
237 NOTMUCH_DATABASE_MODE_READ_WRITE,
238 NULL, NULL, &db, &msg);
239 if (stat != NOTMUCH_STATUS_SUCCESS) {
240 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
243 fd = open(argv[2],O_WRONLY|O_TRUNC);
245 fprintf (stderr, "error opening %s\n", argv[1]);
251 const char *stat_str = notmuch_database_status_string (db);
253 fputs (stat_str, stderr);
259 POSTLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/postlist.*)
261 test_begin_subtest "Xapian exception finding message"
262 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
264 notmuch_message_t *message = NULL;
265 stat = notmuch_database_find_message (db, "id:nonexistent", &message);
268 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
269 cat <<'EOF' >EXPECTED
272 A Xapian exception occurred finding message
274 test_expect_equal_file EXPECTED OUTPUT.clean
278 test_begin_subtest "Xapian exception creating directory"
279 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
281 notmuch_directory_t *directory = NULL;
282 stat = notmuch_database_get_directory (db, "none/existing", &directory);
285 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
286 cat <<'EOF' >EXPECTED
289 A Xapian exception occurred finding/creating a directory
291 test_expect_equal_file EXPECTED OUTPUT.clean
295 test_begin_subtest "Xapian exception searching messages"
296 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
298 notmuch_messages_t *messages = NULL;
299 notmuch_query_t *query=notmuch_query_create (db, "*");
300 stat = notmuch_query_search_messages (query, &messages);
303 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
304 cat <<'EOF' >EXPECTED
307 A Xapian exception occurred performing query
310 test_expect_equal_file EXPECTED OUTPUT.clean
314 test_begin_subtest "Xapian exception counting messages"
315 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
318 notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
319 stat = notmuch_query_count_messages (query, &count);
322 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
323 cat <<'EOF' >EXPECTED
326 A Xapian exception occurred performing query
327 Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
329 test_expect_equal_file EXPECTED OUTPUT.clean