3
# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
4
# Copyright (C) 2012 Daniel Bates (dbates@intudata.com)
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are
10
# * Redistributions of source code must retain the above copyright
11
# notice, this list of conditions and the following disclaimer.
12
# * Redistributions in binary form must reproduce the above
13
# copyright notice, this list of conditions and the following disclaimer
14
# in the documentation and/or other materials provided with the
16
# * Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17
# its contributors may be used to endorse or promote products derived
18
# from this software without specific prior written permission.
20
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
# Unit tests of parseSvnDiffHeader().
40
# The array of test cases.
41
my @testCaseHashRefs = (
44
diffName => "simple diff",
46
Index: WebKitTools/Scripts/VCSUtils.pm
47
===================================================================
48
--- WebKitTools/Scripts/VCSUtils.pm (revision 53004)
49
+++ WebKitTools/Scripts/VCSUtils.pm (working copy)
50
@@ -32,6 +32,7 @@ use strict;
55
svnConvertedText => <<'END',
56
Index: WebKitTools/Scripts/VCSUtils.pm
57
===================================================================
58
--- WebKitTools/Scripts/VCSUtils.pm (revision 53004)
59
+++ WebKitTools/Scripts/VCSUtils.pm (working copy)
61
indexPath => "WebKitTools/Scripts/VCSUtils.pm",
62
sourceRevision => "53004",
64
"@@ -32,6 +32,7 @@ use strict;\n"],
65
expectedNextLine => " use warnings;\n",
69
diffName => "new file",
71
Index: WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl
72
===================================================================
73
--- WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
74
+++ WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
80
svnConvertedText => <<'END',
81
Index: WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl
82
===================================================================
83
--- WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
84
+++ WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
86
indexPath => "WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl",
89
"@@ -0,0 +1,262 @@\n"],
90
expectedNextLine => "+#!/usr/bin/perl -w\n",
94
diffName => "new file with spaces in its name",
96
Index: WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme
97
===================================================================
98
--- WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme (revision 0)
99
+++ WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme (revision 0)
101
+<?xml version="1.0" encoding="UTF-8"?>
105
svnConvertedText => <<'END',
106
Index: WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme
107
===================================================================
108
--- WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme (revision 0)
109
+++ WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme (revision 0)
111
indexPath => "WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme",
114
"@@ -0,0 +1,8 @@\n"],
115
expectedNextLine => "+<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
119
diffName => "copied file",
120
inputText => <<'END',
122
===================================================================
123
--- index_path.py (revision 53048) (from copied_from_path.py:53048)
124
+++ index_path.py (working copy)
130
svnConvertedText => <<'END',
132
===================================================================
133
--- index_path.py (revision 53048) (from copied_from_path.py:53048)
134
+++ index_path.py (working copy)
136
copiedFromPath => "copied_from_path.py",
137
indexPath => "index_path.py",
138
sourceRevision => 53048,
140
"@@ -0,0 +1,7 @@\n"],
141
expectedNextLine => "+# Python file...\n",
145
diffName => "contains \\r\\n lines",
146
inputText => <<END, # No single quotes to allow interpolation of "\r"
147
Index: index_path.py\r
148
===================================================================\r
149
--- index_path.py (revision 53048)\r
150
+++ index_path.py (working copy)\r
156
svnConvertedText => <<END, # No single quotes to allow interpolation of "\r"
157
Index: index_path.py\r
158
===================================================================\r
159
--- index_path.py (revision 53048)\r
160
+++ index_path.py (working copy)\r
162
indexPath => "index_path.py",
163
sourceRevision => 53048,
165
"@@ -0,0 +1,7 @@\r\n"],
166
expectedNextLine => "+# Python file...\r\n",
170
diffName => "contains path corrections",
171
inputText => <<'END',
173
===================================================================
174
--- bad_path (revision 53048) (from copied_from_path.py:53048)
175
+++ bad_path (working copy)
181
svnConvertedText => <<'END',
183
===================================================================
184
--- index_path.py (revision 53048) (from copied_from_path.py:53048)
185
+++ index_path.py (working copy)
187
copiedFromPath => "copied_from_path.py",
188
indexPath => "index_path.py",
189
sourceRevision => 53048,
191
"@@ -0,0 +1,7 @@\n"],
192
expectedNextLine => "+# Python file...\n",
199
diffName => "binary file",
200
inputText => <<'END',
202
===================================================================
203
Cannot display: file marked as a binary type.
204
svn:mime-type = application/octet-stream
206
Property changes on: test_file.swf
207
___________________________________________________________________
209
+ application/octet-stream
212
Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
216
svnConvertedText => <<'END',
218
===================================================================
219
Cannot display: file marked as a binary type.
220
svn:mime-type = application/octet-stream
223
indexPath => "test_file.swf",
226
"Property changes on: test_file.swf\n"],
227
expectedNextLine => "___________________________________________________________________\n",
231
diffName => "binary file using SVN 1.7 syntax",
232
inputText => <<'END',
234
===================================================================
235
Cannot display: file marked as a binary type.
236
svn:mime-type = application/octet-stream
238
===================================================================
242
Property changes on: test_file.swf
243
___________________________________________________________________
246
+application/octet-stream
247
\ No newline at end of property
249
Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
253
svnConvertedText => <<'END',
255
===================================================================
256
Cannot display: file marked as a binary type.
257
svn:mime-type = application/octet-stream
259
===================================================================
263
indexPath => "test_file.swf",
267
expectedNextLine => "Property changes on: test_file.swf\n",
271
my $testCasesCount = @testCaseHashRefs;
272
plan(tests => 2 * $testCasesCount); # Total number of assertions.
274
foreach my $testCase (@testCaseHashRefs) {
275
my $testNameStart = "parseSvnDiffHeader(): $testCase->{diffName}: comparing";
278
open($fileHandle, "<", \$testCase->{inputText});
279
my $line = <$fileHandle>;
281
my @got = VCSUtils::parseSvnDiffHeader($fileHandle, $line);
282
my $expectedReturn = $testCase->{expectedReturn};
284
is_deeply(\@got, $expectedReturn, "$testNameStart return value.");
286
my $gotNextLine = <$fileHandle>;
287
is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line.");