null+****@clear*****
null+****@clear*****
2012年 3月 6日 (火) 17:13:31 JST
Kouhei Sutou 2012-03-06 17:13:31 +0900 (Tue, 06 Mar 2012)
New Revision: be4e41b18475984578963ddbc8fc7aa4fb19fc8b
Log:
Support suggest-create-dataset command
Modified files:
lib/groonga/tester.rb
test/run-test.rb
test/test-executor.rb
Modified: lib/groonga/tester.rb (+29 -6)
===================================================================
--- lib/groonga/tester.rb 2012-03-06 17:13:16 +0900 (b3d37be)
+++ lib/groonga/tester.rb 2012-03-06 17:13:31 +0900 (90e6b6f)
@@ -178,9 +178,13 @@ module Groonga
private
def run_groonga_script
create_temporary_directory do |directory_path|
- run_groonga(File.join(directory_path, "db")) do |io|
+ db_path = File.join(directory_path, "db")
+ run_groonga(db_path) do |io|
context = Executor::Context.new
+ context.db_path = db_path
context.base_directory =****@teste*****_directory
+ context.groonga_suggest_create_dataset =
+ @tester.groonga_suggest_create_dataset
executer = Executor.new(io, context)
executer.execute(@test_script_path)
end
@@ -295,10 +299,13 @@ module Groonga
class Executor
class Context
attr_writer :logging
- attr_accessor :base_directory, :result
+ attr_accessor :base_directory, :db_path, :groonga_suggest_create_dataset
+ attr_accessor :result
def initialize
@logging = true
@base_directory = "."
+ @db_path = "db"
+ @groonga_suggest_create_dataset = "groonga-suggest-create-dataset"
@n_nested = 0
@result = []
end
@@ -407,18 +414,34 @@ module Groonga
end
def execute_comment(content)
- case content.strip
+ command, *options = Shellwords.split(content)
+ case command
when "disable-logging"
@context.logging = false
when "enable-logging"
@context.logging = true
- when /\Ainclude\s+/
- path = $POSTMATCH.strip
- return if path.empty?
+ when "suggest-create-dataset"
+ dataset_name = options.first
+ return if dataset_name.nil?
+ execute_suggest_create_dataset(dataset_name)
+ when "include"
+ path = options.first
+ return if path.nil?
execute_script(path)
end
end
+ def execute_suggest_create_dataset(dataset_name)
+ command_line = [@context.groonga_suggest_create_dataset,
+ @context.db_path,
+ dataset_name]
+ log_input(command_line.join(" "))
+ IO.popen(command_line, "r:ascii-8bit") do |io|
+ io.close_write
+ log_output(io.read)
+ end
+ end
+
def execute_script(path)
executer = self.class.new(@groonga, @context)
script_path = Pathname(path)
Modified: test/run-test.rb (+1 -0)
===================================================================
--- test/run-test.rb 2012-03-06 17:13:16 +0900 (a5eeaa1)
+++ test/run-test.rb 2012-03-06 17:13:31 +0900 (65d7c88)
@@ -24,5 +24,6 @@ test_dir = File.join(base_dir, "test")
$LOAD_PATH.unshift(lib_dir)
require 'test-unit'
+require 'test/unit/rr'
exit(Test::Unit::AutoRunner.run(true))
Modified: test/test-executor.rb (+6 -1)
===================================================================
--- test/test-executor.rb 2012-03-06 17:13:16 +0900 (5c39314)
+++ test/test-executor.rb 2012-03-06 17:13:31 +0900 (7c184b9)
@@ -18,7 +18,7 @@ require "groonga/tester"
class TestExecutor < Test::Unit::TestCase
def setup
- @groonga = StringIO.new
+ @groonga = stub
@executor = Groonga::Tester::Executor.new(@groonga)
@context =****@execu*****
@script = Tempfile.new("test-executor")
@@ -44,5 +44,10 @@ class TestExecutor < Test::Unit::TestCase
execute("# enable-logging")
assert_predicate(@context, :logging?)
end
+
+ def test_suggest_create_dataset
+ mock(@executor).execute_suggest_create_dataset("shop")
+ execute("# suggest-create-dataset shop")
+ end
end
end