[Groonga-commit] groonga/groonga at 948ec0b [master] test: add command line test

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jan 19 18:38:06 JST 2016


Kouhei Sutou	2016-01-19 18:38:06 +0900 (Tue, 19 Jan 2016)

  New Revision: 948ec0b8255063215dd5695da3c214e49875da6c
  https://github.com/groonga/groonga/commit/948ec0b8255063215dd5695da3c214e49875da6c

  Message:
    test: add command line test
    
    It's not completed yet. lock_acquire command should be implemented.

  Added files:
    test/command_line/helper.rb
    test/command_line/helper/command_runner.rb
    test/command_line/helper/sandbox.rb
    test/command_line/run-test.rb
    test/command_line/suite/grndb/test_check.rb

  Added: test/command_line/helper.rb (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command_line/helper.rb    2016-01-19 18:38:06 +0900 (569fea9)
@@ -0,0 +1,14 @@
+require "fileutils"
+
+require "test-unit"
+
+require_relative "helper/sandbox"
+require_relative "helper/command_runner"
+
+class GroongaTestCase < Test::Unit::TestCase
+  include Sandbox
+  include CommandRunner
+
+  setup :setup_sandbox, :before => :prepend
+  teardown :teardown_sandbox, :after => :append
+end

  Added: test/command_line/helper/command_runner.rb (+45 -0) 100644
===================================================================
--- /dev/null
+++ test/command_line/helper/command_runner.rb    2016-01-19 18:38:06 +0900 (5f33e66)
@@ -0,0 +1,45 @@
+module CommandRunner
+  def run_command(*command_line)
+    env = {}
+    options = {
+      :out => @output_log_path.to_s,
+      :err => @error_output_log_path.to_s,
+    }
+    unless system(env, *command_line, options)
+      message = <<-MESSAGE.chomp
+failed to run: #{command_line.join(" ")}
+-- output start --
+#{@output_log_path.read.chomp}
+-- output end --
+-- error output start --
+#{@error_output_log_path.read.chomp}
+-- error output end --
+      MESSAGE
+      raise message
+    end
+    [@output_log_path.read, @error_output_log_path.read]
+  end
+
+  def groonga(command, *arguments)
+    command_line = [
+      "groonga",
+      "--log-path", @log_path.to_s,
+      "--query-log-path", @query_log_path.to_s,
+    ]
+    command_line << "-n" unless @database_path.exist?
+    command_line << @database_path.to_s
+    command_line << command
+    command_line.concat(arguments)
+    run_command(*command_line)
+  end
+
+  def grndb(command, *arguments)
+    command_line = [
+      "grndb",
+    ]
+    command_line << @database_path.to_s
+    command_line << command
+    command_line.concat(arguments)
+    run_command(*command_line)
+  end
+end

  Added: test/command_line/helper/sandbox.rb (+45 -0) 100644
===================================================================
--- /dev/null
+++ test/command_line/helper/sandbox.rb    2016-01-19 18:38:06 +0900 (dc654aa)
@@ -0,0 +1,45 @@
+module Sandbox
+  private
+  def setup_sandbox
+    setup_tmp_directory
+    setup_log_path
+    setup_database_path
+  end
+
+  def setup_tmp_directory
+    @base_tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
+    memory_file_system = "/run/shm"
+    if File.exist?(memory_file_system)
+      FileUtils.mkdir_p(@base_tmp_dir.parent.to_s)
+      FileUtils.rm_f(@base_tmp_dir.to_s)
+      FileUtils.ln_s(memory_file_system, @base_tmp_dir.to_s)
+    else
+      FileUtils.mkdir_p(@base_tmp_dir.to_s)
+    end
+
+    @tmp_dir = @base_tmp_dir + "groonga-command-line"
+    FileUtils.rm_rf(@tmp_dir.to_s)
+    FileUtils.mkdir_p(@tmp_dir.to_s)
+  end
+
+  def setup_log_path
+    @log_path = @tmp_dir + "groonga.log"
+    @query_log_path = @tmp_dir + "groonga-query.log"
+    @output_log_path = @tmp_dir + "output.log"
+    @error_output_log_path = @tmp_dir + "error-output.log"
+  end
+
+  def setup_database_path
+    name_for_path = name.gsub(/[\(\)\[\] ]/, "-")
+    @database_path = @tmp_dir + "#{name_for_path}.db"
+  end
+
+  def teardown_sandbox
+    teardown_tmp_directory
+  end
+
+  def teardown_tmp_directory
+    FileUtils.rm_rf(@tmp_dir.to_s)
+    FileUtils.rm_rf(@base_tmp_dir.to_s)
+  end
+end

  Added: test/command_line/run-test.rb (+25 -0) 100755
===================================================================
--- /dev/null
+++ test/command_line/run-test.rb    2016-01-19 18:38:06 +0900 (f873fa2)
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+require "rbconfig"
+require "pathname"
+require "fileutils"
+
+base_dir_path       = Pathname(__FILE__).expand_path.dirname
+source_top_dir_path = base_dir_path.parent.parent
+build_top_dir_path  = Pathname($0).expand_path.dirname.parent.parent
+build_base_dir_path = build_top_dir_path + "test/command_line"
+
+Dir.chdir(build_top_dir_path.to_s) do
+  system("make -j8 > /dev/null") or exit(false)
+end
+
+ENV["PATH"] = [
+  (build_top_dir_path + "src").to_s,
+  ENV["PATH"],
+].join(File::PATH_SEPARATOR)
+ENV["GRN_PLUGINS_DIR"]      = (build_top_dir_path + "plugins").to_s
+ENV["GRN_RUBY_SCRIPTS_DIR"] = (build_top_dir_path + "lib/mrb/scripts").to_s
+
+require_relative "helper"
+
+exit(Test::Unit::AutoRunner.run(true, (base_dir_path + "suite").to_s))

  Added: test/command_line/suite/grndb/test_check.rb (+9 -0) 100644
===================================================================
--- /dev/null
+++ test/command_line/suite/grndb/test_check.rb    2016-01-19 18:38:06 +0900 (bc79813)
@@ -0,0 +1,9 @@
+class TestGrnDBCheck < GroongaTestCase
+  def setup
+  end
+
+  def test_locked_database
+    groonga("lock_acquire")
+    grndb("check")
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index