null+****@clear*****
null+****@clear*****
2010年 11月 23日 (火) 20:32:39 JST
Kouhei Sutou 2010-11-23 11:32:39 +0000 (Tue, 23 Nov 2010)
New Revision: c06938b0b317c92d855f5145238baeae0406505a
Log:
add a test for grntest.
Added files:
test/unit/grntest/Makefile.am
test/unit/grntest/test-out-http.rb
test/unit/lib/ruby/groonga-grntest-test-utils.rb
Modified files:
configure.ac
test/unit/Makefile.am
test/unit/lib/ruby/Makefile.am
test/unit/lib/ruby/groonga-test-utils.rb
test/unit/run-test.rb
Modified: configure.ac (+5 -0)
===================================================================
--- configure.ac 2010-11-23 11:23:18 +0000 (99bf443)
+++ configure.ac 2010-11-23 11:32:39 +0000 (abcf9be)
@@ -130,6 +130,7 @@ AC_CONFIG_FILES([Makefile
test/unit/http/Makefile
test/unit/gqtp/Makefile
test/unit/story/Makefile
+ test/unit/grntest/Makefile
test/benchmark/Makefile
test/benchmark/lib/Makefile
])
@@ -407,6 +408,10 @@ AC_SUBST(WINDOWS_LIBS)
GROONGA="\$(abs_top_builddir)/src/groonga"
AC_SUBST(GROONGA)
+# grntest binary path
+GRNTEST="\$(abs_top_builddir)/src/grntest"
+AC_SUBST(GRNTEST)
+
# check Cutter with GLib support if available
REQUIRED_MINIMUM_CUTTER_VERSION=1.1.3
m4_ifdef([AC_CHECK_GCUTTER], [
Modified: test/unit/Makefile.am (+4 -2)
===================================================================
--- test/unit/Makefile.am 2010-11-23 11:23:18 +0000 (409d43b)
+++ test/unit/Makefile.am 2010-11-23 11:32:39 +0000 (202375b)
@@ -6,7 +6,8 @@ SUBDIRS = \
memcached \
http \
gqtp \
- story
+ story \
+ grntest
if WITH_UNIT_TEST
TESTS = run-test.sh
@@ -17,7 +18,8 @@ TESTS_ENVIRONMENT = \
CUTTER="$(CUTTER)" \
CUTTER_VERBOSE=yes \
RUBY="$(RUBY)" \
- GROONGA="$(GROONGA)"
+ GROONGA="$(GROONGA)" \
+ GRNTEST="$(GRNTEST)"
if WITH_CUTTER
noinst_LTLIBRARIES = suite-groonga-test.la
Added: test/unit/grntest/Makefile.am (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/grntest/Makefile.am 2010-11-23 11:32:39 +0000 (e377f6e)
@@ -0,0 +1,2 @@
+EXTRA_DIST = \
+ test-out-http.rb
Added: test/unit/grntest/test-out-http.rb (+56 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/grntest/test-out-http.rb 2010-11-23 11:32:39 +0000 (c1a9fad)
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+class GrnTestOutHTTPTest < Test::Unit::TestCase
+ include GroongaGrnTestTestUtils
+
+ CONFIG_ENV = {"GRN_CONFIG_PATH" => ""}
+
+ def setup
+ setup_database
+ end
+
+ def teardown
+ teardown_database
+ end
+
+ def test_out_http
+ command = tempfile("command") do |file|
+ file.puts('select Shops --sortby _id --limit 5 --output_columns "name"')
+ end
+ expected = tempfile("expected")
+ script = tempfile("script") do |file|
+ file.puts("out_http #{command.path} #{expected.path}")
+ end
+ output, error, status = invoke_grntest("--noftp",
+ "--groonga", groonga,
+ "--protocol", "http",
+ "--log-output-dir", @tmp_dir,
+ script.path, @database_path)
+ assert_predicate(status, :success?, [output, error])
+ status, result = JSON.parse(expected.read)
+ assert_equal([0,
+ [[[36],
+ [["name", "ShortText"]],
+ ["根津のたいやき"],
+ ["たい焼 カタオカ"],
+ ["そばたいやき空"],
+ ["車"],
+ ["広瀬屋"]]]],
+ [status[0], result])
+ end
+end
Modified: test/unit/lib/ruby/Makefile.am (+2 -1)
===================================================================
--- test/unit/lib/ruby/Makefile.am 2010-11-23 11:23:18 +0000 (69613d6)
+++ test/unit/lib/ruby/Makefile.am 2010-11-23 11:32:39 +0000 (2446ccd)
@@ -2,4 +2,5 @@ EXTRA_DIST = \
groonga-test-utils.rb \
groonga-constants.rb \
groonga-http-test-utils.rb \
- groonga-local-gqtp-test-utils.rb
+ groonga-local-gqtp-test-utils.rb \
+ groonga-grntest-test-utils.rb
Added: test/unit/lib/ruby/groonga-grntest-test-utils.rb (+72 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/lib/ruby/groonga-grntest-test-utils.rb 2010-11-23 11:32:39 +0000 (5286fe3)
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+require "tempfile"
+require 'groonga-test-utils'
+
+module GroongaGrnTestTestUtils
+ include GroongaTestUtils
+
+ def setup_database
+ setup_database_path
+ input = ""
+ ["ddl.grn", "areas.grn", "categories.grn", "shops.grn"].each do |grn|
+ input << File.read(taiyaki_story_fixture(grn))
+ end
+ output, error, status = invoke_groonga("-n", @database_path, :input => input)
+ assert_predicate(status, :success?, [output, error])
+ end
+
+ def teardown_database
+ teardown_database_path
+ end
+
+ private
+ def guess_grntest_path
+ grntest = ENV["GRNTEST"]
+ grntest ||= File.join(guess_top_source_dir, "src", "grntest")
+ File.expand_path(grntest)
+ end
+
+ def grntest
+ @grntest ||= guess_grntest_path
+ end
+
+ def invoke_grntest(*args)
+ args.unshift(grntest)
+ invoke_command(*args)
+ end
+
+ def taiyaki_story_fixture(file)
+ File.join(File.dirname(__FILE__),
+ "..",
+ "..",
+ "fixtures",
+ "story",
+ "taiyaki",
+ file)
+ end
+
+ def tempfile(name)
+ file = Tempfile.new(name, @tmp_base_dir)
+ if block_given?
+ yield(file)
+ file.close
+ end
+ file
+ end
+end
Modified: test/unit/lib/ruby/groonga-test-utils.rb (+1 -1)
===================================================================
--- test/unit/lib/ruby/groonga-test-utils.rb 2010-11-23 11:23:18 +0000 (5f88ed0)
+++ test/unit/lib/ruby/groonga-test-utils.rb 2010-11-23 11:32:39 +0000 (0e404f7)
@@ -26,7 +26,7 @@ module GroongaTestUtils
def setup_database_path
base_dir = ENV["BUILD_DIR"] || ENV["BASE_DIR"]
base_dir ||= File.join(File.dirname(__FILE__), "..", "..")
- @tmp_base_dir = File.join(base_dir, "tmp")
+ @tmp_base_dir = File.join(File.expand_path(base_dir), "tmp")
FileUtils.rm_rf(@tmp_base_dir)
FileUtils.mkdir_p(@tmp_base_dir)
@tmp_dir = Dir.mktmpdir("tmp", @tmp_base_dir)
Modified: test/unit/run-test.rb (+1 -0)
===================================================================
--- test/unit/run-test.rb 2010-11-23 11:23:18 +0000 (9f9d05b)
+++ test/unit/run-test.rb 2010-11-23 11:32:39 +0000 (6c3abce)
@@ -67,6 +67,7 @@ $LOAD_PATH.unshift(File.join(base_dir, "lib", "ruby"))
require 'groonga-test-utils'
require 'groonga-http-test-utils'
require 'groonga-local-gqtp-test-utils'
+require 'groonga-grntest-test-utils'
ARGV.unshift("--exclude", "run-test.rb")
ARGV.unshift("--notify")