]> git.notmuchmail.org Git - notmuch/blob - test/T565-lib-tags.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T565-lib-tags.sh
1 #!/usr/bin/env bash
2 test_description="API tests for tags"
3
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 add_email_corpus
7
8 test_begin_subtest "building database"
9 test_expect_success "NOTMUCH_NEW"
10
11 cat <<EOF > c_head
12 #include <stdio.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <talloc.h>
17 #include <notmuch.h>
18
19 int main (int argc, char** argv)
20 {
21    notmuch_database_t *db;
22    notmuch_status_t stat;
23    char *path;
24    char *msg = NULL;
25    int fd;
26
27    stat = notmuch_database_open_with_config (argv[1],
28                                               NOTMUCH_DATABASE_MODE_READ_WRITE,
29                                               NULL, NULL, &db, &msg);
30    if (stat != NOTMUCH_STATUS_SUCCESS) {
31      fprintf (stderr, "error opening database\n%s\n%s\n", notmuch_status_to_string (stat), msg ? msg : "");
32      exit (1);
33    }
34 EOF
35 cat <<'EOF' > c_tail
36    if (stat) {
37        const char *stat_str = notmuch_database_status_string (db);
38        if (stat_str)
39            fputs (stat_str, stderr);
40     }
41
42 }
43 EOF
44
45 POSTLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/postlist.*)
46
47 backup_database
48 test_begin_subtest "Xapian exception getting tags"
49 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} ${POSTLIST_PATH}
50    {
51       notmuch_tags_t *tags = NULL;
52       fd = open(argv[2],O_WRONLY|O_TRUNC);
53       if (fd < 0) {
54           fprintf (stderr, "error opening %s\n", argv[1]);
55           exit (1);
56        }
57        tags = notmuch_database_get_all_tags (db);
58        stat = (tags == NULL);
59    }
60 EOF
61 sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
62 cat <<'EOF' >EXPECTED
63 == stdout ==
64 == stderr ==
65 A Xapian exception occurred getting tags
66 EOF
67 test_expect_equal_file EXPECTED OUTPUT.clean
68 restore_database
69
70 test_begin_subtest "NULL tags are not valid"
71 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
72    {
73        notmuch_bool_t valid = TRUE;
74        valid = notmuch_tags_valid (NULL);
75        fprintf(stdout, "valid = %d\n", valid);
76    }
77 EOF
78 cat <<'EOF' >EXPECTED
79 == stdout ==
80 valid = 0
81 == stderr ==
82 EOF
83 test_expect_equal_file EXPECTED OUTPUT
84
85 test_done