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