]> git.notmuchmail.org Git - notmuch/blob - test/T640-database-modified.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T640-database-modified.sh
1 #!/usr/bin/env bash
2 test_description="DatabaseModifiedError handling"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 # add enough messages to trigger the exception
6 add_email_corpus
7
8 test_begin_subtest "catching DatabaseModifiedError in _notmuch_message_ensure_metadata"
9 # it seems to need to be an early document to trigger the exception
10 first_id=$(notmuch search --output=messages '*'| head -1 | sed s/^id://)
11
12 test_C ${MAIL_DIR} <<EOF
13 #include <notmuch-test.h>
14
15 int
16 main (int argc, char **argv)
17 {
18     const char *path = argv[1];
19
20     notmuch_database_t *rw_db, *ro_db;
21     notmuch_messages_t *messages;
22     notmuch_message_t *message, *ro_message;
23     notmuch_query_t *query;
24     notmuch_tags_t *tags;
25     int i;
26     char* msg = NULL;
27
28     EXPECT0(notmuch_database_open_with_config (argv[1],
29                                                NOTMUCH_DATABASE_MODE_READ_ONLY,
30                                                "", NULL, &ro_db, &msg));
31     if (msg) fputs (msg, stderr);
32     assert(ro_db);
33
34     EXPECT0 (notmuch_database_find_message (ro_db, "${first_id}", &ro_message));
35     assert(ro_message);
36
37     EXPECT0(notmuch_database_open_with_config (argv[1],
38                                                NOTMUCH_DATABASE_MODE_READ_WRITE,
39                                                "", NULL, &rw_db, &msg));
40     if (msg) fputs (msg, stderr);
41
42     query = notmuch_query_create(rw_db, "");
43     EXPECT0 (notmuch_query_search_messages (query, &messages));
44
45     for (;
46          notmuch_messages_valid (messages);
47          notmuch_messages_move_to_next (messages)) {
48         message = notmuch_messages_get (messages);
49         for (i=0; i<200; i++) {
50             char *tag_str = talloc_asprintf(rw_db, "%d", i);
51             EXPECT0 (notmuch_message_add_tag (message, tag_str));
52             talloc_free (tag_str);
53         }
54     }
55
56     notmuch_database_close (rw_db);
57
58     tags = notmuch_message_get_tags (ro_message);
59     if (tags)
60         printf("SUCCESS\n");
61     return 0;
62 }
63 EOF
64
65 cat <<'EOF' >EXPECTED
66 == stdout ==
67 SUCCESS
68 == stderr ==
69 EOF
70 test_expect_equal_file EXPECTED OUTPUT
71
72 test_done