]> git.notmuchmail.org Git - notmuch/blob - test/T570-revision-tracking.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T570-revision-tracking.sh
1 #!/usr/bin/env bash
2 test_description="database revision tracking"
3
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 add_email_corpus
7
8 test_begin_subtest "notmuch_database_get_revision"
9 test_C ${MAIL_DIR} <<'EOF'
10 #include <stdio.h>
11 #include <string.h>
12 #include <notmuch.h>
13 int main (int argc, char** argv)
14 {
15    notmuch_database_t *db;
16    notmuch_status_t stat;
17    unsigned long revision;
18    const char *uuid;
19
20    unsigned long rev;
21
22    char* msg = NULL;
23    stat = notmuch_database_open_with_config (argv[1],
24                                              NOTMUCH_DATABASE_MODE_READ_ONLY,
25                                              "", NULL, &db, &msg);
26    if (msg) fputs (msg, stderr);
27
28    if (stat)
29        fputs ("open failed\n", stderr);
30    revision = notmuch_database_get_revision (db, &uuid);
31    printf("%s\t%lu\n", uuid, revision);
32 }
33 EOF
34 notmuch_uuid_sanitize < OUTPUT > CLEAN
35 cat <<'EOF' >EXPECTED
36 == stdout ==
37 UUID    53
38 == stderr ==
39 EOF
40 test_expect_equal_file EXPECTED CLEAN
41
42 grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
43
44 test_begin_subtest "output of count matches test code"
45 notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
46 test_expect_equal_file INITIAL_OUTPUT OUTPUT
47
48 test_begin_subtest "modification count increases"
49 before=$(notmuch count --lastmod '*' | cut -f3)
50 notmuch tag +a-random-tag-8743632 '*'
51 after=$(notmuch count --lastmod '*' | cut -f3)
52 result=$(($before < $after))
53 test_expect_equal 1 ${result}
54
55 notmuch count --lastmod '*' | cut -f2 > UUID
56
57 test_begin_subtest "search succeeds with correct uuid"
58 test_expect_success "notmuch search --uuid=$(cat UUID) '*'"
59
60 test_begin_subtest "uuid works as global option"
61 test_expect_success "notmuch --uuid=$(cat UUID) search '*'"
62
63 test_begin_subtest "uuid works as global option II"
64 test_expect_code 1 "notmuch --uuid=this-is-no-uuid search '*'"
65
66 test_begin_subtest "search fails with incorrect uuid"
67 test_expect_code 1 "notmuch search --uuid=this-is-no-uuid '*'"
68
69 test_begin_subtest "show succeeds with correct uuid"
70 test_expect_success "notmuch show --uuid=$(cat UUID) '*'"
71
72 test_begin_subtest "show fails with incorrect uuid"
73 test_expect_code 1 "notmuch show --uuid=this-is-no-uuid '*'"
74
75 test_begin_subtest "tag succeeds with correct uuid"
76 test_expect_success "notmuch tag --uuid=$(cat UUID) +test '*'"
77
78 test_begin_subtest "tag fails with incorrect uuid"
79 test_expect_code 1 "notmuch tag --uuid=this-is-no-uuid '*' +test2"
80
81 test_begin_subtest 'lastmod:0.. matches everything'
82 total=$(notmuch count '*')
83 modtotal=$(notmuch count lastmod:0..)
84 test_expect_equal "$total" "$modtotal"
85
86 test_begin_subtest 'lastmod:1000000.. matches nothing'
87 modtotal=$(notmuch count lastmod:1000000..)
88 test_expect_equal 0 "$modtotal"
89
90 test_begin_subtest 'exclude one message using lastmod'
91 lastmod=$(notmuch count --lastmod '*' | cut -f3)
92 total=$(notmuch count '*')
93 notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org
94 subtotal=$(notmuch count lastmod:..$lastmod)
95 result=$(($subtotal == $total-1))
96 test_expect_equal 1 "$result"
97
98 test_done