]> 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 [ "${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 test_done