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: database path 'CWD/nonexistent/foo' does not exist or is not a 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 printf ("%s\n", notmuch_status_to_string (stat));
109 if (msg) fputs (msg, stderr);
112 cat <<'EOF' >EXPECTED
117 test_expect_equal_file EXPECTED OUTPUT
119 test_begin_subtest "Create database in nonexistent directory"
120 test_C ${PWD}/nonexistent/foo<<'EOF'
123 int main (int argc, char** argv)
125 notmuch_database_t *db;
126 notmuch_status_t stat;
129 stat = notmuch_database_create_with_config (argv[1], "", NULL, &db, &msg);
130 printf ("%d\n", stat == NOTMUCH_STATUS_SUCCESS);
131 if (msg) fputs (msg, stderr);
134 cat <<'EOF' >EXPECTED
139 test_expect_equal_file EXPECTED OUTPUT
141 test_begin_subtest "Write to read-only database"
142 test_C ${MAIL_DIR} <<'EOF'
145 int main (int argc, char** argv)
147 notmuch_database_t *db;
148 notmuch_status_t stat;
150 stat = notmuch_database_open_with_config (argv[1],
151 NOTMUCH_DATABASE_MODE_READ_ONLY,
152 "", NULL, &db, &msg);
153 if (msg) fputs (msg, stderr);
154 if (stat != NOTMUCH_STATUS_SUCCESS) {
155 fprintf (stderr, "error opening database: %d\n", stat);
157 stat = notmuch_database_index_file (db, "/dev/null", NULL, NULL);
159 fputs (notmuch_database_status_string (db), stderr);
163 cat <<'EOF' >EXPECTED
166 Cannot write to a read-only database.
168 test_expect_equal_file EXPECTED OUTPUT
170 test_begin_subtest "Add non-existent file"
171 test_C ${MAIL_DIR} <<'EOF'
174 int main (int argc, char** argv)
176 notmuch_database_t *db;
177 notmuch_status_t stat;
178 stat = notmuch_database_open_with_config (argv[1],
179 NOTMUCH_DATABASE_MODE_READ_WRITE,
180 "", NULL, &db, NULL);
181 if (stat != NOTMUCH_STATUS_SUCCESS) {
182 fprintf (stderr, "error opening database: %d\n", stat);
184 stat = notmuch_database_index_file (db, "./nonexistent", NULL, NULL);
186 char *status_string = notmuch_database_status_string (db);
187 if (status_string) fputs (status_string, stderr);
191 cat <<'EOF' >EXPECTED
194 Error opening ./nonexistent: No such file or directory
196 test_expect_equal_file EXPECTED OUTPUT
198 test_begin_subtest "compact, overwriting existing backup"
199 test_C ${MAIL_DIR} <<'EOF'
203 status_cb (const char *msg, void *closure)
205 printf ("%s\n", msg);
207 int main (int argc, char** argv)
209 notmuch_database_t *db;
210 notmuch_status_t stat;
211 stat = notmuch_database_compact (argv[1], argv[1], status_cb, NULL);
214 cat <<'EOF' >EXPECTED
216 Path already exists: MAIL_DIR
220 test_expect_equal_file EXPECTED OUTPUT
224 #include <sys/types.h>
225 #include <sys/stat.h>
230 int main (int argc, char** argv)
232 notmuch_database_t *db;
233 notmuch_status_t stat;
238 stat = notmuch_database_open_with_config (argv[1],
239 NOTMUCH_DATABASE_MODE_READ_WRITE,
240 NULL, NULL, &db, &msg);
241 if (stat != NOTMUCH_STATUS_SUCCESS) {
242 fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
245 fd = open(argv[2],O_WRONLY|O_TRUNC);
247 fprintf (stderr, "error opening %s\n", argv[1]);
253 const char *stat_str = notmuch_database_status_string (db);
255 fputs (stat_str, stderr);
261 POSTLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/postlist.*)
263 test_begin_subtest "Xapian exception finding message"
264 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
266 notmuch_message_t *message = NULL;
267 stat = notmuch_database_find_message (db, "id:nonexistent", &message);
270 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
271 cat <<'EOF' >EXPECTED
274 A Xapian exception occurred finding message
276 test_expect_equal_file EXPECTED OUTPUT.clean
280 test_begin_subtest "Xapian exception creating directory"
281 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
283 notmuch_directory_t *directory = NULL;
284 stat = notmuch_database_get_directory (db, "none/existing", &directory);
287 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
288 cat <<'EOF' >EXPECTED
291 A Xapian exception occurred finding/creating a directory
293 test_expect_equal_file EXPECTED OUTPUT.clean
297 test_begin_subtest "Xapian exception searching messages"
298 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
300 notmuch_messages_t *messages = NULL;
301 notmuch_query_t *query=notmuch_query_create (db, "*");
302 stat = notmuch_query_search_messages (query, &messages);
305 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
306 cat <<'EOF' >EXPECTED
309 A Xapian exception occurred performing query
312 test_expect_equal_file EXPECTED OUTPUT.clean
316 test_begin_subtest "Xapian exception counting messages"
317 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
320 notmuch_query_t *query=notmuch_query_create (db, "id:87ocn0qh6d.fsf@yoom.home.cworth.org");
321 stat = notmuch_query_count_messages (query, &count);
324 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
325 cat <<'EOF' >EXPECTED
328 A Xapian exception occurred performing query
329 Query string was: id:87ocn0qh6d.fsf@yoom.home.cworth.org
331 test_expect_equal_file EXPECTED OUTPUT.clean