1#!/usr/bin/env bash
2test_description="database revision tracking"
3
4. $(dirname "$0")/test-lib.sh || exit 1
5
6add_email_corpus
7
8test_begin_subtest "notmuch_database_get_revision"
9test_C ${MAIL_DIR} <<'EOF'
10#include <stdio.h>
11#include <string.h>
12#include <notmuch.h>
13int 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}
28EOF
29notmuch_uuid_sanitize < OUTPUT > CLEAN
30cat <<'EOF' >EXPECTED
31== stdout ==
32UUID	53
33== stderr ==
34EOF
35test_expect_equal_file EXPECTED CLEAN
36
37grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
38
39test_begin_subtest "output of count matches test code"
40notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
41test_expect_equal_file INITIAL_OUTPUT OUTPUT
42
43test_begin_subtest "modification count increases"
44before=$(notmuch count --lastmod '*' | cut -f3)
45notmuch tag +a-random-tag-8743632 '*'
46after=$(notmuch count --lastmod '*' | cut -f3)
47result=$(($before < $after))
48test_expect_equal 1 ${result}
49
50notmuch count --lastmod '*' | cut -f2 > UUID
51
52test_begin_subtest "search succeeds with correct uuid"
53test_expect_success "notmuch search --uuid=$(cat UUID) '*'"
54
55test_begin_subtest "uuid works as global option"
56test_expect_success "notmuch --uuid=$(cat UUID) search '*'"
57
58test_begin_subtest "uuid works as global option II"
59test_expect_code 1 "notmuch --uuid=this-is-no-uuid search '*'"
60
61test_begin_subtest "search fails with incorrect uuid"
62test_expect_code 1 "notmuch search --uuid=this-is-no-uuid '*'"
63
64test_begin_subtest "show succeeds with correct uuid"
65test_expect_success "notmuch show --uuid=$(cat UUID) '*'"
66
67test_begin_subtest "show fails with incorrect uuid"
68test_expect_code 1 "notmuch show --uuid=this-is-no-uuid '*'"
69
70test_begin_subtest "tag succeeds with correct uuid"
71test_expect_success "notmuch tag --uuid=$(cat UUID) +test '*'"
72
73test_begin_subtest "tag fails with incorrect uuid"
74test_expect_code 1 "notmuch tag --uuid=this-is-no-uuid '*' +test2"
75
76test_begin_subtest 'lastmod:0.. matches everything'
77total=$(notmuch count '*')
78modtotal=$(notmuch count lastmod:0..)
79test_expect_equal "$total" "$modtotal"
80
81test_begin_subtest 'lastmod:1000000.. matches nothing'
82modtotal=$(notmuch count lastmod:1000000..)
83test_expect_equal 0 "$modtotal"
84
85test_begin_subtest 'exclude one message using lastmod'
86lastmod=$(notmuch count --lastmod '*' | cut -f3)
87total=$(notmuch count '*')
88notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org
89subtotal=$(notmuch count lastmod:..$lastmod)
90result=$(($subtotal == $total-1))
91test_expect_equal 1 "$result"
92
93test_done
94