]> git.cworth.org Git - notmuch/blob - test/T760-as-text.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T760-as-text.sh
1 #!/usr/bin/env bash
2 test_description='index attachments as text'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_email_corpus indexing
6 test_begin_subtest "empty as_text; skip text/x-diff"
7 messages=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain)
8 count=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz)
9 test_expect_equal "$messages,$count" "1,0"
10
11 notmuch config set index.as_text "^text/"
12 add_email_corpus indexing
13
14 test_begin_subtest "as_index is text/; find text/x-diff"
15 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
16 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
17 test_expect_equal_file_nonempty EXPECTED OUTPUT
18
19 test_begin_subtest "reindex with empty as_text, skips text/x-diff"
20 notmuch config set index.as_text
21 notmuch reindex '*'
22 messages=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain)
23 count=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz)
24 test_expect_equal "$messages,$count" "1,0"
25
26 test_begin_subtest "reindex with empty as_text; skips application/pdf"
27 notmuch config set index.as_text
28 notmuch reindex '*'
29 gmessages=$(notmuch count id:871qo9p4tf.fsf@tethera.net)
30 count=$(notmuch count id:871qo9p4tf.fsf@tethera.net and body:not-really-PDF)
31 test_expect_equal "$messages,$count" "1,0"
32
33 test_begin_subtest "reindex with as_text as text/; finds text/x-diff"
34 notmuch config set index.as_text "^text/"
35 notmuch reindex '*'
36 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
37 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
38 test_expect_equal_file_nonempty EXPECTED OUTPUT
39
40 test_begin_subtest "reindex with as_text as text/; skips application/pdf"
41 notmuch config set index.as_text "^text/"
42 notmuch config set index.as_text
43 notmuch reindex '*'
44 messages=$(notmuch count id:871qo9p4tf.fsf@tethera.net)
45 count=$(notmuch count id:871qo9p4tf.fsf@tethera.net and body:not-really-PDF)
46 test_expect_equal "$messages,$count" "1,0"
47
48 test_begin_subtest "as_text has multiple regexes"
49 notmuch config set index.as_text "blahblah;^text/"
50 notmuch reindex '*'
51 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
52 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
53 test_expect_equal_file_nonempty EXPECTED OUTPUT
54
55 test_begin_subtest "as_text is non-anchored regex"
56 notmuch config set index.as_text "e.t/"
57 notmuch reindex '*'
58 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
59 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
60 test_expect_equal_file_nonempty EXPECTED OUTPUT
61
62 test_begin_subtest "as_text is 'application/pdf'"
63 notmuch config set index.as_text "^application/pdf$"
64 notmuch reindex '*'
65 notmuch search id:871qo9p4tf.fsf@tethera.net > EXPECTED
66 notmuch search id:871qo9p4tf.fsf@tethera.net and '"not really PDF"' > OUTPUT
67 test_expect_equal_file_nonempty EXPECTED OUTPUT
68
69 test_begin_subtest "as_text is bad regex"
70 notmuch config set index.as_text '['
71 notmuch reindex '*' >& OUTPUT
72 cat<<EOF > EXPECTED
73 Error in index.as_text: Invalid regular expression: [
74 EOF
75 test_expect_equal_file EXPECTED OUTPUT
76
77 test_done