~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#
 
3
# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
 
4
# Copyright (C) 2012 Daniel Bates (dbates@intudata.com)
 
5
#
 
6
# Redistribution and use in source and binary forms, with or without
 
7
# modification, are permitted provided that the following conditions are
 
8
# met:
 
9
#
 
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
 
15
# distribution.
 
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.
 
19
#
 
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.
 
31
 
 
32
# Unit tests of parseSvnDiffHeader().
 
33
 
 
34
use strict;
 
35
use warnings;
 
36
 
 
37
use Test::More;
 
38
use VCSUtils;
 
39
 
 
40
# The array of test cases.
 
41
my @testCaseHashRefs = (
 
42
{
 
43
    # New test
 
44
    diffName => "simple diff",
 
45
    inputText => <<'END',
 
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;
 
51
 use warnings;
 
52
END
 
53
    expectedReturn => [
 
54
{
 
55
    svnConvertedText => <<'END',
 
56
Index: WebKitTools/Scripts/VCSUtils.pm
 
57
===================================================================
 
58
--- WebKitTools/Scripts/VCSUtils.pm     (revision 53004)
 
59
+++ WebKitTools/Scripts/VCSUtils.pm     (working copy)
 
60
END
 
61
    indexPath => "WebKitTools/Scripts/VCSUtils.pm",
 
62
    sourceRevision => "53004",
 
63
},
 
64
"@@ -32,6 +32,7 @@ use strict;\n"],
 
65
    expectedNextLine => " use warnings;\n",
 
66
},
 
67
{
 
68
    # New test
 
69
    diffName => "new file",
 
70
    inputText => <<'END',
 
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)
 
75
@@ -0,0 +1,262 @@
 
76
+#!/usr/bin/perl -w
 
77
END
 
78
    expectedReturn => [
 
79
{
 
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)
 
85
END
 
86
    indexPath => "WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl",
 
87
    isNew => 1,
 
88
},
 
89
"@@ -0,0 +1,262 @@\n"],
 
90
    expectedNextLine => "+#!/usr/bin/perl -w\n",
 
91
},
 
92
{
 
93
    # New test
 
94
    diffName => "new file with spaces in its name",
 
95
    inputText => <<'END',
 
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)
 
100
@@ -0,0 +1,8 @@
 
101
+<?xml version="1.0" encoding="UTF-8"?>
 
102
END
 
103
    expectedReturn => [
 
104
{
 
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)
 
110
END
 
111
    indexPath => "WebKit.xcworkspace/xcshareddata/xcschemes/All Source (target WebProcess).xcscheme",
 
112
    isNew => 1,
 
113
},
 
114
"@@ -0,0 +1,8 @@\n"],
 
115
    expectedNextLine => "+<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
 
116
},
 
117
{
 
118
    # New test
 
119
    diffName => "copied file",
 
120
    inputText => <<'END',
 
121
Index: index_path.py
 
122
===================================================================
 
123
--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)
 
124
+++ index_path.py       (working copy)
 
125
@@ -0,0 +1,7 @@
 
126
+# Python file...
 
127
END
 
128
    expectedReturn => [
 
129
{
 
130
    svnConvertedText => <<'END',
 
131
Index: index_path.py
 
132
===================================================================
 
133
--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)
 
134
+++ index_path.py       (working copy)
 
135
END
 
136
    copiedFromPath => "copied_from_path.py",
 
137
    indexPath => "index_path.py",
 
138
    sourceRevision => 53048,
 
139
},
 
140
"@@ -0,0 +1,7 @@\n"],
 
141
    expectedNextLine => "+# Python file...\n",
 
142
},
 
143
{
 
144
    # New test
 
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
 
151
@@ -0,0 +1,7 @@\r
 
152
+# Python file...\r
 
153
END
 
154
    expectedReturn => [
 
155
{
 
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
 
161
END
 
162
    indexPath => "index_path.py",
 
163
    sourceRevision => 53048,
 
164
},
 
165
"@@ -0,0 +1,7 @@\r\n"],
 
166
    expectedNextLine => "+# Python file...\r\n",
 
167
},
 
168
{
 
169
    # New test
 
170
    diffName => "contains path corrections",
 
171
    inputText => <<'END',
 
172
Index: index_path.py
 
173
===================================================================
 
174
--- bad_path    (revision 53048)        (from copied_from_path.py:53048)
 
175
+++ bad_path    (working copy)
 
176
@@ -0,0 +1,7 @@
 
177
+# Python file...
 
178
END
 
179
    expectedReturn => [
 
180
{
 
181
    svnConvertedText => <<'END',
 
182
Index: index_path.py
 
183
===================================================================
 
184
--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)
 
185
+++ index_path.py       (working copy)
 
186
END
 
187
    copiedFromPath => "copied_from_path.py",
 
188
    indexPath => "index_path.py",
 
189
    sourceRevision => 53048,
 
190
},
 
191
"@@ -0,0 +1,7 @@\n"],
 
192
    expectedNextLine => "+# Python file...\n",
 
193
},
 
194
####
 
195
#    Binary test cases
 
196
##
 
197
{
 
198
    # New test
 
199
    diffName => "binary file",
 
200
    inputText => <<'END',
 
201
Index: test_file.swf
 
202
===================================================================
 
203
Cannot display: file marked as a binary type.
 
204
svn:mime-type = application/octet-stream
 
205
 
 
206
Property changes on: test_file.swf
 
207
___________________________________________________________________
 
208
Name: svn:mime-type
 
209
   + application/octet-stream
 
210
 
 
211
 
 
212
Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
 
213
END
 
214
    expectedReturn => [
 
215
{
 
216
    svnConvertedText => <<'END',
 
217
Index: test_file.swf
 
218
===================================================================
 
219
Cannot display: file marked as a binary type.
 
220
svn:mime-type = application/octet-stream
 
221
 
 
222
END
 
223
    indexPath => "test_file.swf",
 
224
    isBinary => 1,
 
225
},
 
226
"Property changes on: test_file.swf\n"],
 
227
    expectedNextLine => "___________________________________________________________________\n",
 
228
},
 
229
{
 
230
    # New test
 
231
    diffName => "binary file using SVN 1.7 syntax",
 
232
    inputText => <<'END',
 
233
Index: test_file.swf
 
234
===================================================================
 
235
Cannot display: file marked as a binary type.
 
236
svn:mime-type = application/octet-stream
 
237
Index: test_file.swf
 
238
===================================================================
 
239
--- test_file.swf
 
240
+++ test_file.swf
 
241
 
 
242
Property changes on: test_file.swf
 
243
___________________________________________________________________
 
244
Added: svn:mime-type
 
245
## -0,0 +1 ##
 
246
+application/octet-stream
 
247
\ No newline at end of property
 
248
 
 
249
Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==
 
250
END
 
251
    expectedReturn => [
 
252
{
 
253
    svnConvertedText => <<'END',
 
254
Index: test_file.swf
 
255
===================================================================
 
256
Cannot display: file marked as a binary type.
 
257
svn:mime-type = application/octet-stream
 
258
Index: test_file.swf
 
259
===================================================================
 
260
--- test_file.swf
 
261
+++ test_file.swf
 
262
END
 
263
    indexPath => "test_file.swf",
 
264
    isBinary => 1,
 
265
},
 
266
"\n"],
 
267
    expectedNextLine => "Property changes on: test_file.swf\n",
 
268
},
 
269
);
 
270
 
 
271
my $testCasesCount = @testCaseHashRefs;
 
272
plan(tests => 2 * $testCasesCount); # Total number of assertions.
 
273
 
 
274
foreach my $testCase (@testCaseHashRefs) {
 
275
    my $testNameStart = "parseSvnDiffHeader(): $testCase->{diffName}: comparing";
 
276
 
 
277
    my $fileHandle;
 
278
    open($fileHandle, "<", \$testCase->{inputText});
 
279
    my $line = <$fileHandle>;
 
280
 
 
281
    my @got = VCSUtils::parseSvnDiffHeader($fileHandle, $line);
 
282
    my $expectedReturn = $testCase->{expectedReturn};
 
283
 
 
284
    is_deeply(\@got, $expectedReturn, "$testNameStart return value.");
 
285
 
 
286
    my $gotNextLine = <$fileHandle>;
 
287
    is($gotNextLine, $testCase->{expectedNextLine},  "$testNameStart next read line.");
 
288
}