2 test_description="error reporting for library"
4 . ./test-lib.sh || exit 1
8 test_expect_success "building database" "NOTMUCH_NEW"
10 test_begin_subtest "Open null pointer"
14 int main (int argc, char** argv)
16 notmuch_database_t *db;
17 notmuch_status_t stat;
18 stat = notmuch_database_open (NULL, 0, 0);
24 Error: Cannot open a database for a NULL path.
26 test_expect_equal_file EXPECTED OUTPUT
28 test_begin_subtest "Open relative path"
32 int main (int argc, char** argv)
34 notmuch_database_t *db;
35 notmuch_status_t stat;
36 stat = notmuch_database_open ("./nonexistent/foo", 0, 0);
42 Error: Database path must be absolute.
44 test_expect_equal_file EXPECTED OUTPUT
46 test_begin_subtest "Create database in relative path"
50 int main (int argc, char** argv)
52 notmuch_database_t *db;
53 notmuch_status_t stat;
54 stat = notmuch_database_create ("./nonexistent/foo", &db);
60 Error: Database path must be absolute.
62 test_expect_equal_file EXPECTED OUTPUT
64 test_begin_subtest "Open nonexistent database"
65 test_C ${PWD}/nonexistent/foo <<'EOF'
68 int main (int argc, char** argv)
70 notmuch_database_t *db;
71 notmuch_status_t stat;
72 stat = notmuch_database_open (argv[1], 0, 0);
78 Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory
80 test_expect_equal_file EXPECTED OUTPUT
82 test_begin_subtest "create NULL path"
86 int main (int argc, char** argv)
88 notmuch_status_t stat;
89 stat = notmuch_database_create (NULL, NULL);
95 Error: Cannot create a database for a NULL path.
97 test_expect_equal_file EXPECTED OUTPUT
99 test_begin_subtest "Create database in nonexistent directory"
100 test_C ${PWD}/nonexistent/foo<<'EOF'
103 int main (int argc, char** argv)
105 notmuch_database_t *db;
106 notmuch_status_t stat;
107 stat = notmuch_database_create (argv[1], &db);
110 cat <<'EOF' >EXPECTED
113 Error: Cannot create database at CWD/nonexistent/foo: No such file or directory.
115 test_expect_equal_file EXPECTED OUTPUT
117 test_begin_subtest "Write to read-only database"
118 test_C ${MAIL_DIR} <<'EOF'
121 int main (int argc, char** argv)
123 notmuch_database_t *db;
124 notmuch_status_t stat;
125 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
126 if (stat != NOTMUCH_STATUS_SUCCESS) {
127 fprintf (stderr, "error opening database: %d\n", stat);
129 stat = notmuch_database_add_message (db, "/dev/null", NULL);
131 fputs (notmuch_database_status_string (db), stderr);
135 cat <<'EOF' >EXPECTED
138 Cannot write to a read-only database.
140 test_expect_equal_file EXPECTED OUTPUT
142 test_begin_subtest "Add non-existent file"
143 test_C ${MAIL_DIR} <<'EOF'
146 int main (int argc, char** argv)
148 notmuch_database_t *db;
149 notmuch_status_t stat;
150 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
151 if (stat != NOTMUCH_STATUS_SUCCESS) {
152 fprintf (stderr, "error opening database: %d\n", stat);
154 stat = notmuch_database_add_message (db, "./nonexistent", NULL);
156 char *status_string = notmuch_database_status_string (db);
157 if (status_string) fputs (status_string, stderr);
161 cat <<'EOF' >EXPECTED
164 Error opening ./nonexistent: No such file or directory
166 test_expect_equal_file EXPECTED OUTPUT
168 test_begin_subtest "compact, overwriting existing backup"
169 test_C ${MAIL_DIR} <<'EOF'
173 status_cb (const char *msg, void *closure)
175 printf ("%s\n", msg);
177 int main (int argc, char** argv)
179 notmuch_database_t *db;
180 notmuch_status_t stat;
181 stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
184 cat <<'EOF' >EXPECTED
186 Path already exists: CWD/mail
190 test_expect_equal_file EXPECTED OUTPUT
194 #include <sys/types.h>
195 #include <sys/stat.h>
200 int main (int argc, char** argv)
202 notmuch_database_t *db;
203 notmuch_status_t stat;
207 stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db);
208 if (stat != NOTMUCH_STATUS_SUCCESS) {
209 fprintf (stderr, "error opening database: %d\n", stat);
211 path = talloc_asprintf (db, "%s/.notmuch/xapian/postlist.DB", argv[1]);
212 fd = open(path,O_WRONLY|O_TRUNC);
214 fprintf (stderr, "error opening %s\n");
218 const char *stat_str = notmuch_database_status_string (db);
220 fputs (stat_str, stderr);
227 test_begin_subtest "Xapian exception finding message"
228 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
230 notmuch_message_t *message = NULL;
231 stat = notmuch_database_find_message (db, "id:nonexistent", &message);
234 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
235 cat <<'EOF' >EXPECTED
238 A Xapian exception occurred finding message
240 test_expect_equal_file EXPECTED OUTPUT.clean
244 test_begin_subtest "Xapian exception getting tags"
245 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
247 notmuch_tags_t *tags = NULL;
248 tags = notmuch_database_get_all_tags (db);
249 stat = (tags == NULL);
252 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
253 cat <<'EOF' >EXPECTED
256 A Xapian exception occurred getting tags
258 test_expect_equal_file EXPECTED OUTPUT.clean
262 test_begin_subtest "Xapian exception creating directory"
263 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
265 notmuch_directory_t *directory = NULL;
266 stat = notmuch_database_get_directory (db, "none/existing", &directory);
269 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
270 cat <<'EOF' >EXPECTED
273 A Xapian exception occurred creating a directory
275 test_expect_equal_file EXPECTED OUTPUT.clean
279 test_begin_subtest "Xapian exception searching messages"
280 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
282 notmuch_messages_t *messages = NULL;
283 notmuch_query_t *query=notmuch_query_create (db, "*");
284 stat = notmuch_query_search_messages_st (query, &messages);
287 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
288 cat <<'EOF' >EXPECTED
291 A Xapian exception occurred performing query
294 test_expect_equal_file EXPECTED OUTPUT.clean
298 test_begin_subtest "Xapian exception counting messages"
299 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
301 notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
302 int count = notmuch_query_count_messages (query);
306 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
307 cat <<'EOF' >EXPECTED
310 A Xapian exception occurred performing query
311 Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
313 test_expect_equal_file EXPECTED OUTPUT.clean