[Groonga-commit] groonga/groonga-query-log at ed57d0e [master] run-regression-test: accept output if given

Back to archive index
Kentaro Hayashi null+****@clear*****
Tue Jan 15 18:59:14 JST 2019


Kentaro Hayashi	2019-01-15 18:59:14 +0900 (Tue, 15 Jan 2019)

  Revision: ed57d0e52c721258176e610d352cff356257c7de
  https://github.com/groonga/groonga-query-log/commit/ed57d0e52c721258176e610d352cff356257c7de

  Merged 2ee362c: Merge pull request #39 from kenhys/regression-test-logs-output

  Message:
    run-regression-test: accept output if given

  Modified files:
    lib/groonga-query-log/command/format-regression-test-logs.rb
    test/command/test-format-regression-test-logs.rb

  Modified: lib/groonga-query-log/command/format-regression-test-logs.rb (+29 -22)
===================================================================
--- lib/groonga-query-log/command/format-regression-test-logs.rb    2019-01-10 09:51:09 +0900 (48ea1a5)
+++ lib/groonga-query-log/command/format-regression-test-logs.rb    2019-01-15 18:59:14 +0900 (a214b7f)
@@ -28,7 +28,8 @@ require "groonga-query-log/version"
 module GroongaQueryLog
     module Command
       class FormatRegressionTestLogs
-        def initialize
+        def initialize(options={})
+          @output = options[:output] || $stdout
         end
 
         def run(command_line)
@@ -68,8 +69,8 @@ module GroongaQueryLog
 
           input.each_line do |line|
             unless line.valid_encoding?
-              puts("invalid encoding line")
-              puts("#{path}:#{input.lineno}:#{line}")
+              @output.puts("invalid encoding line")
+              @output.puts("#{path}:#{input.lineno}:#{line}")
               next
             end
             case line
@@ -97,18 +98,18 @@ module GroongaQueryLog
           begin
             JSON.parse(response_old)
           rescue JSON::ParserError
-            puts(command)
-            puts("failed to parse old response: #{$!.message}")
-            puts(response_old)
+            @output.puts(command)
+            @output.puts("failed to parse old response: #{$!.message}")
+            @output.puts(response_old)
             valid = false
           end
 
           begin
             JSON.parse(response_new)
           rescue JSON::ParserError
-            puts(command)
-            puts("failed to parse new response: #{$!.message}")
-            puts(response_new)
+            @output.puts(command)
+            @output.puts("failed to parse new response: #{$!.message}")
+            @output.puts(response_new)
             valid = false
           end
 
@@ -125,33 +126,39 @@ module GroongaQueryLog
               PP.pp(JSON.parse(response_new), response_new_file)
               response_new_file.flush
               report_command(command)
-              system("diff",
-                     "--label=old",
-                     "--label=new",
-                     "-u",
-                     response_old_file.path, response_new_file.path)
+              Tempfile.open("response-diff") do |response_diff_file|
+                system("diff",
+                       "--label=old",
+                       "--label=new",
+                       "-u",
+                       response_old_file.path,
+                       response_new_file.path,
+                       out: response_diff_file)
+                response_diff_file.rewind
+                @output.puts(response_diff_file.read)
+              end
             end
           end
         end
 
         def report_error(command, message, backtrace)
           report_command(command)
-          puts("Error: #{message}")
-          puts("Backtrace:")
-          puts(backtrace)
+          @output.puts("Error: #{message}")
+          @output.puts("Backtrace:")
+          @output.puts(backtrace)
         end
 
         def report_command(command)
-          puts("Command:")
-          puts(command)
+          @output.puts("Command:")
+          @output.puts(command)
           parsed_command = Groonga::Command::Parser.parse(command)
-          puts("Name: #{parsed_command.name}")
-          puts("Arguments:")
+          @output.puts("Name: #{parsed_command.name}")
+          @output.puts("Arguments:")
           sorted_arguments = parsed_command.arguments.sort_by do |key, value|
             key
           end
           sorted_arguments.each do |key, value|
-            puts("  #{key}: #{value}")
+            @output.puts("  #{key}: #{value}")
           end
         end
       end

  Modified: test/command/test-format-regression-test-logs.rb (+24 -0)
===================================================================
--- test/command/test-format-regression-test-logs.rb    2019-01-10 09:51:09 +0900 (4d2f4c0)
+++ test/command/test-format-regression-test-logs.rb    2019-01-15 18:59:14 +0900 (e78110c)
@@ -108,4 +108,28 @@ Backtrace:
     assert_equal([true, output],
                  run_command([fixture_path("error.log")]))
   end
+
+  def test_output_option
+    output = StringIO.new("output-option")
+    options = {:output => output}
+    @command = GroongaQueryLog::Command::FormatRegressionTestLogs.new(options)
+    run_command([fixture_path("command-format.log")])
+    output.rewind
+    expected = <<-OUTPUT
+Command:
+select Logs
+Name: select
+Arguments:
+  table: Logs
+--- old
++++ new
+@@ -1,4 +1,4 @@
+ [[[2],
+   [[\"_id\", \"UInt32\"], [\"message\", \"Text\"]],
+   [1, \"log message1\"],
+-  [2, \"log message2\"]]]
++  [3, \"log message3\"]]]
+    OUTPUT
+    assert_equal(expected, output.read)
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190115/85ceb618/attachment-0001.html>


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