]> git.notmuchmail.org Git - notmuch/blob - test/T395-ruby.sh
test: move test_ruby() inside the only client
[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     MAIL_DIR=$MAIL_DIR $NOTMUCH_RUBY -I "$NOTMUCH_BUILDDIR/bindings/ruby"> OUTPUT
13 }
14
15 test_begin_subtest "compare thread ids"
16 test_ruby <<"EOF"
17 require 'notmuch'
18 $maildir = ENV['MAIL_DIR']
19 if not $maildir then
20   abort('environment variable MAIL_DIR must be set')
21 end
22 @db = Notmuch::Database.new($maildir)
23 @q = @db.query('tag:inbox')
24 @q.sort = Notmuch::SORT_OLDEST_FIRST
25 for t in @q.search_threads do
26   print t.thread_id, "\n"
27 end
28 EOF
29 notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
30 test_expect_equal_file EXPECTED OUTPUT
31
32 test_begin_subtest "compare message ids"
33 test_ruby <<"EOF"
34 require 'notmuch'
35 $maildir = ENV['MAIL_DIR']
36 if not $maildir then
37   abort('environment variable MAIL_DIR must be set')
38 end
39 @db = Notmuch::Database.new($maildir)
40 @q = @db.query('tag:inbox')
41 @q.sort = Notmuch::SORT_OLDEST_FIRST
42 for m in @q.search_messages do
43   print m.message_id, "\n"
44 end
45 EOF
46 notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
47 test_expect_equal_file EXPECTED OUTPUT
48
49 test_begin_subtest "get non-existent file"
50 test_ruby <<"EOF"
51 require 'notmuch'
52 $maildir = ENV['MAIL_DIR']
53 if not $maildir then
54   abort('environment variable MAIL_DIR must be set')
55 end
56 @db = Notmuch::Database.new($maildir)
57 result = @db.find_message_by_filename('i-dont-exist')
58 print (result == nil)
59 EOF
60 test_expect_equal "$(cat OUTPUT)" "true"
61
62 test_begin_subtest "count messages"
63 test_ruby <<"EOF"
64 require 'notmuch'
65 $maildir = ENV['MAIL_DIR']
66 if not $maildir then
67   abort('environment variable MAIL_DIR must be set')
68 end
69 @db = Notmuch::Database.new($maildir)
70 @q = @db.query('tag:inbox')
71 print @q.count_messages(),"\n"
72 EOF
73 notmuch count --output=messages tag:inbox > EXPECTED
74 test_expect_equal_file EXPECTED OUTPUT
75
76 test_begin_subtest "count threads"
77 test_ruby <<"EOF"
78 require 'notmuch'
79 $maildir = ENV['MAIL_DIR']
80 if not $maildir then
81   abort('environment variable MAIL_DIR must be set')
82 end
83 @db = Notmuch::Database.new($maildir)
84 @q = @db.query('tag:inbox')
85 print @q.count_threads(),"\n"
86 EOF
87 notmuch count --output=threads tag:inbox > EXPECTED
88 test_expect_equal_file EXPECTED OUTPUT
89
90 test_begin_subtest "get all tags"
91 test_ruby <<"EOF"
92 require 'notmuch'
93 $maildir = ENV['MAIL_DIR']
94 if not $maildir then
95   abort('environment variable MAIL_DIR must be set')
96 end
97 @db = Notmuch::Database.new($maildir)
98 @t = @db.all_tags()
99 for tag in @t do
100    print tag,"\n"
101 end
102 EOF
103 notmuch search --output=tags '*' > EXPECTED
104 test_expect_equal_file EXPECTED OUTPUT
105
106 test_done