]> git.notmuchmail.org Git - notmuch/blob - test/T395-ruby.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T395-ruby.sh
1 #!/usr/bin/env bash
2 test_description="ruby bindings"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 if [ -z "${NOTMUCH_TEST_INSTALLED-}" -a "${NOTMUCH_HAVE_RUBY_DEV-0}" = "0" ]; then
6     test_subtest_missing_external_prereq_["ruby development files"]=t
7 fi
8
9 add_email_corpus
10
11 test_ruby() {
12     (
13         cat <<-EOF
14         require 'notmuch'
15         db = Notmuch::Database.new()
16         EOF
17         cat
18     ) | if [ -n "${NOTMUCH_TEST_INSTALLED-}" ]; then
19         ruby
20     else
21         $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"
22     fi> OUTPUT
23     test_expect_equal_file EXPECTED OUTPUT
24 }
25
26 test_begin_subtest "compare thread ids"
27 notmuch search --sort=oldest-first --output=threads tag:inbox > EXPECTED
28 test_ruby <<"EOF"
29 q = db.query('tag:inbox')
30 q.sort = Notmuch::SORT_OLDEST_FIRST
31 q.search_threads.each do |t|
32   puts 'thread:%s' % t.thread_id
33 end
34 EOF
35
36 test_begin_subtest "compare message ids"
37 notmuch search --sort=oldest-first --output=messages tag:inbox > EXPECTED
38 test_ruby <<"EOF"
39 q = db.query('tag:inbox')
40 q.sort = Notmuch::SORT_OLDEST_FIRST
41 q.search_messages.each do |m|
42   puts 'id:%s' % m.message_id
43 end
44 EOF
45
46 test_begin_subtest "get non-existent file"
47 echo nil > EXPECTED
48 test_ruby <<"EOF"
49 p db.find_message_by_filename('i-dont-exist')
50 EOF
51
52 test_begin_subtest "count messages"
53 notmuch count --output=messages tag:inbox > EXPECTED
54 test_ruby <<"EOF"
55 puts db.query('tag:inbox').count_messages()
56 EOF
57
58 test_begin_subtest "count threads"
59 notmuch count --output=threads tag:inbox > EXPECTED
60 test_ruby <<"EOF"
61 puts db.query('tag:inbox').count_threads()
62 EOF
63
64 test_begin_subtest "get all tags"
65 notmuch search --output=tags '*' > EXPECTED
66 test_ruby <<"EOF"
67 db.all_tags.each do |tag|
68   puts tag
69 end
70 EOF
71
72 notmuch config set search.exclude_tags deleted
73 generate_message '[subject]="Good"'
74 generate_message '[subject]="Bad"' "[in-reply-to]=\<$gen_msg_id\>"
75 notmuch new > /dev/null
76 notmuch tag +deleted id:$gen_msg_id
77
78 test_begin_subtest "omit excluded all"
79 notmuch search --output=threads --exclude=all tag:inbox > EXPECTED
80 test_ruby <<"EOF"
81 q = db.query('tag:inbox')
82 q.add_tag_exclude('deleted')
83 q.omit_excluded = Notmuch::EXCLUDE_ALL
84 q.search_threads.each do |t|
85   puts 'thread:%s' % t.thread_id
86 end
87 EOF
88
89 test_begin_subtest "check sort argument"
90 notmuch search --sort=oldest-first --output=threads tag:inbox > EXPECTED
91 test_ruby <<"EOF"
92 q = db.query('tag:inbox', sort: Notmuch::SORT_OLDEST_FIRST)
93 q.search_threads.each do |t|
94   puts 'thread:%s' % t.thread_id
95 end
96 EOF
97
98 test_begin_subtest "check exclude_tags argument"
99 notmuch search --output=threads --exclude=all tag:inbox > EXPECTED
100 test_ruby <<"EOF"
101 q = db.query('tag:inbox', exclude_tags: %w[deleted], omit_excluded: Notmuch::EXCLUDE_ALL)
102 q.search_threads.each do |t|
103   puts 'thread:%s' % t.thread_id
104 end
105 EOF
106
107 test_done