Kouhei Sutou
null+****@clear*****
Thu Aug 7 10:43:18 JST 2014
Kouhei Sutou 2014-08-07 10:43:18 +0900 (Thu, 07 Aug 2014) New Revision: c5994e91f9f07c5901e51d4f37e4d4349a0e8200 https://github.com/groonga/groonga/commit/c5994e91f9f07c5901e51d4f37e4d4349a0e8200 Message: Remove unit tests written by Ruby Because we can't maintain them. :< Removed files: test/unit/Gemfile test/unit/command/Makefile.am test/unit/command/test-bom.rb test/unit/command/test-config-file.rb test/unit/command/test-option.rb test/unit/groonga-benchmark/Makefile.am test/unit/groonga-benchmark/test-gqtp.rb test/unit/groonga-benchmark/test-http.rb test/unit/groonga-benchmark/test-option.rb test/unit/http/.gitignore test/unit/http/Makefile.am test/unit/http/test-invalid-http.rb test/unit/http/test-static-html.rb test/unit/lib/ruby/Makefile.am test/unit/lib/ruby/groonga-benchmark-test-utils.rb test/unit/lib/ruby/groonga-constants.rb test/unit/lib/ruby/groonga-http-test-utils.rb test/unit/lib/ruby/groonga-local-gqtp-test-utils.rb test/unit/lib/ruby/groonga-test-utils.rb test/unit/run-test.rb test/unit/suggest/test-httpd.rb Modified files: configure.ac test/unit/Makefile.am test/unit/lib/Makefile.am test/unit/run-test.sh tools/travis-script.sh Modified: configure.ac (+0 -3) =================================================================== --- configure.ac 2014-08-06 23:05:09 +0900 (b226777) +++ configure.ac 2014-08-07 10:43:18 +0900 (ea96a1a) @@ -275,7 +275,6 @@ AC_CONFIG_FILES([ test/Makefile test/unit/Makefile test/unit/lib/Makefile - test/unit/lib/ruby/Makefile test/unit/fixtures/Makefile test/unit/fixtures/inverted-index/Makefile test/unit/fixtures/stress/Makefile @@ -286,9 +285,7 @@ AC_CONFIG_FILES([ test/unit/util/Makefile test/unit/core/Makefile test/unit/core/dat/Makefile - test/unit/http/Makefile test/unit/story/Makefile - test/unit/groonga-benchmark/Makefile test/command/Makefile benchmark/Makefile benchmark/fixtures/Makefile Deleted: test/unit/Gemfile (+0 -23) 100644 =================================================================== --- test/unit/Gemfile 2014-08-06 23:05:09 +0900 (ed09b48) +++ /dev/null @@ -1,23 +0,0 @@ -# -*- mode: ruby; coding: utf-8 -*- -# -# Copyright (C) 2011 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -source "http://rubygems.org/" - -gem "test-unit" -gem "test-unit-notify" -gem "json" -gem "msgpack" Modified: test/unit/Makefile.am (+2 -11) =================================================================== --- test/unit/Makefile.am 2014-08-06 23:05:09 +0900 (1b36dd8) +++ test/unit/Makefile.am 2014-08-07 10:43:18 +0900 (75d97ce) @@ -3,9 +3,7 @@ SUBDIRS = \ fixtures \ util \ core \ - http \ - story \ - groonga-benchmark + story if WITH_UNIT_TEST TESTS = run-test.sh @@ -15,7 +13,6 @@ TESTS_ENVIRONMENT = \ BUILD_DIR="$(builddir)" \ CUTTER="$(CUTTER)" \ CUTTER_VERBOSE=yes \ - RUBY="$(RUBY)" \ GROONGA="$(GROONGA)" \ GROONGA_BENCHMARK="$(GROONGA_BENCHMARK)" @@ -25,14 +22,8 @@ else TESTS_ENVIRONMENT += NO_CUTTER=yes endif -if !WITH_RUBY -TESTS_ENVIRONMENT += NO_RUBY=yes -endif - EXTRA_DIST = \ - run-test.sh \ - run-test.rb \ - Gemfile + run-test.sh AM_CPPFLAGS = \ -I$(srcdir) \ Deleted: test/unit/command/Makefile.am (+0 -4) 100644 =================================================================== --- test/unit/command/Makefile.am 2014-08-06 23:05:09 +0900 (020194b) +++ /dev/null @@ -1,4 +0,0 @@ -EXTRA_DIST = \ - test-config-file.rb \ - test-option.rb \ - test-option-bom.rb Deleted: test/unit/command/test-bom.rb (+0 -46) 100644 =================================================================== --- test/unit/command/test-bom.rb 2014-08-06 23:05:09 +0900 (cc366c5) +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class BOMTest < Test::Unit::TestCase - include GroongaTestUtils - - def setup - setup_database_path - @input_file = File.join(@tmp_dir, "commands") - end - - def teardown - teardown_database_path - end - - def test_no_bom - open(@input_file, "w") do |file| - file.puts("defrag") - end - assert_equal("[[0,0.0,0.0],true]\n", - run_groonga("--file", @input_file, "-n", @database_path)) - end - - def test_bom - open(@input_file, "w") do |file| - file.print("\xef\xbb\xbf") - file.puts("defrag") - end - assert_equal("[[0,0.0,0.0],true]\n", - run_groonga("--file", @input_file, "-n", @database_path)) - end -end Deleted: test/unit/command/test-config-file.rb (+0 -39) 100644 =================================================================== --- test/unit/command/test-config-file.rb 2014-08-06 23:05:09 +0900 (0b9649d) +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010 Nobuyoshi Nakada <nakada �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class ConfigFileTest < Test::Unit::TestCase - include GroongaTestUtils - - def setup - setup_database_path - @config_env = ENV['GRN_CONFIG_PATH'] - @config_path = File.join(@tmp_dir, "groonga.conf") - ENV['GRN_CONFIG_PATH'] = @config_path - end - - def teardown - ENV['GRN_CONFIG_PATH'] = @config_env - FileUtils.rm_f(@config_path) - teardown_database_path - end - - def test_config_empty - open(@config_path, "w") {|f|} - assert_equal("[[0,0.0,0.0],true]\n", - run_groonga("-n", @database_path, "quit")) - end -end Deleted: test/unit/command/test-option.rb (+0 -121) 100644 =================================================================== --- test/unit/command/test-option.rb 2014-08-06 23:05:09 +0900 (561c993) +++ /dev/null @@ -1,121 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010 Nobuyoshi Nakada <nakada �� clear-code.com> -# Copyright (C) 2011-2012 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class OptionTest < Test::Unit::TestCase - include GroongaTestUtils - - CONFIG_ENV = {"GRN_CONFIG_PATH" => ""} - - def setup - setup_database_path - end - - def teardown - teardown_database_path - end - - def test_daemon_pid_path - pid_path = File.join(@tmp_dir, "groonga.pid") - assert_path_not_exist(pid_path) - assert_equal("", run_groonga("-d", "--pid-path", pid_path)) - assert_path_exist(pid_path) - pid = File.open(pid_path) do |f| - Integer(f.read) - end - assert_equal(1, Process.kill(:INT, pid)) - 30.times do - break unless File.exist?(pid_path) - sleep 0.1 - end - assert_path_not_exist(pid_path) - end - - def test_help - assert_run_groonga(/\AUsage: groonga \[options\.\.\.\] \[dest\]$/, - "", - ["--help"]) - assert_predicate($?, :success?) - end - - def test_mandatory_argument_missing - usage = 'Usage: groonga \[options\.\.\.\] \[dest\]$' - %w[-e -l -p -i -t - --document-root --protocol --log-path - --query-log-path --pid-path --config-path].each do |option| - status = assert_run_groonga("", - /: option '#{option}' needs argument\.$/, - option) - assert_not_predicate(status, :success?) - end - end - - # FIXME: This test is too dirty. It should be split. - def test_config_path - test_options = %W[ - port=1.1.1.1 encoding=none encoding=euc-jp - max-threads=12345 bind-address=localhost - log-level=1 server-id=localhost - ] - config_file = File.join(@tmp_dir, "test-option.config") - assert_path_not_exist(config_file) - status = assert_run_groonga("", - /can't open config file: #{Regexp.quote(config_file)} /, - [CONFIG_ENV, "--config-path=#{config_file}"]) - assert_not_predicate(status, :success?) - open(config_file, "w") {} - status = assert_run_groonga("", - "", - [CONFIG_ENV, "--config-path=#{config_file}"]) - assert_predicate(status, :success?) - - default_config = run_groonga("--show-config").split(/\n/) - - test_options.each do |opt| - status = assert_run_groonga(([opt] + default_config).sort.join("\n"), - "", - [CONFIG_ENV, - "--#{opt}", - "--config-path=#{config_file}", - "--show-config"]) do |stdout, stderr| - [stdout.split(/\n/).sort.join("\n"), stderr] - end - assert_predicate(status, :success?) - end - - test_options.each do |opt| - open(config_file, "w") {|f| f.puts opt} - status = assert_run_groonga(([opt] + default_config).sort.join("\n"), - "", - [CONFIG_ENV, - "--config-path=#{config_file}", - "--show-config"]) do |stdout, stderr| - [stdout.split(/\n/).sort.join("\n"), stderr] - end - assert_predicate(status, :success?) - end - ensure - FileUtils.rm_f(config_file) - end - - def test_default_command_version - result = JSON.parse(run_groonga("--default-command-version", "1", - "-n", @database_path, - "status")) - assert_equal(1, result[1]["command_version"]) - end -end Deleted: test/unit/groonga-benchmark/Makefile.am (+0 -4) 100644 =================================================================== --- test/unit/groonga-benchmark/Makefile.am 2014-08-06 23:05:09 +0900 (1c8d408) +++ /dev/null @@ -1,4 +0,0 @@ -EXTRA_DIST = \ - test-http.rb \ - test-gqtp.rb \ - test-option.rb Deleted: test/unit/groonga-benchmark/test-gqtp.rb (+0 -54) 100644 =================================================================== --- test/unit/groonga-benchmark/test-gqtp.rb 2014-08-06 23:05:09 +0900 (99549c4) +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2011 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class GroongaBenchmarkGQTPTest < Test::Unit::TestCase - include GroongaBenchmarkTestUtils - - CONFIG_ENV = {"GRN_CONFIG_PATH" => ""} - - def setup - setup_database - end - - def teardown - teardown_database - end - - def test_do_multi_thread - command = 'select Shops --sortby _id --limit 5 --output_columns "name"' - command_file = tempfile("command") do |file| - file.puts(command) - end - script_file = tempfile("script") do |file| - file.puts("do_gqtp #{command_file.path} 10 5") - file.puts("do_gqtp #{command_file.path} 4 2") - end - output, error, status = invoke_groonga_benchmark("--groonga", groonga, - "--protocol", "gqtp", - "--port", "20041", - "--log-output-dir", @tmp_dir, - script_file.path, - @database_path) - assert_predicate(status, :success?, [output, error]) - log_file = nil - Dir.glob("#{@tmp_dir}/*.log") do |file| - log_file = file - end - result = JSON.parse(File.read(log_file)) - assert_equal((10 * 5) + (4 * 2), result.last["queries"]) - end -end Deleted: test/unit/groonga-benchmark/test-http.rb (+0 -178) 100644 =================================================================== --- test/unit/groonga-benchmark/test-http.rb 2014-08-06 23:05:09 +0900 (bf085b5) +++ /dev/null @@ -1,178 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010-2011 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class GroongaBenchmarkHTTPTest < Test::Unit::TestCase - include GroongaBenchmarkTestUtils - - 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_groonga_benchmark("--groonga", groonga, - "--protocol", "http", - "--port", "20041", - "--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 - - def test_report_http_json - command = tempfile("command") do |file| - file.puts('select Shops --sortby _id --limit 5 --output_columns "name"') - end - groonga_benchmark_command = "rep_http #{command.path}" - script = tempfile("script") do |file| - file.puts(groonga_benchmark_command) - end - log = tempfile("log") - output, error, status = invoke_groonga_benchmark("--groonga", groonga, - "--protocol", "http", - "--port", "20041", - "--log-path", log.path, - script.path, @database_path) - assert_predicate(status, :success?, [output, error]) - jobs_list = JSON.parse(log.read).find_all do |element| - element.has_key?("jobs") - end - assert_equal([groonga_benchmark_command], - jobs_list.collect {|jobs| jobs["jobs"]}) - end - - def test_report_http_xml - command = tempfile("command") do |file| - file.puts('select Shops --sortby _id --limit 5 --output_columns "name" ' + - '--output_type xml') - end - groonga_benchmark_command = "rep_http #{command.path}" - script = tempfile("script") do |file| - file.puts(groonga_benchmark_command) - end - log = tempfile("log") - output, error, status = invoke_groonga_benchmark("--groonga", groonga, - "--protocol", "http", - "--port", "20041", - "--log-path", log.path, - script.path, @database_path) - assert_predicate(status, :success?, [output, error]) - jobs_list = JSON.parse(log.read).find_all do |element| - element.has_key?("jobs") - end - assert_equal([groonga_benchmark_command], - jobs_list.collect {|jobs| jobs["jobs"]}) - end - - def test_test_http_same - command = 'select Shops --sortby _id --limit 5 --output_columns "name"' - command_file = tempfile("command") do |file| - file.puts(command) - end - expected = - '[[0,1290511592.67556,0.00068249],' + - '[[[36],' + - '[["name","ShortText"]],' + - '["根津のたいやき"],' + - '["たい焼 カタオカ"],' + - '["そばたいやき空"],' + - '["車"],' + - '["広瀬屋"]]]]' - expected_file = tempfile("expected") do |file| - file.puts(expected) - end - script_file = tempfile("script") do |file| - file.puts("test_http #{command_file.path} #{expected_file.path}") - end - output, error, status = invoke_groonga_benchmark("--groonga", groonga, - "--protocol", "http", - "--port", "20041", - "--log-output-dir", @tmp_dir, - script_file.path, - @database_path) - assert_predicate(status, :success?, [output, error]) - assert_equal("", File.read("#{expected_file.path}.diff")) - end - - def test_test_http_diff - command = 'select Shops --sortby _id --limit 5 --output_columns "name"' - command_file = tempfile("command") do |file| - file.puts(command) - end - expected = - '[[0,1290511592.67556,0.00068249],' + - '[[[36],' + - '[["name","ShortText"]],' + - '["たい焼 カタオカ"],' + - '["根津のたいやき"],' + - '["そばたいやき空"],' + - '["車"],' + - '["広瀬屋"]]]]' - actual = - '[[0,1290511592.67556,0.00068249],' + - '[[[36],' + - '[["name","ShortText"]],' + - '["根津のたいやき"],' + - '["たい焼 カタオカ"],' + - '["そばたいやき空"],' + - '["車"],' + - '["広瀬屋"]]]]' - expected_file = tempfile("expected") do |file| - file.puts(expected) - end - script_file = tempfile("script") do |file| - file.puts("test_http #{command_file.path} #{expected_file.path}") - end - output, error, status = invoke_groonga_benchmark("--groonga", groonga, - "--protocol", "http", - "--port", "20041", - "--log-output-dir", @tmp_dir, - script_file.path, - @database_path) - assert_predicate(status, :success?, [output, error]) - assert_equal("DIFF:command:#{command}\n" + - "DIFF:result:#{normalize_result(actual)}\n" + - "DIFF:expect:#{normalize_result(expected)}\n", - normalize_result(File.read("#{expected_file.path}.diff"))) - end - - private - def normalize_result(result) - result.gsub(/\[\[0,[\d.]+,[\d.]+\],/, '[[0,0.0,0.0],') - end -end Deleted: test/unit/groonga-benchmark/test-option.rb (+0 -47) 100644 =================================================================== --- test/unit/groonga-benchmark/test-option.rb 2014-08-06 23:05:09 +0900 (8c1b68c) +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2011 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class GroongaBenchmarkOptionTest < Test::Unit::TestCase - include GroongaBenchmarkTestUtils - - def setup - setup_database - end - - def teardown - teardown_database - end - - def test_log_path - command = 'status' - command_file = tempfile("command") do |file| - file.puts(command) - end - script_file = tempfile("script") do |file| - file.puts("do_gqtp #{command_file.path}") - end - log = tempfile("log") - output, error, status = invoke_groonga_benchmark("--groonga", groonga, - "--protocol", "gqtp", - "--log-path", log.path, - script_file.path, - @database_path) - assert_predicate(status, :success?, [output, error]) - result = JSON.parse(log.read) - assert_equal(1, result.last["queries"]) - end -end Deleted: test/unit/http/.gitignore (+0 -5) 100644 =================================================================== --- test/unit/http/.gitignore 2014-08-06 23:05:09 +0900 (1a5ef8d) +++ /dev/null @@ -1,5 +0,0 @@ -Makefile -Makefile.in -test-http.la -test-http.lo -test-http.o Deleted: test/unit/http/Makefile.am (+0 -3) 100644 =================================================================== --- test/unit/http/Makefile.am 2014-08-06 23:05:09 +0900 (b0e18cb) +++ /dev/null @@ -1,3 +0,0 @@ -EXTRA_DIST = \ - test-static-html.rb \ - test-invalid-http.rb Deleted: test/unit/http/test-invalid-http.rb (+0 -118) 100644 =================================================================== --- test/unit/http/test-invalid-http.rb 2014-08-06 23:05:09 +0900 (d851967) +++ /dev/null @@ -1,118 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2009-2014 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class InvalidHTTPTest < Test::Unit::TestCase - include GroongaHTTPTestUtils - - def setup - setup_server - end - - def teardown - teardown_server - end - - def test_root - response = get("/") - assert_equal("200", response.code) - path = File.join(document_root, 'index.html') - assert_equal(utf8(File.read(path)), utf8(response.body)) - end - - def test_outside_html_outside_existent_inner_nonexistent - relative_path = "../../Makefile.am" - assert_true(File.exist?(File.join(document_root, relative_path))) - assert_false(File.exist?(File.join(document_root, - File.basename(relative_path)))) - - response = get("/#{relative_path}") - assert_equal("404", response.code) - end - - def test_outside_html_with_invalid_utf8 - relative_path = "../../Makefile.am" - assert_true(File.exist?(File.join(document_root, relative_path))) - assert_false(File.exist?(File.join(document_root, - File.basename(relative_path)))) - invalid_relative_path = relative_path.gsub(/\//, "\xC0\x2F") - - response = get("/#{invalid_relative_path}") - assert_equal("404", response.code) - end - - def test_symbolic_link - relative_path = "../../Makefile.am" - relative_symbolic_link_path = "link" - path = File.join(document_root, relative_symbolic_link_path) - symbolic_link_path = File.join(document_root, relative_symbolic_link_path) - assert_false(File.exist?(symbolic_link_path)) - - begin - FileUtils.ln_s(relative_path, symbolic_link_path) - assert_true(File.exist?(symbolic_link_path)) - assert_true(File.exist?(path)) - assert_equal(File.read(path), File.read(symbolic_link_path)) - - response = get("/#{relative_symbolic_link_path}") - assert_equal("404", response.code) - ensure - FileUtils.rm_f(symbolic_link_path) - end - end - - def test_not_start_with_slash - response = get(".") - assert_equal("400", response.code) - end - - def test_long_path - response = get("/0123456789" * 10000) - assert_equal("400", response.code) - assert_response([[Result::INVALID_ARGUMENT, - 0.0, - 0.0, - "too long path name: <PATH...> LENGTH(MAX_LENGTH)", - nil]], - response, :content_type => "application/json") do |_response| - message = _response[0][3] - message.gsub!(/<(.+?)\.\.\.>/, '<PATH...>') - message.gsub!(/(\d+)\((\d+)\)/, 'LENGTH(MAX_LENGTH)') - _response - end - end - - def test_long_query - options = {} - 100.times do |i| - options["key#{i}"] = "value#{i}" - end - response = get(command_path("status", options)) - assert_equal("200", response.code) - # TODO: check body - end - - def test_short_method - omit('now groonga server cannot handle short method.') - socket = TCPSocket.new(@address, @port) - socket.print("G") - socket.flush - Timeout.timeout(1) do - response = get(command_path("table_list")) - assert_equal("200", response.code) - end - end -end Deleted: test/unit/http/test-static-html.rb (+0 -63) 100644 =================================================================== --- test/unit/http/test-static-html.rb 2014-08-06 23:05:09 +0900 (7033c32) +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2009-2011 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class StaticHTMLTest < Test::Unit::TestCase - include GroongaHTTPTestUtils - - def setup - setup_server - end - - def teardown - teardown_server - end - - def test_normal - response = get("/index.html") - assert_response(File.read(File.join(document_root, "index.html")), - response, - :content_type => "text/html") - end - - def test_with_fragment - response = get("/index.html#anchor") - assert_response(File.read(File.join(document_root, "index.html")), - response, - :content_type => "text/html") - end - - def test_with_query - response = get("/index.html?key=value") - assert_response(File.read(File.join(document_root, "index.html")), - response, - :content_type => "text/html") - end - - def test_with_query_and_fragment - response = get("/index.html?key=value#anchor") - assert_response(File.read(File.join(document_root, "index.html")), - response, - :content_type => "text/html") - end - - def test_outside - response = get("/../index.html") - assert_response(File.read(File.join(document_root, "index.html")), - response, - :content_type => "text/html") - end -end Modified: test/unit/lib/Makefile.am (+0 -3) =================================================================== --- test/unit/lib/Makefile.am 2014-08-06 23:05:09 +0900 (96f6c70) +++ test/unit/lib/Makefile.am 2014-08-07 10:43:18 +0900 (607cc2e) @@ -1,6 +1,3 @@ -SUBDIRS = \ - ruby - if WITH_CUTTER noinst_LTLIBRARIES = \ libgrn-test-utils.la \ Deleted: test/unit/lib/ruby/Makefile.am (+0 -6) 100644 =================================================================== --- test/unit/lib/ruby/Makefile.am 2014-08-06 23:05:09 +0900 (147ec34) +++ /dev/null @@ -1,6 +0,0 @@ -EXTRA_DIST = \ - groonga-test-utils.rb \ - groonga-constants.rb \ - groonga-http-test-utils.rb \ - groonga-local-gqtp-test-utils.rb \ - groonga-benchmark-test-utils.rb Deleted: test/unit/lib/ruby/groonga-benchmark-test-utils.rb (+0 -73) 100644 =================================================================== --- test/unit/lib/ruby/groonga-benchmark-test-utils.rb 2014-08-06 23:05:09 +0900 (2669c02) +++ /dev/null @@ -1,73 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010-2012 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -require "tempfile" -require 'groonga-test-utils' - -module GroongaBenchmarkTestUtils - 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_groonga_benchmark_path - groonga_benchmark = ENV["GROONGA_BENCHMARK"] - groonga_benchmark ||= File.join(guess_top_source_dir, - "src", "groonga-benchmark") - File.expand_path(groonga_benchmark) - end - - def groonga_benchmark - @groonga_benchmark ||= guess_groonga_benchmark_path - end - - def invoke_groonga_benchmark(*args) - args.unshift(groonga_benchmark) - 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 Deleted: test/unit/lib/ruby/groonga-constants.rb (+0 -149) 100644 =================================================================== --- test/unit/lib/ruby/groonga-constants.rb 2014-08-06 23:05:09 +0900 (0537839) +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2009 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -module GroongaConstants - module Result - SUCCESS = 0 - END_OF_DATA = 1 - UNKNOWN_ERROR = -1 - OPERATION_NOT_PERMITTED = -2 - NO_SUCH_FILE_OR_DIRECTORY = -3 - NO_SUCH_PROCESS = -4 - INTERRUPTED_FUNCTION_CALL = -5 - INPUT_OUTPUT_ERROR = -6 - NO_SUCH_DEVICE_OR_ADDRESS = -7 - ARG_LIST_TOO_LONG = -8 - EXEC_FORMAT_ERROR = -9 - BAD_FILE_DESCRIPTOR = -10 - NO_CHILD_PROCESSES = -11 - RESOURCE_TEMPORARILY_UNAVAILABLE = -12 - NOT_ENOUGH_SPACE = -13 - PERMISSION_DENIED = -14 - BAD_ADDRESS = -15 - RESOURCE_BUSY = -16 - FILE_EXISTS = -17 - IMPROPER_LINK = -18 - NO_SUCH_DEVICE = -19 - NOT_A_DIRECTORY = -20 - IS_A_DIRECTORY = -21 - INVALID_ARGUMENT = -22 - TOO_MANY_OPEN_FILES_IN_SYSTEM = -23 - TOO_MANY_OPEN_FILES = -24 - INAPPROPRIATE_I_O_CONTROL_OPERATION = -25 - FILE_TOO_LARGE = -26 - NO_SPACE_LEFT_ON_DEVICE = -27 - INVALID_SEEK = -28 - READ_ONLY_FILE_SYSTEM = -29 - TOO_MANY_LINKS = -30 - BROKEN_PIPE = -31 - DOMAIN_ERROR = -32 - RESULT_TOO_LARGE = -33 - RESOURCE_DEADLOCK_AVOIDED = -34 - NO_MEMORY_AVAILABLE = -35 - FILENAME_TOO_LONG = -36 - NO_LOCKS_AVAILABLE = -37 - FUNCTION_NOT_IMPLEMENTED = -38 - DIRECTORY_NOT_EMPTY = -39 - ILLEGAL_BYTE_SEQUENCE = -40 - SOCKET_NOT_INITIALIZED = -41 - OPERATION_WOULD_BLOCK = -42 - ADDRESS_IS_NOT_AVAILABLE = -43 - NETWORK_IS_DOWN = -44 - NO_BUFFER = -45 - SOCKET_IS_ALREADY_CONNECTED = -46 - SOCKET_IS_NOT_CONNECTED = -47 - SOCKET_IS_ALREADY_SHUTDOWNED = -48 - OPERATION_TIMEOUT = -49 - CONNECTION_REFUSED = -50 - RANGE_ERROR = -51 - TOKENIZER_ERROR = -52 - FILE_CORRUPT = -53 - INVALID_FORMAT = -54 - OBJECT_CORRUPT = -55 - TOO_MANY_SYMBOLIC_LINKS = -56 - NOT_SOCKET = -57 - OPERATION_NOT_SUPPORTED = -58 - ADDRESS_IS_IN_USE = -59 - ZLIB_ERROR = -60 - LZO_ERROR = -61 - STACK_OVER_FLOW = -62 - SYNTAX_ERROR = -63 - RETRY_MAX = -64 - INCOMPATIBLE_FILE_FORMAT = -65 - UPDATE_NOT_ALLOWED = -66 - TOO_SMALL_OFFSET = -67 - TOO_LARGE_OFFSET = -68 - TOO_SMALL_LIMIT = -69 - CAS_ERROR = -70 - UNSUPPORTED_COMMAND_VERSION = -71 - end - - module Table - HASH_KEY = 0x0 - PAT_KEY = 0x1 - NO_KEY = 0x3 - VIEW = 0x04 - end - - module Key - SIS = 0x01 << 6 - NORMALIZE = 0x01 << 7 - - UINT = 0x00 << 3 - INT = 0x01 << 3 - FLOAT = 0x02 << 3 - - VAR_SIZE = 0x01 << 14 - end - - module Column - SCALAR = 0x0 - VECTOR = 0x1 - INDEX = 0x2 - end - - module Flag - WITH_SECTION = 0x80 - WITH_WEIGHT = 0x100 - WITH_POSITION = 0x200 - - TEMPORARY = 0x00 << 15 - PERSISTENT = 0x01 << 15 - end - - module Type - VOID = 0 - DB = 1 - OBJECT = 2 - BOOL = 3 - INT8 = 4 - UINT8 = 5 - INT16 = 6 - UINT16 = 7 - INT32 = 8 - UINT32 = 9 - INT64 = 10 - UINT64 = 11 - FLOAT = 12 - TIME = 13 - SHORT_TEXT = 14 - TEXT = 15 - LONG_TEXT = 16 - TOKYO_GEO_POINT = 17 - WGS84_GEO_POINT = 18 - end -end Deleted: test/unit/lib/ruby/groonga-http-test-utils.rb (+0 -369) 100644 =================================================================== --- test/unit/lib/ruby/groonga-http-test-utils.rb 2014-08-06 23:05:09 +0900 (af3325b) +++ /dev/null @@ -1,369 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2009-2010 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -require 'groonga-test-utils' -require 'net/http' -require 'cgi' -require 'json' -require 'msgpack' - -module GroongaHTTPTestUtils - include GroongaTestUtils - - module Format - module JSON - private - def output_type - nil - end - - def content_type - "application/json" - end - - def parse(response) - ::JSON.parse(response) - end - end - - module MessagePack - private - def output_type - "msgpack" - end - - def content_type - "application/x-msgpack" - end - - def parse(response) - ::MessagePack.unpack(response) - end - end - end - - def setup_server - super("http") - end - - def teardown_server - if @groonga_pid - begin - timeout(5) do - shutdown_server - begin - Process.waitpid(@groonga_pid) - @groonga_pid = nil - rescue Errno::ECHILD - end - end - rescue Timeout::Error - end - end - super - end - - private - def shutdown_server - get(command_path("shutdown")) - rescue SystemCallError - end - - def get(path) - Net::HTTP.start(@bind_address, @port) do |http| - http.get(path) - end - end - - def encode_options(options) - return "" if options.empty? - - options.collect do |key, value| - if value.nil? - nil - else - "#{key}=#{CGI.escape(value.to_s)}" - end - end.compact.join("&") - end - - def command_path(command, options={}) - path = "/d/#{command}" - options = options.dup - output_type = options.delete(:output_type) - path += ".#{output_type}" if output_type - encoded_options = encode_options(options) - path += "?#{encoded_options}" unless encoded_options.empty? - path - end - - def populate_users - create_users_table - load_users - end - - def populate_tags - create_users_table - load_tags - end - - def table_create(name, options={}) - response = get(command_path(:table_create, - options.merge({:name => name}))) - assert_success_response(response, :content_type => "application/json") - object_registered - end - - def column_create(table, name, flags, type, options={}) - response = get(command_path(:column_create, - options.merge(:table => table, - :name => name, - :flags => flags, - :type => type))) - assert_success_response(response, :content_type => "application/json") - object_registered - end - - def view_add(view, table) - response = get(command_path(:view_add, - :view => view, - :table => table)) - assert_success_response(response, :content_type => "application/json") - end - - def create_users_table - table_create("users", - :flags => Table::PAT_KEY, - :key_type => "ShortText") - column_create("users", "real_name", Column::SCALAR, "ShortText") - column_create("users", "description", Column::SCALAR, "ShortText") - column_create("users", "hp", Column::SCALAR, "Int32") - column_create("users", "prefecture", Column::SCALAR, "ShortText") - column_create("users", "city", Column::SCALAR, "ShortText") - - table_create("terms", - :flags => Table::PAT_KEY, - :key_type => "ShortText", - :default_tokenizer => "TokenBigram") - column_create("terms", "users_real_name", - Column::INDEX | Flag::WITH_POSITION, - "users", - :source => "real_name") - column_create("terms", "users_description", - Column::INDEX | Flag::WITH_POSITION, - "users", - :source => "description") - column_create("terms", "users_prefecture_city", - Column::INDEX | Flag::WITH_POSITION | Flag::WITH_SECTION, - "users", - :source => "prefecture,city") - - table_create("tags", - :flags => Table::HASH_KEY, - :key_type => "ShortText") - end - - def load(table, values) - n_values = values.size - n_values -= 1 if values.first.is_a?(Array) - response = get(command_path(:load, - :table => table, - :values => json(values))) - assert_response([success_status_response, n_values], response, - :content_type => "application/json") - end - - def load_users - load("users", - [{:_key => "ryoqun", :real_name => "Ryo Onodera", :description => "ryoくんです。", :hp => 200, :prefecture => "不明", :city => "不明"}, - {:_key => "hayamiz", :real_name => "Yuto Hayamizu", :description => "λかわいいよλ", :hp => 200, :prefecture => "富山県", :city => "富山市"}]) - end - - def load_many_users - load("users", - [{:_key => "moritan", :real_name => "モリタン", :description => "モリタンはモリタポ星からやってきました。", :hp => 100, :prefecture => "モリタポ県", :city => "モリタポ市"}, - {:_key => "taporobo", :real_name => "タポロボ", :description => "モリモリモリタポをあつめるタポロボです。", :hp => 100, :prefecture => "モリタポ県", :city => "タポロボ市"}, - {:_key => "ryoqun", :real_name => "Ryo Onodera", :description => "ryoくんです。", :hp => 200, :prefecture => "不明", :city => "不明"}, - {:_key => "hayamiz", :real_name => "Yuto Hayamizu", :description => "λかわいいよλ", :hp => 200, :prefecture => "富山県", :city => "富山市"}, - {:_key => "gunyara-kun", :real_name => "Tasuku SUENAGA", :description => "エロいおっさん", :hp => 150, :prefecture => "長崎県", :city => "長崎市"}]) - end - - def load_tags - load("tags", - [{:_key => "programmer"}, - {:_key => "CEO"}, - {:_key => "male"}]) - end - - def create_calendar_table - table_create("calendar", :flags => Table::NO_KEY) - column_create("calendar", "month", Column::SCALAR, "Int32") - column_create("calendar", "day", Column::SCALAR, "Int32") - end - - def load_schedules - header = ["day", "month"] - - records = [] - 1.upto(12) do |month| - days = (1..28).to_a.shuffle - 1.upto(10) do - records.push([days.pop, month]) - end - end - records.shuffle! - - load("calendar", [header, *records]) - - id = 0 - records.collect do |record| - id += 1 - [id , *record] - end - end - - def json(object) - ::JSON.generate(object) - end - - def success_status_response - [Result::SUCCESS, 0.0, 0.0] - end - - def hexdump_hex_part(binary, bytes_per_line) - sublines_per_line = 2 - sublines_delimiter = ' ' - - bytes_per_subline = bytes_per_line / sublines_per_line - hex_part_length = 2 * bytes_per_line + - (bytes_per_line - sublines_per_line) + - sublines_delimiter.length * (sublines_per_line - 1) - - hex_sublines = [] - binary.each_slice(bytes_per_subline) do |binary_subline| - hex_sublines << binary_subline.collect {|byte| '%02x' % byte}.join(' ') - end - hex_sublines.join(sublines_delimiter).ljust(hex_part_length) - end - - def hexdump_ascii_part(binary) - binary.collect do |byte| - (0x20..0x7e).include?(byte) ? byte.chr : '.' - end.join - end - - def hexdump(str) - results = '' - bytes_per_line = 16 - binary_lines = str.bytes.each_slice(bytes_per_line) - binary_lines.each do |binary_line| - results << hexdump_hex_part(binary_line, bytes_per_line) - results << " " - results << hexdump_ascii_part(binary_line) - results << "\n" - end - results - end - - def assert_response(expected, response, options=nil) - actual = nil - options ||= {} - - if options[:content_type] - assert_equal(options[:content_type], response.content_type) - end - - case response.content_type - when "application/json" - begin - actual = ::JSON.parse(response.body) - rescue ::JSON::ParserError => e - raise "JSON ParserError #{e.message}\nJSON is ...\n" \ - "---\n#{response.body}\n---" - end - normalize_structured_response(actual) - when "application/x-msgpack" - begin - actual = ::MessagePack.unpack(response.body) - rescue ::MessagePack::UnpackError => e - raise "MessagePack UnpackError #{e.message}\nMessagePack is ...\n" \ - "---\n#{hexdump(response.body)}---" - end - normalize_structured_response(actual) - when "text/html" - actual = utf8(response.body) - when "text/xml" - actual = utf8(response.body) - else - flunk("unknown content-type: #{response.content_type}") - end - - actual = yield(actual) if block_given? - assert_equal(expected, actual) - end - - def assert_success_response(response, options=nil) - assert_response([success_status_response, true], response, options) - end - - def assert_response_body(body, response, options=nil, &block) - assert_response([success_status_response, body], response, options, &block) - end - - def assert_error_response(code, message, response, options=nil) - assert_response([[code, 0.0, 0.0, message, nil]], response, options) - end - - def assert_select(header, expected, parameters, options={}, &block) - command_name = options[:command] || :select - response = get(command_path(command_name, parameters)) - drilldown_results = options[:drilldown_results] || [] - expected_content_type = options[:content_type] || "application/json" - - assert_response([success_status_response, - [[[options[:n_hits] || expected.size], - header, - *expected - ], - *drilldown_results]], - response, - :content_type => expected_content_type, - &block) - end - - def assert_select_xml(expected, parameters, options={}, &block) - command_name = options[:command] || :select - response = get(command_path(command_name, - parameters.merge(:output_type => "xml"))) - - assert_response(expected, - response, - :content_type => "text/xml") do |xml| - xml = xml.gsub(/UP="\d+\.\d+" ELAPSED="\d+\.\d+"/, - "UP=\"0.0\" ELAPSED=\"0.0\"") - xml = block.call(xml) if block - xml - end - end - - def normalize_structured_response(response) - if response[0][0].is_a?(Integer) - response[0][1..2] = [0.0, 0.0] - response[0][4] = nil if response[0][4] - end - end -end Deleted: test/unit/lib/ruby/groonga-local-gqtp-test-utils.rb (+0 -75) 100644 =================================================================== --- test/unit/lib/ruby/groonga-local-gqtp-test-utils.rb 2014-08-06 23:05:09 +0900 (f319330) +++ /dev/null @@ -1,75 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -require 'groonga-test-utils' - -module GroongaLocalGQTPTestUtils - include GroongaTestUtils - - def setup_local_database - setup_database_path - create_empty_database - end - - def teardown_local_database - teardown_database_path - end - - private - def create_empty_database - run_groonga("-n", @database_path, "shutdown") - end - - def dump - output = run_groonga(@database_path, "dump") - unless $?.success? - flunk("groonga exited with unexpected exit status while dumping: " + - "#{$?.exitstatus}") - end - output - end - - def feed_commands(commands) - output = "" - IO.popen(construct_command_line(@database_path), "w+") do |pipe| - pipe.write(commands) - pipe.write("shutdown\n") - output = pipe.read - end - unless $?.success? - flunk("groonga exited with unexpected exit status while executing " + - "commands: #{$?.exitstatus.inspect}:\n" + - "commands:\n>>>\n#{commands}\n<<<\n" + - "output:\n>>>\n#{output}\n<<<\n") - end - normalize_json_result(output) - end - - def assert_dump(expected, commands) - feed_commands(commands) - assert_equal(expected, dump) - end - - def assert_same_dump(commands) - assert_dump(commands, commands) - end - - def assert_commands(expected, commands) - actual = feed_commands(commands) - assert_equal(expected, actual) - end -end Deleted: test/unit/lib/ruby/groonga-test-utils.rb (+0 -264) 100644 =================================================================== --- test/unit/lib/ruby/groonga-test-utils.rb 2014-08-06 23:05:09 +0900 (e8ede69) +++ /dev/null @@ -1,264 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2009 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -require 'fileutils' -require 'shellwords' -require 'tmpdir' -require 'groonga-constants' - -module GroongaTestUtils - include GroongaConstants - - def setup_database_path - base_dir = ENV["BUILD_DIR"] || ENV["BASE_DIR"] - base_dir ||= File.join(File.dirname(__FILE__), "..", "..") - @tmp_base_dir = File.join(File.expand_path(base_dir), "tmp", "ruby") - FileUtils.rm_rf(@tmp_base_dir, :secure => true) - FileUtils.mkdir_p(@tmp_base_dir) - @tmp_dir = Dir.mktmpdir("tmp", @tmp_base_dir) - @database_path = File.join(@tmp_dir, "database") - end - - def teardown_database_path - @tmp_base_dir ||= nil - FileUtils.rm_rf(@tmp_base_dir, :secure => true) if @tmp_base_dir - end - - def setup_server(protocol=nil) - setup_database_path - @protocol = protocol - @bind_address = "127.0.0.1" - @port = 5454 - @encoding = "utf8" - @user_object_start_id = 256 - start_server - end - - def teardown_server - @groonga_pid ||= nil - stop_server_process(@groonga_pid) - @groonga_pid = nil - - teardown_database_path - end - - private - def guess_groonga_path - groonga = ENV["GROONGA"] - groonga ||= File.join(guess_top_source_dir, "src", "groonga") - File.expand_path(groonga) - end - - def groonga - @groonga ||= guess_groonga_path - end - - def guess_document_root - File.join(guess_top_source_dir, "data", "html", "admin") - end - - def document_root - @document_root ||= guess_document_root - end - - def guess_top_source_dir - base_dir = ENV["BASE_DIR"] - if base_dir - top_source_dir = File.join(base_dir, "..", "..") - else - top_source_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "..") - end - File.expand_path(top_source_dir) - end - - def start_server_process(address, port, *command_line) - pid = fork do - exec(*command_line) - end - - begin - timeout(1) do - loop do - sleep 0.1 - begin - TCPSocket.new(address, port) - break - rescue SystemCallError - end - end - end - rescue - stop_server_process(pid) - raise - end - - pid - end - - def start_server - command_line = [ - groonga, - "-s", - "--bind-address", @bind_address, - "-p", @port.to_s, - "-e", @encoding, - "--document-root", document_root, - ] - command_line.concat(["--protocol", @protocol]) if @protocol - command_line.concat(["-n", @database_path]) - @groonga_pid = start_server_process(@bind_address, @port, *command_line) - end - - def stop_server_process(pid) - return if pid.nil? - Process.kill(:TERM, pid) - begin - Process.waitpid(pid) - rescue Errno::ECHILD - end - end - - def object_registered - current_id = @user_object_start_id - @user_object_start_id += 1 - current_id - end - - def timeout(seconds, &block) - Timeout.timeout(seconds, &block) - rescue Timeout::Error - raise RuntimeError, "timeout #{seconds}s", [caller[0]] + $@ - end - - def construct_command_line(*arguments) - command_line = [guess_groonga_path, *arguments].collect do |component| - Shellwords.escape(component) - end.join(" ") - end - - def run_groonga(*arguments) - normalize_json_result(`#{construct_command_line(*arguments)}`) - end - - def normalize_json_result(result) - result.gsub(/^\[\[0,[\d\.e\-]+,[\d\.e\-]+\]/, "[[0,0.0,0.0]") - end - - def utf8(string) - string.force_encoding("UTF-8") if string.respond_to?(:force_encoding) - string - end - - LANG_ENVS = %w"LANG LC_ALL LC_CTYPE" - - def invoke_command(*args) - options = args.last.is_a?(Hash) ? args.pop : {} - input_data = options[:input] || "" - capture_output = options[:capture_output] - capture_output = true if capture_output.nil? - capture_error = options[:capture_error] - args = [args] unless args.kind_of?(Array) - begin - in_child, in_parent = IO.pipe - out_parent, out_child = IO.pipe if capture_output - err_parent, err_child = IO.pipe if capture_error - pid = fork do - c = "C" - LANG_ENVS.each {|lc| ENV[lc] = c} - case args.first - when Hash - ENV.update(args.shift) - end - STDIN.reopen(in_child) - in_parent.close - if capture_output - STDOUT.reopen(out_child) - out_parent.close - end - if capture_error - STDERR.reopen(err_child) - err_parent.close - end - Process.setrlimit(Process::RLIMIT_CORE, 0) rescue nil - exec(*args) - end - in_child.close - out_child.close if capture_output - err_child.close if capture_error - th_stdout = Thread.new { out_parent.read } if capture_output - th_stderr = Thread.new { err_parent.read } if capture_error - in_parent.write(input_data.to_str) - in_parent.close - if (!capture_output || th_stdout.join(60)) && - (!capture_error || th_stderr.join(60)) - stdout = th_stdout.value if capture_output - stderr = th_stderr.value if capture_error - else - raise Timeout::Error - end - Process.wait pid - status = $? - ensure - [in_child, in_parent, out_child, out_parent, err_child, err_parent].each do |io| - io.close if io && !io.closed? - end - [th_stdout, th_stderr].each do |th| - (th.kill; th.join) if th - end - end - return stdout, stderr, status - end - - def invoke_groonga(*args) - environment = args.first.is_a?(Hash) ? args.shift : {} - args.unshift(groonga) - args.unshift(environment) - invoke_command(*args) - end - - def assert_run_groonga(test_stdout, test_stderr, args, *rest) - argnum = rest.size + 3 - options = (Hash === rest.last ? rest.pop : {}) - message = (rest.pop if String === rest.last) - if String === rest.last - input = rest.pop - else - input = options.delete(:input) || "" - end - unless rest.empty? - raise ArgumentError, "wrong number of arguments (#{argnum} for 3)" - end - args = [args] unless args.is_a?(Array) - args << options.merge(:input => input, - :capture_output => true, - :capture_error => true) - stdout, stderr, status = invoke_groonga(*args) - assert_not_predicate(status, :signaled?) - stdout, stderr = yield(stdout, stderr) if block_given? - if test_stderr.is_a?(Regexp) - assert_match(test_stderr, stderr, message) - else - assert_equal(test_stderr, stderr, message) - end - if test_stdout.is_a?(Regexp) - assert_match(test_stdout, stdout, message) - else - assert_equal(test_stdout, stdout, message) - end - status - end -end Deleted: test/unit/run-test.rb (+0 -28) 100755 =================================================================== --- test/unit/run-test.rb 2014-08-06 23:05:09 +0900 (3366e01) +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env ruby - -$KCODE = 'utf-8' unless defined?(Encoding) - -require 'rbconfig' -require 'fileutils' -require "rubygems" -require "bundler/setup" -require "test/unit" -require "test/unit/notify" -require "json" -require "msgpack" - -build_dir = File.expand_path(ENV["BUILD_DIR"] || File.dirname(__FILE__)) -base_dir = File.expand_path(ENV["BASE_DIR"] || File.dirname(__FILE__)) - -test_lib_dir = File.expand_path(File.join(build_dir, "..", "lib")) -FileUtils.mkdir_p(test_lib_dir) - -$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-benchmark-test-utils' - -ARGV.unshift("--exclude", "run-test.rb") -exit Test::Unit::AutoRunner.run(true, File.dirname($0)) Modified: test/unit/run-test.sh (+1 -41) =================================================================== --- test/unit/run-test.sh 2014-08-06 23:05:09 +0900 (b1afdef) +++ test/unit/run-test.sh 2014-08-07 10:43:18 +0900 (867684b) @@ -41,12 +41,6 @@ elif test x"$CUTTER_CHECK_LEAK" = x"yes"; then CUTTER_ARGS="--keep-opening-modules" fi -RUBY_TEST_ARGS= -if test x"$PRIORITY_MODE" = x"yes"; then - RUBY_TEST_ARGS="$RUBY_TEST_ARGS --priority-mode" - # CUTTER_ARGS="$CUTTER_ARGS --priority-mode" -fi - CUTTER_ARGS="$CUTTER_ARGS -s $BASE_DIR" if test x"$CUTTER_VERBOSE" = x"yes"; then CUTTER_ARGS="$CUTTER_ARGS -v v" @@ -79,38 +73,4 @@ for tmpfs in $tmpfs_candidates; do fi done -no_test=1 - -cutter_result=0 -if test "$NO_CUTTER" != "yes" -a -n "$CUTTER"; then - $CUTTER_WRAPPER $CUTTER $CUTTER_ARGS "$@" $BUILD_DIR - cutter_result=$? - no_test=0 -fi - -ruby_result=0 -if test "$NO_RUBY" != "yes" -a -n "$RUBY"; then - : ${TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE:=30000} - export TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE - BUNDLE_GEMFILE="$BUILD_DIR/Gemfile" - export BUNDLE_GEMFILE - if [ ! -e "$BUNDLE_GEMFILE" ]; then - ln -s "$BASE_DIR/Gemfile" "$BUNDLE_GEMFILE" - fi - if ! type bundle > /dev/null; then - $RUBY -S gem install bundler - fi - if [ ! -e "$BUNDLE_GEMFILE.lock" -o \ - "$BUNDLE_GEMFILE" -nt "$BUNDLE_GEMFILE.lock" ]; then - $RUBY -S bundle install - fi - $RUBY $BASE_DIR/run-test.rb $RUBY_TEST_ARGS "$@" - ruby_result=$? - no_test=0 -fi - -if [ $no_test = 0 -a $cutter_result = 0 -a $ruby_result = 0 ]; then - exit 0 -else - exit 1 -fi +$CUTTER_WRAPPER $CUTTER $CUTTER_ARGS "$@" $BUILD_DIR Deleted: test/unit/suggest/test-httpd.rb (+0 -100) 100644 =================================================================== --- test/unit/suggest/test-httpd.rb 2014-08-06 23:05:09 +0900 (d5bab77) +++ /dev/null @@ -1,100 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2011 Kouhei Sutou <kou �� clear-code.com> -# -# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -class SuggestHTTPDTest < Test::Unit::TestCase - include GroongaHTTPTestUtils - - setup :setup_database_path - setup :setup_dataset - setup :setup_httpd - - teardown :teardown_httpd - teardown :teardown_database_path - - def setup_dataset - @dataset_name = "shops" - system(groonga_suggest_create_dataset, @database_path, @dataset_name) - end - - def setup_httpd - @bind_address = "127.0.0.1" - @port = 8080 - start_httpd - end - - def teardown_httpd - @groonga_suggest_httpd_pid ||= nil - stop_server_process(@groonga_suggest_httpd_pid) - @groonga_suggest_httpd_pid = nil - end - - def test_complete - options = { - "q" => "wo", - "s" => Time.now.to_i * 1000, - "i" => "id", - "t" => "complete", - "n" => @dataset_name, - "l" => @dataset_name, - } - encoded_options = encode_options(options) - response = get("/?#{encoded_options}") - assert_equal("application/json", response.content_type) - assert_equal({"complete" => [[0], - [["_key", "ShortText"], - ["_score", "Int32"]]]}, - JSON.parse(response.body)) - end - - private - def groonga_suggest_httpd - @groonga_suggest_httpd ||= guess_groonga_suggest_httpd_path - end - - def groonga_suggest_create_dataset - @groonga_suggest_create_dataset ||= guess_groonga_suggest_create_dataset_path - end - - def guess_top_suggest_source_dir - File.join(guess_top_source_dir, "src", "suggest") - end - - def guess_groonga_suggest_httpd_path - httpd = ENV["GROONGA_SUGGEST_HTTPD"] - httpd ||= File.join(guess_top_suggest_source_dir, "groonga-suggest-httpd") - File.expand_path(httpd) - end - - def guess_groonga_suggest_create_dataset_path - create_dataset = ENV["GROONGA_SUGGEST_CREATE_DATASET"] - create_dataset ||= File.join(guess_top_suggest_source_dir, - "groonga-suggest-create-dataset") - File.expand_path(create_dataset) - end - - def start_httpd - command_line = [ - groonga_suggest_httpd, - "--bind-address", @bind_address, - "--port", @port.to_s, - "--disable-max-fd-check", - @database_path, - ] - @groonga_suggest_httpd_pid = start_server_process(@bind_address, @port, - *command_line) - end -end Modified: tools/travis-script.sh (+1 -1) =================================================================== --- tools/travis-script.sh 2014-08-06 23:05:09 +0900 (0374f99) +++ tools/travis-script.sh 2014-08-07 10:43:18 +0900 (7931903) @@ -4,7 +4,7 @@ set -e case "${BUILD_TOOL}" in autotools) - NO_RUBY=yes test/unit/run-test.sh + test/unit/run-test.sh test/command/run-test.sh # test/command/run-test.sh --interface http # test/command/run-test.sh --interface http --testee groonga-httpd