Navigation Menu

Skip to content

Commit

Permalink
Always use "db/db" for db path
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 11, 2012
1 parent d6af49c commit c1a858c
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions lib/grntest/tester.rb
Expand Up @@ -87,7 +87,7 @@ def create_option_parser(tester, tag)
parser.on("--base-directory=DIRECTORY",
"Use DIRECTORY as a base directory of relative path",
"(#{tester.base_directory})") do |directory|
tester.base_directory = directory
tester.base_directory = Pathname(directory)
end

parser.on("--diff=DIFF",
Expand Down Expand Up @@ -205,7 +205,7 @@ def initialize
@groonga_suggest_create_dataset = "groonga-suggest-create-dataset"
@interface = :stdio
@testee = "groonga"
@base_directory = "."
@base_directory = Pathname(".")
@reporter = nil
@n_workers = 1
@output = $stdout
Expand Down Expand Up @@ -563,7 +563,7 @@ def run_test_suites(test_suites)
@tester.n_workers.times do |i|
workers << Worker.new(i, @tester, @result, @reporter)
end
@result.workers = workers.dup
@result.workers = workers
@reporter.start(@result)

succeeded = true
Expand Down Expand Up @@ -662,11 +662,13 @@ def run
private
def run_groonga_script
create_temporary_directory do |directory_path|
db_path = File.join(directory_path, "db")
db_dir = directory_path + "db"
FileUtils.mkdir_p(db_dir.to_s)
db_path = db_dir + "db"
context = Executor::Context.new
context.temporary_directory_path = directory_path
context.db_path = db_path
context.base_directory = @tester.base_directory
context.base_directory = @tester.base_directory.expand_path
context.groonga_suggest_create_dataset =
@tester.groonga_suggest_create_dataset
run_groonga(context) do |executor|
Expand All @@ -682,7 +684,7 @@ def create_temporary_directory
FileUtils.rm_rf(path, :secure => true)
FileUtils.mkdir_p(path)
begin
yield(path)
yield(Pathname(path).expand_path)
ensure
if @tester.keep_database? and File.exist?(path)
FileUtils.rm_rf(keep_database_path, :secure => true)
Expand Down Expand Up @@ -719,7 +721,9 @@ def run_groonga_stdio(context)
command_line += [
"--input-fd", input_fd.to_s,
"--output-fd", output_fd.to_s,
"-n", context.db_path,
"--working-directory", context.temporary_directory_path.to_s,
"-n",
context.relative_db_path.to_s,
]
env = {}
options = {
Expand Down Expand Up @@ -755,8 +759,7 @@ def groonga_command_line(context)
command_line << "--mode=execute"
end
command_line << @tester.gdb
gdb_command_path = File.join(context.temporary_directory_path,
"groonga.gdb")
gdb_command_path = context.temporary_directory_path + "groonga.gdb"
File.open(gdb_command_path, "w") do |gdb_command|
gdb_command.puts(<<-EOC)
break main
Expand Down Expand Up @@ -836,27 +839,30 @@ def groonga_http_command(host, port, pid_file, context)
"--bind-address", host,
"--port", port.to_s,
"--protocol", "http",
"--log-path", context.log_path,
"--log-path", context.log_path.to_s,
"--working-directory", context.temporary_directory_path.to_s,
"-d",
"-n", context.db_path,
"-n",
context.relative_db_path.to_s,
]
when "groonga-httpd"
db_path = context.db_path
config_file = create_config_file(host, port, db_path, pid_file)
config_file = create_config_file(context, host, port, pid_file)
command_line = [
@tester.groonga_httpd,
"-c", config_file.path,
"-p", File.join(File.dirname(db_path), "/"),
"-p", "#{context.db_path.parent}/",
]
end
command_line
end

def create_config_file(host, port, db_path, pid_file)
create_empty_database(db_path)
def create_config_file(context, host, port, pid_file)
create_empty_database(context.db_path.to_s)
config_file = Tempfile.new("test-httpd.conf")
config_file.puts <<EOF
worker_processes 1;
working_directory #{context.temporary_directory_path};
error_log #{context.temporary_directory_path + "error.log"};
pid #{pid_file.path};
events {
worker_connections 1024;
Expand All @@ -869,7 +875,7 @@ def create_config_file(host, port, db_path, pid_file)
listen #{port};
server_name #{host};
location /d/ {
groonga_database #{db_path};
groonga_database #{context.relative_db_path};
groonga on;
}
}
Expand Down Expand Up @@ -987,9 +993,9 @@ class Context
attr_accessor :result
def initialize
@logging = true
@base_directory = "."
@temporary_directory_path = "tmp"
@db_path = "db"
@base_directory = Pathname(".")
@temporary_directory_path = Pathname("tmp")
@db_path = Pathname("db")
@groonga_suggest_create_dataset = "groonga-suggest-create-dataset"
@n_nested = 0
@result = []
Expand All @@ -1012,11 +1018,15 @@ def top_level?
end

def log_path
File.join(@temporary_directory_path, "groonga.log")
@temporary_directory_path + "groonga.log"
end

def log
@log ||= File.open(log_path, "a+")
@log ||= File.open(log_path.to_s, "a+")
end

def relative_db_path
@db_path.relative_path_from(@temporary_directory_path)
end
end

Expand Down Expand Up @@ -1118,7 +1128,7 @@ def execute_comment(content)
when "include"
path = options.first
return if path.nil?
execute_script(path)
execute_script(Pathname(path))
end
end

Expand All @@ -1138,11 +1148,10 @@ def execute_suggest_create_dataset(dataset_name)
end
end

def execute_script(path)
def execute_script(script_path)
executor = create_sub_executor(@context)
script_path = Pathname(path)
if script_path.relative?
script_path = Pathname(@context.base_directory) + script_path
script_path = @context.base_directory + script_path
end
executor.execute(script_path)
end
Expand Down

0 comments on commit c1a858c

Please sign in to comment.