[Groonga-commit] groonga/groonga-query-log at 85d98f6 [master] Add a script to format regression test logs

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jun 2 17:08:39 JST 2014


Kouhei Sutou	2014-06-02 17:08:39 +0900 (Mon, 02 Jun 2014)

  New Revision: 85d98f65adddf16730b1588bcc499fca414c71f3
  https://github.com/groonga/groonga-query-log/commit/85d98f65adddf16730b1588bcc499fca414c71f3

  Message:
    Add a script to format regression test logs

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

  Added: bin/groonga-query-log-format-regression-test-logs (+22 -0) 100755
===================================================================
--- /dev/null
+++ bin/groonga-query-log-format-regression-test-logs    2014-06-02 17:08:39 +0900 (6be4d22)
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+#
+# Copyright (C) 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 as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# 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/query-log/command/format-regression-test-logs"
+
+command = Groonga::QueryLog::Command::FormatRegressionTestLogs.new
+exit(command.run(ARGV))

  Added: lib/groonga/query-log/command/format-regression-test-logs.rb (+113 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/query-log/command/format-regression-test-logs.rb    2014-06-02 17:08:39 +0900 (d00eb4c)
@@ -0,0 +1,113 @@
+# Copyright (C) 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 as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# 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 "English"
+require "find"
+require "tempfile"
+require "pp"
+require "json"
+
+module Groonga
+  module QueryLog
+    module Command
+      class FormatRegressionTestLogs
+        def initialize
+        end
+
+        def run(command_line)
+          if command_line.empty?
+            format_log($stdin, "-")
+          else
+            command_line.each do |path|
+              if File.directory?(path)
+                Find.find(path) do |sub_path|
+                  next unless File.file?(sub_path)
+                  File.open(sub_path) do |file|
+                    format_log(file, sub_path)
+                  end
+                end
+              else
+                File.open(path) do |file|
+                  format_log(file, path)
+                end
+              end
+            end
+          end
+          true
+        end
+
+        private
+        def format_log(input, path)
+          command = nil
+          response1 = nil
+          response2 = nil
+
+          input.each_line do |line|
+            unless line.valid_encoding?
+              puts("invalid encoding line")
+              puts("#{path}:#{input.lineno}:#{line}")
+              next
+            end
+            case line
+            when /\Acommand: /
+              command = $POSTMATCH.chomp
+            when /\Aresponse1: /
+              response1 = $POSTMATCH.chomp
+            when /\Aresponse2: /
+              response2 = $POSTMATCH.chomp
+              parse_failed = false
+              begin
+                JSON.parse(response1)
+              rescue JSON::ParserError
+                puts(command)
+                puts("failed to parse response1: #{$!.message}")
+                puts(response1)
+                parse_failed = true
+              end
+
+              begin
+                JSON.parse(response2)
+              rescue JSON::ParserError
+                puts(command)
+                puts("failed to parse response2: #{$!.message}")
+                puts(response2)
+                parse_failed = true
+              end
+
+              next if parse_failed
+
+              next if response1 == response2
+
+              base_name = File.basename(path, ".*")
+              Tempfile.open("response1-#{base_name}") do |response1_file|
+                PP.pp(JSON.parse(response1), response1_file)
+                response1_file.flush
+                Tempfile.open("response2-#{base_name}") do |response2_file|
+                  PP.pp(JSON.parse(response2), response2_file)
+                  response2_file.flush
+                  puts(command)
+                  system("diff",
+                         "-u",
+                         response1_file.path, response2_file.path)
+                end
+              end
+            end
+          end
+        end
+      end
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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