[Groonga-commit] droonga/drntest at 4b467f5 [master] Show diff on failure

Back to archive index

Yoji Shidara null+****@clear*****
Wed Sep 18 17:34:22 JST 2013


Yoji Shidara	2013-09-18 17:34:22 +0900 (Wed, 18 Sep 2013)

  New Revision: 4b467f502f8836742f6341703ddd891f2964ef36
  https://github.com/droonga/drntest/commit/4b467f502f8836742f6341703ddd891f2964ef36

  Message:
    Show diff on failure

  Modified files:
    lib/drntest/tester.rb

  Modified: lib/drntest/tester.rb (+26 -4)
===================================================================
--- lib/drntest/tester.rb    2013-09-18 17:05:34 +0900 (17d8f92)
+++ lib/drntest/tester.rb    2013-09-18 17:34:22 +0900 (027828d)
@@ -1,6 +1,8 @@
 require "optparse"
 require "json"
 require "droonga/client"
+require "tempfile"
+require "pp"
 
 module Drntest
   class Tester
@@ -78,10 +80,7 @@ module Drntest
           puts "PASS"
         else
           puts "FAIL"
-          puts "Expected:"
-          p expected
-          puts "Actual:"
-          p actual
+          show_diff(expected, actual)
           reject_path = target_path.sub_ext(".reject")
           puts "Saving received result as #{reject_path}"
           File.write(reject_path, actual_json)
@@ -93,6 +92,29 @@ module Drntest
       end
     end
 
+    def show_diff(expected, actual)
+      expected_pretty = expected.pretty_inspect
+      actual_pretty = actual.pretty_inspect
+
+      create_temporary_file("expected", expected_pretty) do |expected_file|
+        create_temporary_file("actual", actual_pretty) do |actual_file|
+          diff_options = [
+            "-u",
+            "--label", "(expected)", expected_file.path,
+            "--label", "(actual)", actual_file.path
+          ]
+          system("diff", *diff_options)
+        end
+      end
+    end
+
+    def create_temporary_file(key, content)
+      file = Tempfile.new("drntest-#{key}")
+      file.write(content)
+      file.close
+      yield(file)
+    end
+
     def normalize_result(result)
       result = result.dup
       result[1] = 0 # Mask start time
-------------- next part --------------
HTML����������������������������...
Download 



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