[PATCH 3/3] test: add tests for Ruby bindings

Felipe Contreras felipe.contreras at gmail.com
Fri May 23 03:34:27 PDT 2014


Signed-off-by: Felipe Contreras <felipe.contreras at gmail.com>
---
 test/T540-ruby.sh | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/test-lib.sh  |  1 +
 2 files changed, 99 insertions(+)
 create mode 100755 test/T540-ruby.sh

diff --git a/test/T540-ruby.sh b/test/T540-ruby.sh
new file mode 100755
index 0000000..a9f6ac5
--- /dev/null
+++ b/test/T540-ruby.sh
@@ -0,0 +1,98 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2014 Felipe Contreras
+#
+
+test_description="Ruby bindings"
+
+. ./test-lib.sh
+
+export LD_LIBRARY_PATH=$TEST_DIRECTORY/../lib
+export RUBYLIB=$TEST_DIRECTORY/../bindings/ruby
+
+if ! test_have_prereq RUBY
+then
+	skip_all='skipping ruby tests'
+	test_done
+fi
+
+test_ruby () {
+	cat > test.rb <<-\EOF &&
+	#!/usr/bin/env ruby
+
+	require 'notmuch'
+
+	$MAIL_DIR = ENV['MAIL_DIR']
+	EOF
+	cat >> test.rb &&
+	ruby test.rb
+}
+
+test_expect_success 'setup' '
+	add_email_corpus &&
+	notmuch new --quiet &&
+	export MAIL_DIR
+'
+
+test_expect_success 'new and close' '
+	test_ruby <<-\EOF
+	db = Notmuch::Database.new($MAIL_DIR)
+	db.close
+	EOF
+'
+
+test_expect_success 'open' '
+	test_ruby <<-\EOF
+	Notmuch::Database.open($MAIL_DIR) do |db|
+	end
+	EOF
+'
+
+test_expect_success 'path' '
+	echo $MAIL_DIR > expected &&
+	test_ruby > actual <<-\EOF &&
+	Notmuch::Database.open($MAIL_DIR) do |db|
+		puts db.path
+	end
+	EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'query' '
+	notmuch count "tag:inbox" > expected &&
+	test_ruby > actual <<-\EOF &&
+	Notmuch::Database.open($MAIL_DIR) do |db|
+		query = db.query("tag:inbox")
+		puts query.count_messages
+	end
+	EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'query threads' '
+	notmuch search --output=threads "tag:inbox" > expected &&
+	test_ruby > actual <<-\EOF &&
+	Notmuch::Database.open($MAIL_DIR) do |db|
+		query = db.query("tag:inbox")
+		query.search_threads.each do |thread|
+			puts "thread:" + thread.thread_id
+		end
+	end
+	EOF
+	test_cmp expected actual
+'
+
+test_expect_success 'query messages' '
+	notmuch search --output=messages "tag:inbox" > expected &&
+	test_ruby > actual <<-\EOF &&
+	Notmuch::Database.open($MAIL_DIR) do |db|
+		query = db.query("tag:inbox")
+		query.search_messages.each do |message|
+			puts "id:" + message.message_id
+		end
+	end
+	EOF
+	test_cmp expected actual
+'
+
+test_done
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 8697d6a..1f9dd1f 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -1208,6 +1208,7 @@ test_init_ () {
 
 emacs_generate_script
 
+grep -q "WITH_RUBY = 1" ../Makefile.config && test_set_prereq RUBY
 
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
-- 
1.9.3+fc1~5~gfaddd51



More information about the notmuch mailing list