diff options
Diffstat (limited to 'WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiff.pl')
-rw-r--r-- | WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiff.pl | 769 |
1 files changed, 660 insertions, 109 deletions
diff --git a/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiff.pl b/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiff.pl index 2507d2d..245916c 100644 --- a/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiff.pl +++ b/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiff.pl @@ -30,13 +30,6 @@ use warnings; use Test::More; use VCSUtils; -my @diffHashRefKeys = ( # The $diffHashRef keys to check. - "copiedFromPath", - "indexPath", - "sourceRevision", - "svnConvertedText", -); - # The array of test cases. my @testCaseHashRefs = ( { @@ -53,7 +46,8 @@ Index: Makefile all: END - # Header keys to check + expectedReturn => [ +[{ svnConvertedText => <<'END', # Same as input text Index: Makefile =================================================================== @@ -65,12 +59,48 @@ Index: Makefile all: END - copiedFromPath => undef, indexPath => "Makefile", + isSvn => 1, sourceRevision => "53052", - # Other values to check - lastReadLine => undef, - nextLine => undef, +}], +undef], + expectedNextLine => undef, +}, +{ + # New test + diffName => "SVN: binary file (isBinary true)", + inputText => <<'END', +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + +Property changes on: test_file.swf +___________________________________________________________________ +Name: svn:mime-type + + application/octet-stream + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== +END + indexPath => "test_file.swf", + isBinary => 1, + isSvn => 1, +}], +undef], + expectedNextLine => undef, }, { # New test @@ -89,7 +119,8 @@ Index: Makefile all: END - # Header keys to check + expectedReturn => [ +[{ svnConvertedText => <<'END', # Same as input text LEADING JUNK @@ -104,12 +135,12 @@ Index: Makefile all: END - copiedFromPath => undef, indexPath => "Makefile", + isSvn => 1, sourceRevision => "53052", - # Other values to check - lastReadLine => undef, - nextLine => undef, +}], +undef], + expectedNextLine => undef, }, { # New test @@ -122,21 +153,14 @@ Index: Makefile_new @@ -0,0 +1,1 @@ +MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools END - # Header keys to check - svnConvertedText => <<'END', # Same as input text -Index: Makefile_new -=================================================================== ---- Makefile_new (revision 53131) (from Makefile:53131) -+++ Makefile_new (working copy) -@@ -0,0 +1,1 @@ -+MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools -END + expectedReturn => [ +[{ copiedFromPath => "Makefile", indexPath => "Makefile_new", sourceRevision => "53131", - # Other values to check - lastReadLine => undef, - nextLine => undef, +}], +undef], + expectedNextLine => undef, }, { # New test @@ -152,7 +176,8 @@ Index: Makefile_new =================================================================== --- Makefile_new (revision 53131) (from Makefile:53131) END - # Header keys to check + expectedReturn => [ +[{ svnConvertedText => <<'END', Index: Makefile =================================================================== @@ -161,12 +186,12 @@ Index: Makefile @@ -1,1 +0,0 @@ -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools END - copiedFromPath => undef, indexPath => "Makefile", + isSvn => 1, sourceRevision => "53131", - # Other values to check - lastReadLine => "Index: Makefile_new\n", - nextLine => "===================================================================\n", +}], +"Index: Makefile_new\n"], + expectedNextLine => "===================================================================\n", }, { # New test @@ -184,7 +209,8 @@ index f5d5e74..3b6aa92 100644 +++ b/Makefile @@ -1,1 1,1 @@ public: END - # Header keys to check + expectedReturn => [ +[{ svnConvertedText => <<'END', # Same as input text Index: Makefile =================================================================== @@ -198,13 +224,411 @@ index f5d5e74..3b6aa92 100644 +++ b/Makefile @@ -1,1 1,1 @@ public: END - copiedFromPath => undef, indexPath => "Makefile", + isSvn => 1, sourceRevision => "53131", - # Other values to check - lastReadLine => undef, - nextLine => undef, +}], +undef], + expectedNextLine => undef, +}, +#### +# Property Changes: Simple +## +{ + # New test + diffName => "SVN: file change diff with property change diff", + inputText => <<'END', +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + +Property changes on: Makefile +___________________________________________________________________ +Name: svn:executable + + * +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + +END + executableBitDelta => 1, + indexPath => "Makefile", + isSvn => 1, + sourceRevision => "60021", +}], +undef], + expectedNextLine => undef, +}, +{ + # New test + diffName => "SVN: file change diff, followed by property change diff on different file", + inputText => <<'END', +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + +Property changes on: Makefile.shared +___________________________________________________________________ +Name: svn:executable + + * +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + +END + indexPath => "Makefile", + isSvn => 1, + sourceRevision => "60021", +}], +"Property changes on: Makefile.shared\n"], + expectedNextLine => "___________________________________________________________________\n", +}, +{ + # New test + diffName => "SVN: property diff, followed by file change diff", + inputText => <<'END', +Property changes on: Makefile +___________________________________________________________________ +Deleted: svn:executable + - * + +Index: Makefile.shared +=================================================================== +--- Makefile.shared (revision 60021) ++++ Makefile.shared (working copy) +@@ -1,3 +1,4 @@ ++ +SCRIPTS_PATH ?= ../WebKitTools/Scripts +XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) +END + expectedReturn => [ +[{ + executableBitDelta => -1, + indexPath => "Makefile", + isSvn => 1, +}], +"Index: Makefile.shared\n"], + expectedNextLine => "===================================================================\n", +}, +{ + # New test + diffName => "SVN: copied file with property change", + inputText => <<'END', +Index: NMakefile +=================================================================== +--- NMakefile (revision 60021) (from Makefile:60021) ++++ NMakefile (working copy) +@@ -0,0 +1,1 @@ ++MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + +Property changes on: NMakefile +___________________________________________________________________ +Added: svn:executable + + * +END + expectedReturn => [ +[{ + copiedFromPath => "Makefile", + executableBitDelta => 1, + indexPath => "NMakefile", + sourceRevision => "60021", +}], +undef], + expectedNextLine => undef, +}, +{ + # New test + diffName => "SVN: two consecutive property diffs", + inputText => <<'END', +Property changes on: Makefile +___________________________________________________________________ +Added: svn:executable + + * + + +Property changes on: Makefile.shared +___________________________________________________________________ +Added: svn:executable + + * +END + expectedReturn => [ +[{ + executableBitDelta => 1, + indexPath => "Makefile", + isSvn => 1, +}], +"Property changes on: Makefile.shared\n"], + expectedNextLine => "___________________________________________________________________\n", +}, +#### +# Property Changes: Binary files +## +{ + # New test + diffName => "SVN: binary file with executable bit change", + inputText => <<'END', +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + +Property changes on: test_file.swf +___________________________________________________________________ +Name: svn:mime-type + + application/octet-stream +Name: svn:executable + + * + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== +END + executableBitDelta => 1, + indexPath => "test_file.swf", + isBinary => 1, + isSvn => 1, +}], +undef], + expectedNextLine => undef, +}, +{ + # New test + diffName => "SVN: binary file followed by property change on different file", + inputText => <<'END', +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + +Property changes on: test_file.swf +___________________________________________________________________ +Name: svn:mime-type + + application/octet-stream + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== + +Property changes on: Makefile +___________________________________________________________________ +Added: svn:executable + + * +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== + +END + indexPath => "test_file.swf", + isBinary => 1, + isSvn => 1, +}], +"Property changes on: Makefile\n"], + expectedNextLine => "___________________________________________________________________\n", +}, +{ + # New test + diffName => "SVN: binary file followed by file change on different file", + inputText => <<'END', +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + +Property changes on: test_file.swf +___________________________________________________________________ +Name: svn:mime-type + + application/octet-stream + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== + +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: test_file.swf +=================================================================== +Cannot display: file marked as a binary type. +svn:mime-type = application/octet-stream + + + +Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== + +END + indexPath => "test_file.swf", + isBinary => 1, + isSvn => 1, +}], +"Index: Makefile\n"], + expectedNextLine => "===================================================================\n", +}, +#### +# Property Changes: File change with property change +## +{ + # New test + diffName => "SVN: file change diff with property change, followed by property change diff", + inputText => <<'END', +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + +Property changes on: Makefile +___________________________________________________________________ +Added: svn:executable + + * + + +Property changes on: Makefile.shared +___________________________________________________________________ +Deleted: svn:executable + - * +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + + + +END + executableBitDelta => 1, + indexPath => "Makefile", + isSvn => 1, + sourceRevision => "60021", +}], +"Property changes on: Makefile.shared\n"], + expectedNextLine => "___________________________________________________________________\n", +}, +{ + # New test + diffName => "SVN: file change diff with property change, followed by file change diff", + inputText => <<'END', +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + +Property changes on: Makefile +___________________________________________________________________ +Name: svn:executable + - * + +Index: Makefile.shared +=================================================================== +--- Makefile.shared (revision 60021) ++++ Makefile.shared (working copy) +@@ -1,3 +1,4 @@ ++ +SCRIPTS_PATH ?= ../WebKitTools/Scripts +XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', # Same as input text +Index: Makefile +=================================================================== +--- Makefile (revision 60021) ++++ Makefile (working copy) +@@ -1,3 +1,4 @@ ++ + MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools + + all: + + +END + executableBitDelta => -1, + indexPath => "Makefile", + isSvn => 1, + sourceRevision => "60021", +}], +"Index: Makefile.shared\n"], + expectedNextLine => "===================================================================\n", }, +#### +# Git test cases +## { # New test diffName => "Git: simple", @@ -215,20 +639,82 @@ index f5d5e74..3b6aa92 100644 +++ b/Makefile @@ -1,1 1,1 @@ public: END - # Header keys to check + expectedReturn => [ +[{ svnConvertedText => <<'END', Index: Makefile -=================================================================== +index f5d5e74..3b6aa92 100644 --- Makefile +++ Makefile @@ -1,1 1,1 @@ public: END - copiedFromPath => undef, indexPath => "Makefile", - sourceRevision => undef, - # Other values to check - lastReadLine => undef, - nextLine => undef, + isGit => 1, +}], +undef], + expectedNextLine => undef, +}, +{ # New test + diffName => "Git: new file", + inputText => <<'END', +diff --git a/foo.h b/foo.h +new file mode 100644 +index 0000000..3c9f114 +--- /dev/null ++++ b/foo.h +@@ -0,0 +1,34 @@ ++<html> +diff --git a/bar b/bar +index d45dd40..3494526 100644 +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', +Index: foo.h +new file mode 100644 +index 0000000..3c9f114 +--- foo.h ++++ foo.h +@@ -0,0 +1,34 @@ ++<html> +END + indexPath => "foo.h", + isGit => 1, + isNew => 1, +}], +"diff --git a/bar b/bar\n"], + expectedNextLine => "index d45dd40..3494526 100644\n", +}, +{ # New test + diffName => "Git: file deletion", + inputText => <<'END', +diff --git a/foo b/foo +deleted file mode 100644 +index 1e50d1d..0000000 +--- a/foo ++++ /dev/null +@@ -1,1 +0,0 @@ +-line1 +diff --git a/bar b/bar +index d45dd40..3494526 100644 +END + expectedReturn => [ +[{ + svnConvertedText => <<'END', +Index: foo +deleted file mode 100644 +index 1e50d1d..0000000 +--- foo ++++ foo +@@ -1,1 +0,0 @@ +-line1 +END + indexPath => "foo", + isDeletion => 1, + isGit => 1, +}], +"diff --git a/bar b/bar\n"], + expectedNextLine => "index d45dd40..3494526 100644\n", }, { # New test @@ -243,10 +729,11 @@ Index: Makefile_new =================================================================== --- Makefile_new (revision 53131) (from Makefile:53131) END - # Header keys to check + expectedReturn => [ +[{ svnConvertedText => <<'END', Index: Makefile -=================================================================== +index f5d5e74..3b6aa92 100644 --- Makefile +++ Makefile @@ -1,1 1,1 @@ public: @@ -254,75 +741,139 @@ Index: Makefile_new =================================================================== --- Makefile_new (revision 53131) (from Makefile:53131) END - copiedFromPath => undef, indexPath => "Makefile", - sourceRevision => undef, - # Other values to check - lastReadLine => undef, - nextLine => undef, + isGit => 1, +}], +undef], + expectedNextLine => undef, +}, +#### +# Git test cases: file moves (multiple return values) +## +{ + diffName => "Git: rename (with similarity index 100%)", + inputText => <<'END', +diff --git a/foo b/foo_new +similarity index 100% +rename from foo +rename to foo_new +diff --git a/bar b/bar +index d45dd40..3494526 100644 +END + expectedReturn => [ +[{ + indexPath => "foo", + isDeletion => 1, +}, +{ + copiedFromPath => "foo", + indexPath => "foo_new", +}], +"diff --git a/bar b/bar\n"], + expectedNextLine => "index d45dd40..3494526 100644\n", +}, +{ + diffName => "rename (with similarity index < 100%)", + inputText => <<'END', +diff --git a/foo b/foo_new +similarity index 99% +rename from foo +rename to foo_new +index 1e50d1d..1459d21 100644 +--- a/foo ++++ b/foo_new +@@ -15,3 +15,4 @@ release r deployment dep deploy: + line1 + line2 + line3 ++line4 +diff --git a/bar b/bar +index d45dd40..3494526 100644 +END + expectedReturn => [ +[{ + indexPath => "foo", + isDeletion => 1, +}, +{ + copiedFromPath => "foo", + indexPath => "foo_new", +}, +{ + indexPath => "foo_new", + isGit => 1, + svnConvertedText => <<'END', +Index: foo_new +similarity index 99% +rename from foo +rename to foo_new +index 1e50d1d..1459d21 100644 +--- foo_new ++++ foo_new +@@ -15,3 +15,4 @@ release r deployment dep deploy: + line1 + line2 + line3 ++line4 +END +}], +"diff --git a/bar b/bar\n"], + expectedNextLine => "index d45dd40..3494526 100644\n", +}, +{ + diffName => "rename (with executable bit change)", + inputText => <<'END', +diff --git a/foo b/foo_new +old mode 100644 +new mode 100755 +similarity index 100% +rename from foo +rename to foo_new +diff --git a/bar b/bar +index d45dd40..3494526 100644 +END + expectedReturn => [ +[{ + indexPath => "foo", + isDeletion => 1, +}, +{ + copiedFromPath => "foo", + indexPath => "foo_new", +}, +{ + executableBitDelta => 1, + indexPath => "foo_new", + isGit => 1, + svnConvertedText => <<'END', +Index: foo_new +old mode 100644 +new mode 100755 +similarity index 100% +rename from foo +rename to foo_new +END +}], +"diff --git a/bar b/bar\n"], + expectedNextLine => "index d45dd40..3494526 100644\n", }, ); -# Return the arguments for each assertion per test case. -# -# In particular, the number of assertions per test case is the length -# of the return value of this subroutine on a sample input. -# -# Returns @assertionArgsArrayRefs: -# $assertionArgsArrayRef: A reference to an array of parameters to pass -# to each call to is(). The parameters are-- -# $got: The value obtained -# $expected: The expected value -# $testName: The name of the test -sub testParseDiffAssertionArgs($) -{ - my ($testCaseHashRef) = @_; +my $testCasesCount = @testCaseHashRefs; +plan(tests => 2 * $testCasesCount); # Total number of assertions. - my $fileHandle; - open($fileHandle, "<", \$testCaseHashRef->{inputText}); +foreach my $testCase (@testCaseHashRefs) { + my $testNameStart = "parseDiff(): $testCase->{diffName}: comparing"; + my $fileHandle; + open($fileHandle, "<", \$testCase->{inputText}); my $line = <$fileHandle>; - my ($diffHashRef, $lastReadLine) = VCSUtils::parseDiff($fileHandle, $line); - - my $testNameStart = "parseDiff(): [$testCaseHashRef->{diffName}] "; - - my @assertionArgsArrayRefs; # Return value - my @assertionArgs; - foreach my $diffHashRefKey (@diffHashRefKeys) { - my $testName = "${testNameStart}key=\"$diffHashRefKey\""; - @assertionArgs = ($diffHashRef->{$diffHashRefKey}, $testCaseHashRef->{$diffHashRefKey}, $testName); - push(@assertionArgsArrayRefs, \@assertionArgs); - } - - @assertionArgs = ($lastReadLine, $testCaseHashRef->{lastReadLine}, "${testNameStart}lastReadLine"); - push(@assertionArgsArrayRefs, \@assertionArgs); - - my $nextLine = <$fileHandle>; - @assertionArgs = ($nextLine, $testCaseHashRef->{nextLine}, "${testNameStart}nextLine"); - push(@assertionArgsArrayRefs, \@assertionArgs); - - return @assertionArgsArrayRefs; -} - -# Test parseDiff() for the given test case. -sub testParseDiff($) -{ - my ($testCaseHashRef) = @_; - - my @assertionArgsArrayRefs = testParseDiffAssertionArgs($testCaseHashRef); - - foreach my $arrayRef (@assertionArgsArrayRefs) { - # The parameters are -- is($got, $expected, $testName). - is($arrayRef->[0], $arrayRef->[1], $arrayRef->[2]); - } -} - -# Count the number of assertions per test case, using a sample test case. -my $assertionCount = testParseDiffAssertionArgs($testCaseHashRefs[0]); + my @got = VCSUtils::parseDiff($fileHandle, $line); + my $expectedReturn = $testCase->{expectedReturn}; -plan(tests => @testCaseHashRefs * $assertionCount); # Total number of tests + is_deeply(\@got, $expectedReturn, "$testNameStart return value."); -foreach my $testCaseHashRef (@testCaseHashRefs) { - testParseDiff($testCaseHashRef); + my $gotNextLine = <$fileHandle>; + is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line."); } |