Kouhei Sutou
null+****@clear*****
Mon Jan 15 13:57:13 JST 2018
Kouhei Sutou 2018-01-15 13:57:13 +0900 (Mon, 15 Jan 2018) New Revision: 564f15ab6f708550d2a1d779c9f1df044f2a841d https://github.com/groonga/groonga-query-log/commit/564f15ab6f708550d2a1d779c9f1df044f2a841d Message: Make test passed again Modified files: lib/groonga-query-log/command-line.rb lib/groonga-query-log/command/analyze-load.rb lib/groonga-query-log/command/analyzer.rb lib/groonga-query-log/command/extract.rb test/command/test-analyzer.rb test/command/test-extract.rb test/command/test-format-regression-test-logs.rb test/helper.rb Modified: lib/groonga-query-log/command-line.rb (+1 -1) =================================================================== --- lib/groonga-query-log/command-line.rb 2018-01-15 12:13:19 +0900 (5a67d21) +++ lib/groonga-query-log/command-line.rb 2018-01-15 13:57:13 +0900 (08f3dce) @@ -1,5 +1,5 @@ -# Copyright (C) 2017-2018 Kouhei Sutou <kou �� clear-code.com> # Copyright (C) 2012 Haruka Yoshihara <yoshihara �� clear-code.com> +# Copyright (C) 2017-2018 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 Modified: lib/groonga-query-log/command/analyze-load.rb (+3 -0) =================================================================== --- lib/groonga-query-log/command/analyze-load.rb 2018-01-15 12:13:19 +0900 (a08c6fd) +++ lib/groonga-query-log/command/analyze-load.rb 2018-01-15 13:57:13 +0900 (a7d813e) @@ -62,6 +62,9 @@ module GroongaQueryLog end end rescue Interrupt + rescue Error + $stderr.puts($!.message) + return false end true Modified: lib/groonga-query-log/command/analyzer.rb (+3 -0) =================================================================== --- lib/groonga-query-log/command/analyzer.rb 2018-01-15 12:13:19 +0900 (0785245) +++ lib/groonga-query-log/command/analyzer.rb 2018-01-15 13:57:13 +0900 (f445cf7) @@ -82,6 +82,9 @@ module GroongaQueryLog parse(log_paths, &process_statistic) rescue Interrupt raise unless stream + rescue Error + $stderr.puts($!.message) + return false end if stream Modified: lib/groonga-query-log/command/extract.rb (+11 -5) =================================================================== --- lib/groonga-query-log/command/extract.rb 2018-01-15 12:13:19 +0900 (b7ec8e7) +++ lib/groonga-query-log/command/extract.rb 2018-01-15 13:57:13 +0900 (36a4b14) @@ -56,12 +56,18 @@ module GroongaQueryLog return false end - if****@optio*****_path - File.open(@options.output_path, "w") do |output| - extract(log_paths, output) + begin + if****@optio*****_path + File.open(@options.output_path, "w") do |output| + extract(log_paths, output) + end + else + extract(log_paths, $stdout) end - else - extract(log_paths, $stdout) + rescue Interrupt + rescue Error + $stderr.puts($!.message) + return false end true Modified: test/command/test-analyzer.rb (+13 -7) =================================================================== --- test/command/test-analyzer.rb 2018-01-15 12:13:19 +0900 (7fa4590) +++ test/command/test-analyzer.rb 2018-01-15 13:57:13 +0900 (6a14414) @@ -1,5 +1,5 @@ -# Copyright (C) 2014-2017 Kouhei Sutou <kou �� clear-code.com> # Copyright (C) 2012 Haruka Yoshihara <yoshihara �� clear-code.com> +# Copyright (C) 2014-2018 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 @@ -20,6 +20,8 @@ require "pathname" require "groonga-query-log/command/analyzer" class AnalyzerCommandTest < Test::Unit::TestCase + include Helper::Command + setup def setup_fixtures @fixtures_path = File.join(__dir__, "..", "fixtures") @@ -40,9 +42,8 @@ class AnalyzerCommandTest < Test::Unit::TestCase end def test_no_specified - assert_raise(GroongaQueryLog::Command::Analyzer::NoInputError) do - run_analyzer - end + assert_equal("Error: Please specify input log files.\n", + run_analyzer) end end @@ -101,9 +102,14 @@ class AnalyzerCommandTest < Test::Unit::TestCase private def run_analyzer(*arguments) Tempfile.open("output.actual") do |output| - arguments << "--output" << output.path - @analyzer.run(arguments) - File.read(output.path) + open_error_output do |error| + arguments << "--output" << output.path + if****@analy*****(arguments) + File.read(output.path) + else + File.read(error.path) + end + end end end Modified: test/command/test-extract.rb (+7 -16) =================================================================== --- test/command/test-extract.rb 2018-01-15 12:13:19 +0900 (c58c100) +++ test/command/test-extract.rb 2018-01-15 13:57:13 +0900 (1eac824) @@ -1,8 +1,7 @@ #!/usr/bin/env ruby -# -*- coding: utf-8 -*- # # Copyright (C) 2012 Haruka Yoshihara <yoshihara �� clear-code.com> -# Copyright (C) 2015 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2015-2018 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 @@ -22,6 +21,8 @@ require "groonga/command" require "groonga-query-log/command/extract" class ExtractCommandTest < Test::Unit::TestCase + include Helper::Command + setup def setup_fixtures @fixtures_path = File.join(File.dirname(__FILE__), "..", "fixtures") @@ -112,19 +113,6 @@ EOC end end - def open_error_output - Tempfile.open("extract.error") do |error| - error.sync = true - original_stderr = $stderr.dup - $stderr.reopen(error) - begin - yield(error) - ensure - $stderr.reopen(original_stderr) - end - end - end - class TestExtract < self def setup super @@ -163,8 +151,11 @@ EOL private def extract + input = Tempfile.new(["groonga-query", ".log"]) + input.puts(@log) + input.close output = StringIO.new - @extract_command.send(:extract, @log, output) + @extract_command.send(:extract, [input.path], output) output.string end end Modified: test/command/test-format-regression-test-logs.rb (+1 -1) =================================================================== --- test/command/test-format-regression-test-logs.rb 2018-01-15 12:13:19 +0900 (7d2b752) +++ test/command/test-format-regression-test-logs.rb 2018-01-15 13:57:13 +0900 (2f71517) @@ -19,7 +19,7 @@ require "groonga-query-log/command/format-regression-test-logs" class FormatRegressionTestLogsCommandTest < Test::Unit::TestCase - include Path + include Helper::Path def setup @command = GroongaQueryLog::Command::FormatRegressionTestLogs.new Modified: test/helper.rb (+20 -3) =================================================================== --- test/helper.rb 2018-01-15 12:13:19 +0900 (5c95fbf) +++ test/helper.rb 2018-01-15 13:57:13 +0900 (4fca80c) @@ -21,8 +21,25 @@ require "groonga/command" require "groonga-query-log" -module Path - def fixture_path(*components) - File.join(File.dirname(__FILE__), "fixtures", *components) +module Helper + module Path + def fixture_path(*components) + File.join(File.dirname(__FILE__), "fixtures", *components) + end + end + + module Command + def open_error_output + Tempfile.open("groonga-query-log.error") do |error| + error.sync = true + original_stderr = $stderr.dup + $stderr.reopen(error) + begin + yield(error) + ensure + $stderr.reopen(original_stderr) + end + end + end end end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180115/278b0e74/attachment-0001.htm