]> git.cworth.org Git - notmuch/blob - test/T395-ruby.sh
emacs: Make notmuch-show-next-thread return nil on failure
[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 [ "${NOTMUCH_HAVE_RUBY_DEV}" = "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('$MAIL_DIR')
16         EOF
17         cat
18     ) | $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
19     test_expect_equal_file EXPECTED OUTPUT
20 }
21
22 test_begin_subtest "compare thread ids"
23 notmuch search --sort=oldest-first --output=threads tag:inbox > EXPECTED
24 test_ruby <<"EOF"
25 q = db.query('tag:inbox')
26 q.sort = Notmuch::SORT_OLDEST_FIRST
27 q.search_threads.each do |t|
28   puts 'thread:%s' % t.thread_id
29 end
30 EOF
31
32 test_begin_subtest "compare message ids"
33 notmuch search --sort=oldest-first --output=messages tag:inbox > EXPECTED
34 test_ruby <<"EOF"
35 q = db.query('tag:inbox')
36 q.sort = Notmuch::SORT_OLDEST_FIRST
37 q.search_messages.each do |m|
38   puts 'id:%s' % m.message_id
39 end
40 EOF
41
42 test_begin_subtest "get non-existent file"
43 echo nil > EXPECTED
44 test_ruby <<"EOF"
45 p db.find_message_by_filename('i-dont-exist')
46 EOF
47
48 test_begin_subtest "count messages"
49 notmuch count --output=messages tag:inbox > EXPECTED
50 test_ruby <<"EOF"
51 puts db.query('tag:inbox').count_messages()
52 EOF
53
54 test_begin_subtest "count threads"
55 notmuch count --output=threads tag:inbox > EXPECTED
56 test_ruby <<"EOF"
57 puts db.query('tag:inbox').count_threads()
58 EOF
59
60 test_begin_subtest "get all tags"
61 notmuch search --output=tags '*' > EXPECTED
62 test_ruby <<"EOF"
63 db.all_tags.each do |tag|
64   puts tag
65 end
66 EOF
67
68 notmuch config set search.exclude_tags deleted
69 generate_message '[subject]="Good"'
70 generate_message '[subject]="Bad"' "[in-reply-to]=\<$gen_msg_id\>"
71 notmuch new > /dev/null
72 notmuch tag +deleted id:$gen_msg_id
73
74 test_begin_subtest "omit excluded all"
75 notmuch search --output=threads --exclude=all tag:inbox > EXPECTED
76 test_ruby <<"EOF"
77 q = db.query('tag:inbox')
78 q.add_tag_exclude('deleted')
79 q.omit_excluded = Notmuch::EXCLUDE_ALL
80 q.search_threads.each do |t|
81   puts 'thread:%s' % t.thread_id
82 end
83 EOF
84
85 test_begin_subtest "check sort argument"
86 notmuch search --sort=oldest-first --output=threads tag:inbox > EXPECTED
87 test_ruby <<"EOF"
88 q = db.query('tag:inbox', sort: Notmuch::SORT_OLDEST_FIRST)
89 q.search_threads.each do |t|
90   puts 'thread:%s' % t.thread_id
91 end
92 EOF
93
94 test_begin_subtest "check exclude_tags argument"
95 notmuch search --output=threads --exclude=all tag:inbox > EXPECTED
96 test_ruby <<"EOF"
97 q = db.query('tag:inbox', exclude_tags: %w[deleted], omit_excluded: Notmuch::EXCLUDE_ALL)
98 q.search_threads.each do |t|
99   puts 'thread:%s' % t.thread_id
100 end
101 EOF
102
103 test_done