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 relative path"
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: Database path must be absolute.
54 test_expect_equal_file EXPECTED OUTPUT
56 test_begin_subtest "Create database in relative path"
60 int main (int argc, char** argv)
62 notmuch_database_t *db;
63 notmuch_status_t stat;
64 stat = notmuch_database_create ("./nonexistent/foo", &db);
70 Error: Database path must be absolute.
72 test_expect_equal_file EXPECTED OUTPUT
74 test_begin_subtest "Open nonexistent database"
75 test_C ${PWD}/nonexistent/foo <<'EOF'
78 int main (int argc, char** argv)
80 notmuch_database_t *db;
81 notmuch_status_t stat;
82 stat = notmuch_database_open (argv[1], 0, 0);
88 Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory
90 test_expect_equal_file EXPECTED OUTPUT
92 test_begin_subtest "create NULL path"
96 int main (int argc, char** argv)
98 notmuch_status_t stat;
99 stat = notmuch_database_create (NULL, NULL);
102 cat <<'EOF' >EXPECTED
105 Error: Cannot create a database for a NULL path.
107 test_expect_equal_file EXPECTED OUTPUT
109 test_begin_subtest "Create database in nonexistent directory"
110 test_C ${PWD}/nonexistent/foo<<'EOF'
113 int main (int argc, char** argv)
115 notmuch_database_t *db;
116 notmuch_status_t stat;
117 stat = notmuch_database_create (argv[1], &db);
120 cat <<'EOF' >EXPECTED
123 Error: Cannot create database at CWD/nonexistent/foo: No such file or directory.
125 test_expect_equal_file EXPECTED OUTPUT
127 test_begin_subtest "Write to read-only database"
128 test_C ${MAIL_DIR} <<'EOF'
131 int main (int argc, char** argv)
133 notmuch_database_t *db;
134 notmuch_status_t stat;
135 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
136 if (stat != NOTMUCH_STATUS_SUCCESS) {
137 fprintf (stderr, "error opening database: %d\n", stat);
139 stat = notmuch_database_add_message (db, "/dev/null", NULL);
141 fputs (notmuch_database_status_string (db), stderr);
145 cat <<'EOF' >EXPECTED
148 Cannot write to a read-only database.
150 test_expect_equal_file EXPECTED OUTPUT
152 test_begin_subtest "Add non-existent file"
153 test_C ${MAIL_DIR} <<'EOF'
156 int main (int argc, char** argv)
158 notmuch_database_t *db;
159 notmuch_status_t stat;
160 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
161 if (stat != NOTMUCH_STATUS_SUCCESS) {
162 fprintf (stderr, "error opening database: %d\n", stat);
164 stat = notmuch_database_add_message (db, "./nonexistent", NULL);
166 char *status_string = notmuch_database_status_string (db);
167 if (status_string) fputs (status_string, stderr);
171 cat <<'EOF' >EXPECTED
174 Error opening ./nonexistent: No such file or directory
176 test_expect_equal_file EXPECTED OUTPUT
178 test_begin_subtest "compact, overwriting existing backup"
179 test_C ${MAIL_DIR} <<'EOF'
183 status_cb (const char *msg, void *closure)
185 printf ("%s\n", msg);
187 int main (int argc, char** argv)
189 notmuch_database_t *db;
190 notmuch_status_t stat;
191 stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
194 cat <<'EOF' >EXPECTED
196 Path already exists: CWD/mail
200 test_expect_equal_file EXPECTED OUTPUT
204 #include <sys/types.h>
205 #include <sys/stat.h>
210 int main (int argc, char** argv)
212 notmuch_database_t *db;
213 notmuch_status_t stat;
217 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
218 if (stat != NOTMUCH_STATUS_SUCCESS) {
219 fprintf (stderr, "error opening database: %d\n", stat);
221 path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]);
222 fd = open(path,O_WRONLY|O_TRUNC);
224 fprintf (stderr, "error opening %s\n");
228 const char *stat_str = notmuch_database_status_string (db);
230 fputs (stat_str, stderr);
237 test_begin_subtest "Xapian exception finding message"
238 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
240 notmuch_message_t *message = NULL;
241 stat = notmuch_database_find_message (db, "id:nonexistent", &message);
244 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
245 cat <<'EOF' >EXPECTED
248 A Xapian exception occurred finding message
250 test_expect_equal_file EXPECTED OUTPUT.clean
254 test_begin_subtest "Xapian exception getting tags"
255 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
257 notmuch_tags_t *tags = NULL;
258 tags = notmuch_database_get_all_tags (db);
259 stat = (tags == NULL);
262 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
263 cat <<'EOF' >EXPECTED
266 A Xapian exception occurred getting tags
268 test_expect_equal_file EXPECTED OUTPUT.clean
272 test_begin_subtest "Xapian exception creating directory"
273 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
275 notmuch_directory_t *directory = NULL;
276 stat = notmuch_database_get_directory (db, "none/existing", &directory);
279 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
280 cat <<'EOF' >EXPECTED
283 A Xapian exception occurred creating a directory
285 test_expect_equal_file EXPECTED OUTPUT.clean
289 test_begin_subtest "Xapian exception searching messages"
290 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
292 notmuch_messages_t *messages = NULL;
293 notmuch_query_t *query=notmuch_query_create (db, "*");
294 stat = notmuch_query_search_messages_st (query, &messages);
297 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
298 cat <<'EOF' >EXPECTED
301 A Xapian exception occurred performing query
304 test_expect_equal_file EXPECTED OUTPUT.clean
308 test_begin_subtest "Xapian exception counting messages"
309 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
311 notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
312 int count = notmuch_query_count_messages (query);
316 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
317 cat <<'EOF' >EXPECTED
320 A Xapian exception occurred performing query
321 Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
323 test_expect_equal_file EXPECTED OUTPUT.clean