2011-05-03 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
authorcaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 May 2011 20:57:14 +0000 (20:57 +0000)
committercaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 May 2011 20:57:14 +0000 (20:57 +0000)
        Reviewed by Adam Roben.

        Add tests to PrettyPatch
        https://bugs.webkit.org/show_bug.cgi?id=57298

        Verify that 'prettify' parse the right number of files and parts
        (add/remove/shared) by checking a set of patches available in
        bugs.webkit.org.

        * PrettyPatch/PrettyPatch.rb: exported a couple a globals with
        statistics information for our test script.
        * PrettyPatch/PrettyPatch_test.rb: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@85657 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/bugs.webkit.org/ChangeLog
Websites/bugs.webkit.org/PrettyPatch/PrettyPatch.rb
Websites/bugs.webkit.org/PrettyPatch/PrettyPatch_test.rb [new file with mode: 0755]

index 38dec04..4fe5bbf 100644 (file)
@@ -1,3 +1,18 @@
+2011-05-03  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
+        Reviewed by Adam Roben.
+
+        Add tests to PrettyPatch
+        https://bugs.webkit.org/show_bug.cgi?id=57298
+
+        Verify that 'prettify' parse the right number of files and parts
+        (add/remove/shared) by checking a set of patches available in
+        bugs.webkit.org.
+
+        * PrettyPatch/PrettyPatch.rb: exported a couple a globals with
+        statistics information for our test script.
+        * PrettyPatch/PrettyPatch_test.rb: Added.
+
 2011-04-22  Alexey Proskuryakov  <ap@apple.com>
 
         Code changes by Adam Barth. Reviewed by Ojan Vafai.
 2011-04-22  Alexey Proskuryakov  <ap@apple.com>
 
         Code changes by Adam Barth. Reviewed by Ojan Vafai.
index e556b1d..b8e2fb4 100644 (file)
@@ -12,6 +12,8 @@ public
     GIT_PATH = "git"
 
     def self.prettify(string)
     GIT_PATH = "git"
 
     def self.prettify(string)
+        $last_prettify_file_count = -1
+        $last_prettify_part_count = { "remove" => 0, "add" => 0, "shared" => 0 }
         string = normalize_line_ending(string)
         fileDiffs = FileDiff.parse(string)
 
         string = normalize_line_ending(string)
         fileDiffs = FileDiff.parse(string)
 
@@ -27,6 +29,7 @@ public
             break
         end
 
             break
         end
 
+        $last_prettify_file_count = fileDiffs.count
         str += fileDiffs.collect{ |diff| diff.to_html }.join
     end
 
         str += fileDiffs.collect{ |diff| diff.to_html }.join
     end
 
@@ -682,6 +685,7 @@ END
         attr :lines
 
         def initialize(className, container)
         attr :lines
 
         def initialize(className, container)
+            $last_prettify_part_count[className] += 1
             @className = className
             @lines = []
             container.parts << self
             @className = className
             @lines = []
             container.parts << self
diff --git a/Websites/bugs.webkit.org/PrettyPatch/PrettyPatch_test.rb b/Websites/bugs.webkit.org/PrettyPatch/PrettyPatch_test.rb
new file mode 100755 (executable)
index 0000000..8b714cb
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/ruby
+
+require 'test/unit'
+require 'open-uri'
+require 'PrettyPatch'
+
+# Note: internet connection is needed to run this test suite.
+
+class PrettyPatch_test < Test::Unit::TestCase
+    class Info
+        TITLE = 0
+        FILE = 1
+        ADD = 2
+        REMOVE = 3
+        SHARED = 4
+    end
+
+    PATCHES = {
+        20510 => ["Single change", 1, 1, 0, 2],
+        20528 => ["No 'Index' or 'diff' in patch header", 1, 4, 3, 7],
+        21151 => ["Leading '/' in the path of files", 4, 9, 1, 16],
+        # Binary files use shared blocks, there are three in 30488.
+        30488 => ["Quoted filenames in git diff", 23, 28, 25, 64 + 3],
+        23920 => ["Mac line ending", 3, 3, 0, 5],
+        39615 => ["Git signature", 2, 2, 0, 3],
+        80852 => ["Changes one line plus ChangeLog", 2, 2, 1, 4],
+        83127 => ["Only add stuff", 2, 2, 0, 3],
+        85071 => ["Adds and removes from a file plus git signature", 2, 5, 3, 9],
+    }
+
+    def get_patch_uri(id)
+        "https://bugs.webkit.org/attachment.cgi?id=" + id.to_s
+    end
+
+    def get_patch(id)
+        result = nil
+        patch_uri = get_patch_uri(id)
+        begin
+            result = open(patch_uri) { |f| result = f.read }
+        rescue => exception
+            assert(false, "Fail to get patch " + patch_uri)
+        end
+        result
+    end
+
+    def check_one_patch(id, info)
+        patch = get_patch(id)
+        description = get_patch_uri(id)
+        description +=  " (" + info[Info::TITLE] + ")" unless info[Info::TITLE].nil?
+        puts "Testing " + description
+        pretty = nil
+        assert_nothing_raised("Crash while prettifying " + description) {
+            pretty = PrettyPatch.prettify(patch)
+        }
+        assert(pretty, "Empty result while prettifying " + description)
+        assert_equal(info[Info::FILE], $last_prettify_file_count, "Wrong number of files changed in " + description)
+        assert_equal(info[Info::ADD], $last_prettify_part_count["add"], "Wrong number of 'add' parts in " + description)
+        assert_equal(info[Info::REMOVE], $last_prettify_part_count["remove"], "Wrong number of 'remove' parts in " + description)
+        assert_equal(info[Info::SHARED], $last_prettify_part_count["shared"], "Wrong number of 'shared' parts in " + description)
+    end
+
+    def test_patches
+        PATCHES.each { |id, info| check_one_patch(id, info) }
+    end
+end