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;
63 stat = notmuch_database_create ("./nonexistent/foo", &db);
69 Error: Database path must be absolute.
71 test_expect_equal_file EXPECTED OUTPUT
73 test_begin_subtest "Open nonexistent database"
74 test_C ${PWD}/nonexistent/foo <<'EOF'
77 int main (int argc, char** argv)
79 notmuch_database_t *db;
80 notmuch_status_t stat;
82 stat = notmuch_database_open_with_config (argv[1],
83 NOTMUCH_DATABASE_MODE_READ_ONLY,
85 if (msg) fputs (msg, stderr);
91 Error: Cannot open database at CWD/nonexistent/foo: No such file or directory.
93 test_expect_equal_file EXPECTED OUTPUT
95 test_begin_subtest "create NULL path"
99 int main (int argc, char** argv)
101 notmuch_status_t stat;
102 stat = notmuch_database_create (NULL, NULL);
105 cat <<'EOF' >EXPECTED
108 Error: could not locate database.
110 test_expect_equal_file EXPECTED OUTPUT
112 test_begin_subtest "Create database in nonexistent directory"
113 test_C ${PWD}/nonexistent/foo<<'EOF'
116 int main (int argc, char** argv)
118 notmuch_database_t *db;
119 notmuch_status_t stat;
120 stat = notmuch_database_create (argv[1], &db);
123 cat <<'EOF' >EXPECTED
126 Error: Cannot open database at CWD/nonexistent/foo: No such file or directory.
128 test_expect_equal_file EXPECTED OUTPUT
130 test_begin_subtest "Write to read-only database"
131 test_C ${MAIL_DIR} <<'EOF'
134 int main (int argc, char** argv)
136 notmuch_database_t *db;
137 notmuch_status_t stat;
139 stat = notmuch_database_open_with_config (argv[1],
140 NOTMUCH_DATABASE_MODE_READ_ONLY,
141 "", NULL, &db, &msg);
142 if (msg) fputs (msg, stderr);
143 if (stat != NOTMUCH_STATUS_SUCCESS) {
144 fprintf (stderr, "error opening database: %d\n", stat);
146 stat = notmuch_database_index_file (db, "/dev/null", NULL, NULL);
148 fputs (notmuch_database_status_string (db), stderr);
152 cat <<'EOF' >EXPECTED
155 Cannot write to a read-only database.
157 test_expect_equal_file EXPECTED OUTPUT
159 test_begin_subtest "Add non-existent file"
160 test_C ${MAIL_DIR} <<'EOF'
163 int main (int argc, char** argv)
165 notmuch_database_t *db;
166 notmuch_status_t stat;
167 stat = notmuch_database_open_with_config (argv[1],
168 NOTMUCH_DATABASE_MODE_READ_WRITE,
169 "", NULL, &db, NULL);
170 if (stat != NOTMUCH_STATUS_SUCCESS) {
171 fprintf (stderr, "error opening database: %d\n", stat);
173 stat = notmuch_database_index_file (db, "./nonexistent", NULL, NULL);
175 char *status_string = notmuch_database_status_string (db);
176 if (status_string) fputs (status_string, stderr);
180 cat <<'EOF' >EXPECTED
183 Error opening ./nonexistent: No such file or directory
185 test_expect_equal_file EXPECTED OUTPUT
187 test_begin_subtest "compact, overwriting existing backup"
188 test_C ${MAIL_DIR} <<'EOF'
192 status_cb (const char *msg, void *closure)
194 printf ("%s\n", msg);
196 int main (int argc, char** argv)
198 notmuch_database_t *db;
199 notmuch_status_t stat;
200 stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
203 cat <<'EOF' >EXPECTED
205 Path already exists: MAIL_DIR
209 test_expect_equal_file EXPECTED OUTPUT
213 #include <sys/types.h>
214 #include <sys/stat.h>
219 int main (int argc, char** argv)
221 notmuch_database_t *db;
222 notmuch_status_t stat;
227 stat = notmuch_database_open_with_config (argv[1],
228 NOTMUCH_DATABASE_MODE_READ_WRITE,
229 NULL, NULL, &db, &msg);
230 if (stat != NOTMUCH_STATUS_SUCCESS) {
231 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
234 fd = open(argv[2],O_WRONLY|O_TRUNC);
236 fprintf (stderr, "error opening %s\n", argv[1]);
242 const char *stat_str = notmuch_database_status_string (db);
244 fputs (stat_str, stderr);
250 POSTLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/postlist.*)
252 test_begin_subtest "Xapian exception finding message"
253 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
255 notmuch_message_t *message = NULL;
256 stat = notmuch_database_find_message (db, "id:nonexistent", &message);
259 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
260 cat <<'EOF' >EXPECTED
263 A Xapian exception occurred finding message
265 test_expect_equal_file EXPECTED OUTPUT.clean
269 test_begin_subtest "Xapian exception getting tags"
270 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
272 notmuch_tags_t *tags = NULL;
273 tags = notmuch_database_get_all_tags (db);
274 stat = (tags == NULL);
277 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
278 cat <<'EOF' >EXPECTED
281 A Xapian exception occurred getting tags
283 test_expect_equal_file EXPECTED OUTPUT.clean
287 test_begin_subtest "Xapian exception creating directory"
288 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
290 notmuch_directory_t *directory = NULL;
291 stat = notmuch_database_get_directory (db, "none/existing", &directory);
294 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
295 cat <<'EOF' >EXPECTED
298 A Xapian exception occurred finding/creating a directory
300 test_expect_equal_file EXPECTED OUTPUT.clean
304 test_begin_subtest "Xapian exception searching messages"
305 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
307 notmuch_messages_t *messages = NULL;
308 notmuch_query_t *query=notmuch_query_create (db, "*");
309 stat = notmuch_query_search_messages (query, &messages);
312 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
313 cat <<'EOF' >EXPECTED
316 A Xapian exception occurred performing query
319 test_expect_equal_file EXPECTED OUTPUT.clean
323 test_begin_subtest "Xapian exception counting messages"
324 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
327 notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
328 stat = notmuch_query_count_messages (query, &count);
331 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
332 cat <<'EOF' >EXPECTED
335 A Xapian exception occurred performing query
336 Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
338 test_expect_equal_file EXPECTED OUTPUT.clean