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;
19 stat = notmuch_database_open (NULL, 0, 0);
25 Error: Cannot open a database for a NULL path.
27 test_expect_equal_file EXPECTED OUTPUT
29 test_begin_subtest "Open relative path"
33 int main (int argc, char** argv)
35 notmuch_database_t *db;
36 notmuch_status_t stat;
37 stat = notmuch_database_open ("./nonexistent/foo", 0, 0);
43 Error: Database path must be absolute.
45 test_expect_equal_file EXPECTED OUTPUT
47 test_begin_subtest "Create database in relative path"
51 int main (int argc, char** argv)
53 notmuch_database_t *db;
54 notmuch_status_t stat;
55 stat = notmuch_database_create ("./nonexistent/foo", &db);
61 Error: Database path must be absolute.
63 test_expect_equal_file EXPECTED OUTPUT
65 test_begin_subtest "Open nonexistent database"
66 test_C ${PWD}/nonexistent/foo <<'EOF'
69 int main (int argc, char** argv)
71 notmuch_database_t *db;
72 notmuch_status_t stat;
73 stat = notmuch_database_open (argv[1], 0, 0);
79 Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory
81 test_expect_equal_file EXPECTED OUTPUT
83 test_begin_subtest "create NULL path"
87 int main (int argc, char** argv)
89 notmuch_status_t stat;
90 stat = notmuch_database_create (NULL, NULL);
96 Error: Cannot create a database for a NULL path.
98 test_expect_equal_file EXPECTED OUTPUT
100 test_begin_subtest "Create database in nonexistent directory"
101 test_C ${PWD}/nonexistent/foo<<'EOF'
104 int main (int argc, char** argv)
106 notmuch_database_t *db;
107 notmuch_status_t stat;
108 stat = notmuch_database_create (argv[1], &db);
111 cat <<'EOF' >EXPECTED
114 Error: Cannot create database at CWD/nonexistent/foo: No such file or directory.
116 test_expect_equal_file EXPECTED OUTPUT
118 test_begin_subtest "Write to read-only database"
119 test_C ${MAIL_DIR} <<'EOF'
122 int main (int argc, char** argv)
124 notmuch_database_t *db;
125 notmuch_status_t stat;
126 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
127 if (stat != NOTMUCH_STATUS_SUCCESS) {
128 fprintf (stderr, "error opening database: %d\n", stat);
130 stat = notmuch_database_index_file (db, "/dev/null", NULL, NULL);
132 fputs (notmuch_database_status_string (db), stderr);
136 cat <<'EOF' >EXPECTED
139 Cannot write to a read-only database.
141 test_expect_equal_file EXPECTED OUTPUT
143 test_begin_subtest "Add non-existent file"
144 test_C ${MAIL_DIR} <<'EOF'
147 int main (int argc, char** argv)
149 notmuch_database_t *db;
150 notmuch_status_t stat;
151 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
152 if (stat != NOTMUCH_STATUS_SUCCESS) {
153 fprintf (stderr, "error opening database: %d\n", stat);
155 stat = notmuch_database_index_file (db, "./nonexistent", NULL, NULL);
157 char *status_string = notmuch_database_status_string (db);
158 if (status_string) fputs (status_string, stderr);
162 cat <<'EOF' >EXPECTED
165 Error opening ./nonexistent: No such file or directory
167 test_expect_equal_file EXPECTED OUTPUT
169 test_begin_subtest "compact, overwriting existing backup"
170 test_C ${MAIL_DIR} <<'EOF'
174 status_cb (const char *msg, void *closure)
176 printf ("%s\n", msg);
178 int main (int argc, char** argv)
180 notmuch_database_t *db;
181 notmuch_status_t stat;
182 stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
185 cat <<'EOF' >EXPECTED
187 Path already exists: MAIL_DIR
191 test_expect_equal_file EXPECTED OUTPUT
195 #include <sys/types.h>
196 #include <sys/stat.h>
201 int main (int argc, char** argv)
203 notmuch_database_t *db;
204 notmuch_status_t stat;
209 stat = notmuch_database_open_verbose (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db, &msg);
210 if (stat != NOTMUCH_STATUS_SUCCESS) {
211 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
214 path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.${db_ending}", argv[1]);
215 fd = open(path,O_WRONLY|O_TRUNC);
217 fprintf (stderr, "error opening %s\n", argv[1]);
223 const char *stat_str = notmuch_database_status_string (db);
225 fputs (stat_str, stderr);
232 test_begin_subtest "Xapian exception finding message"
233 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
235 notmuch_message_t *message = NULL;
236 stat = notmuch_database_find_message (db, "id:nonexistent", &message);
239 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
240 cat <<'EOF' >EXPECTED
243 A Xapian exception occurred finding message
245 test_expect_equal_file EXPECTED OUTPUT.clean
249 test_begin_subtest "Xapian exception getting tags"
250 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
252 notmuch_tags_t *tags = NULL;
253 tags = notmuch_database_get_all_tags (db);
254 stat = (tags == NULL);
257 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
258 cat <<'EOF' >EXPECTED
261 A Xapian exception occurred getting tags
263 test_expect_equal_file EXPECTED OUTPUT.clean
267 test_begin_subtest "Xapian exception creating directory"
268 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
270 notmuch_directory_t *directory = NULL;
271 stat = notmuch_database_get_directory (db, "none/existing", &directory);
274 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
275 cat <<'EOF' >EXPECTED
278 A Xapian exception occurred creating a directory
280 test_expect_equal_file EXPECTED OUTPUT.clean
284 test_begin_subtest "Xapian exception searching messages"
285 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
287 notmuch_messages_t *messages = NULL;
288 notmuch_query_t *query=notmuch_query_create (db, "*");
289 stat = notmuch_query_search_messages (query, &messages);
292 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
293 cat <<'EOF' >EXPECTED
296 A Xapian exception occurred performing query
299 test_expect_equal_file EXPECTED OUTPUT.clean
303 test_begin_subtest "Xapian exception counting messages"
304 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
307 notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
308 stat = notmuch_query_count_messages (query, &count);
311 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
312 cat <<'EOF' >EXPECTED
315 A Xapian exception occurred performing query
316 Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
318 test_expect_equal_file EXPECTED OUTPUT.clean