]> git.notmuchmail.org Git - notmuch/blob - test/T570-revision-tracking.sh
cli: add global option "--uuid"
[notmuch] / test / T570-revision-tracking.sh
1 #!/usr/bin/env bash
2 test_description="database revision tracking"
3
4 . ./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    stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
23    if (stat)
24        fputs ("open failed\n", stderr);
25    revision = notmuch_database_get_revision (db, &uuid);
26    printf("%s\t%lu\n", uuid, revision);
27 }
28 EOF
29 notmuch_uuid_sanitize < OUTPUT > CLEAN
30 cat <<'EOF' >EXPECTED
31 == stdout ==
32 UUID    53
33 == stderr ==
34 EOF
35 test_expect_equal_file EXPECTED CLEAN
36
37 grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
38
39 test_begin_subtest "output of count matches test code"
40 notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
41 test_expect_equal_file INITIAL_OUTPUT OUTPUT
42
43 test_begin_subtest "modification count increases"
44 before=$(notmuch count --lastmod '*' | cut -f3)
45 notmuch tag +a-random-tag-8743632 '*'
46 after=$(notmuch count --lastmod '*' | cut -f3)
47 result=$(($before < $after))
48 test_expect_equal 1 ${result}
49
50 notmuch count --lastmod '*' | cut -f2 > UUID
51
52 test_expect_success 'search succeeds with correct uuid' \
53                     "notmuch search --uuid=$(cat UUID) '*'"
54
55 test_expect_success 'uuid works as global option ' \
56                     "notmuch --uuid=$(cat UUID) search '*'"
57
58 test_expect_code 1 'uuid works as global option II' \
59                     "notmuch --uuid=this-is-no-uuid search '*'"
60
61 test_expect_code 1 'search fails with incorrect uuid' \
62                  "notmuch search --uuid=this-is-no-uuid '*'"
63
64 test_expect_success 'show succeeds with correct uuid' \
65                     "notmuch show --uuid=$(cat UUID) '*'"
66
67 test_expect_code 1 'show fails with incorrect uuid' \
68                  "notmuch show --uuid=this-is-no-uuid '*'"
69
70 test_expect_success 'tag succeeds with correct uuid' \
71                     "notmuch tag --uuid=$(cat UUID) +test '*'"
72
73 test_expect_code 1 'tag fails with incorrect uuid' \
74                  "notmuch tag --uuid=this-is-no-uuid '*' +test2"
75
76 test_done