]> git.notmuchmail.org Git - notmuch/blob - test/T670-duplicate-mid.sh
test: add known broken test for duplicate thread-id terms
[notmuch] / test / T670-duplicate-mid.sh
1 #!/usr/bin/env bash
2 test_description="duplicate message ids"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 test_require_external_prereq xapian-delve
6
7 add_message '[id]="duplicate"' '[subject]="message 1" [filename]=copy1'
8 add_message '[id]="duplicate"' '[subject]="message 2" [filename]=copy2'
9
10 add_message '[id]="duplicate"' '[subject]="message 0" [filename]=copy0'
11
12 test_begin_subtest 'at most 1 thread-id per xapian document'
13 test_subtest_known_broken
14 db=${MAIL_DIR}/.notmuch/xapian
15 for doc in $(xapian-delve -1 -t '' "$db" | grep '^[1-9]'); do
16     xapian-delve -1 -r "$doc" "$db" | grep -c '^G'
17 done > OUTPUT.raw
18 sort -u < OUTPUT.raw > OUTPUT
19 cat <<EOF > EXPECTED
20 0
21 1
22 EOF
23 test_expect_equal_file EXPECTED OUTPUT
24
25 test_begin_subtest 'search: first indexed subject preserved'
26 cat <<EOF > EXPECTED
27 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 1 (inbox unread)
28 EOF
29 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
30 test_expect_equal_file EXPECTED OUTPUT
31
32 test_begin_subtest 'First subject preserved in notmuch-show (json)'
33 test_subtest_known_broken
34 output=$(notmuch show --body=false --format=json id:duplicate | notmuch_json_show_sanitize)
35 expected='[[[{
36     "id": "XXXXX",
37     "match": true,
38     "excluded": false,
39     "filename": [
40         "'"${MAIL_DIR}"/copy0'",
41         "'"${MAIL_DIR}"/copy1'",
42         "'"${MAIL_DIR}"/copy2'"
43     ],
44     "timestamp": 42,
45     "date_relative": "2001-01-05",
46     "tags": ["inbox","unread"],
47     "headers": {
48         "Subject": "message 1",
49         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
50         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
51         "Date": "GENERATED_DATE"
52     }
53  },
54 []]]]'
55 test_expect_equal_json "$output" "$expected"
56
57 test_begin_subtest 'Search for second subject'
58 cat <<EOF >EXPECTED
59 MAIL_DIR/copy0
60 MAIL_DIR/copy1
61 MAIL_DIR/copy2
62 EOF
63 notmuch search --output=files subject:'"message 2"' | notmuch_dir_sanitize > OUTPUT
64 test_expect_equal_file EXPECTED OUTPUT
65
66 test_begin_subtest 'Regexp search for second subject'
67 test_subtest_known_broken
68 cat <<EOF >EXPECTED
69 MAIL_DIR/copy0
70 MAIL_DIR/copy1
71 MAIL_DIR/copy2
72 EOF
73 notmuch search --output=files 'subject:"/message 2/"' | notmuch_dir_sanitize > OUTPUT
74 test_expect_equal_file EXPECTED OUTPUT
75
76 add_message '[id]="duplicate"' '[body]="sekrit" [filename]=copy3'
77 test_begin_subtest 'search for body in duplicate file'
78 cat <<EOF >EXPECTED
79 MAIL_DIR/copy0
80 MAIL_DIR/copy1
81 MAIL_DIR/copy2
82 MAIL_DIR/copy3
83 EOF
84 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
85 test_expect_equal_file EXPECTED OUTPUT
86
87 rm ${MAIL_DIR}/copy3
88 test_begin_subtest 'reindex drops terms in duplicate file'
89 cp /dev/null EXPECTED
90 notmuch reindex '*'
91 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
92 test_expect_equal_file EXPECTED OUTPUT
93
94 test_begin_subtest 'reindex choses subject from first filename'
95 cat <<EOF > EXPECTED
96 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 0 (inbox unread)
97 EOF
98 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
99 test_expect_equal_file EXPECTED OUTPUT
100
101 rm ${MAIL_DIR}/copy0
102 test_begin_subtest 'Deleted first duplicate file does not stop notmuch show from working'
103 output=$(notmuch show --body=false --format=json id:duplicate |
104              notmuch_json_show_sanitize | sed 's/message [0-9]/A_SUBJECT/')
105 expected='[[[{
106     "id": "XXXXX",
107     "crypto": {},
108     "match": true,
109     "excluded": false,
110     "filename": [
111         "'"${MAIL_DIR}"/copy0'",
112         "'"${MAIL_DIR}"/copy1'",
113         "'"${MAIL_DIR}"/copy2'"
114     ],
115     "timestamp": 42,
116     "date_relative": "2001-01-05",
117     "tags": ["inbox","unread"],
118     "headers": {
119         "Subject": "A_SUBJECT",
120         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
121         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
122         "Date": "GENERATED_DATE"
123     }
124  },
125 []]]]'
126
127 test_expect_equal_json "$output" "$expected"
128
129 test_done