|
1 #!/usr/bin/perl -w |
|
2 # |
|
3 # Copyright (C) Research in Motion Limited 2010. All Rights Reserved. |
|
4 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.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 parseSvnDiffProperties(). |
|
33 |
|
34 use strict; |
|
35 use warnings; |
|
36 |
|
37 use Test::More; |
|
38 use VCSUtils; |
|
39 |
|
40 my @testCaseHashRefs = ( |
|
41 #### |
|
42 # Simple test cases |
|
43 ## |
|
44 { |
|
45 # New test |
|
46 diffName => "simple: add svn:executable", |
|
47 inputText => <<'END', |
|
48 Property changes on: FileA |
|
49 ___________________________________________________________________ |
|
50 Added: svn:executable |
|
51 + * |
|
52 END |
|
53 expectedReturn => [ |
|
54 { |
|
55 propertyPath => "FileA", |
|
56 executableBitDelta => 1, |
|
57 }, |
|
58 undef], |
|
59 expectedNextLine => undef, |
|
60 }, |
|
61 { |
|
62 # New test |
|
63 diffName => "simple: delete svn:executable", |
|
64 inputText => <<'END', |
|
65 Property changes on: FileA |
|
66 ___________________________________________________________________ |
|
67 Deleted: svn:executable |
|
68 - * |
|
69 END |
|
70 expectedReturn => [ |
|
71 { |
|
72 propertyPath => "FileA", |
|
73 executableBitDelta => -1, |
|
74 }, |
|
75 undef], |
|
76 expectedNextLine => undef, |
|
77 }, |
|
78 { |
|
79 # New test |
|
80 diffName => "simple: delete svn:executable using SVN 1.4 syntax", |
|
81 inputText => <<'END', |
|
82 Property changes on: FileA |
|
83 ___________________________________________________________________ |
|
84 Name: svn:executable |
|
85 - * |
|
86 END |
|
87 expectedReturn => [ |
|
88 { |
|
89 propertyPath => "FileA", |
|
90 executableBitDelta => -1, |
|
91 }, |
|
92 undef], |
|
93 expectedNextLine => undef, |
|
94 }, |
|
95 #### |
|
96 # Property value followed by empty line and start of next diff |
|
97 ## |
|
98 { |
|
99 # New test |
|
100 diffName => "add svn:executable, followed by empty line and start of next diff", |
|
101 inputText => <<'END', |
|
102 Property changes on: FileA |
|
103 ___________________________________________________________________ |
|
104 Added: svn:executable |
|
105 + * |
|
106 |
|
107 Index: Makefile.shared |
|
108 END |
|
109 expectedReturn => [ |
|
110 { |
|
111 propertyPath => "FileA", |
|
112 executableBitDelta => 1, |
|
113 }, |
|
114 "\n"], |
|
115 expectedNextLine => "Index: Makefile.shared\n", |
|
116 }, |
|
117 { |
|
118 # New test |
|
119 diffName => "add svn:executable, followed by empty line and start of next property diff", |
|
120 inputText => <<'END', |
|
121 Property changes on: FileA |
|
122 ___________________________________________________________________ |
|
123 Added: svn:executable |
|
124 + * |
|
125 |
|
126 Property changes on: Makefile.shared |
|
127 END |
|
128 expectedReturn => [ |
|
129 { |
|
130 propertyPath => "FileA", |
|
131 executableBitDelta => 1, |
|
132 }, |
|
133 "\n"], |
|
134 expectedNextLine => "Property changes on: Makefile.shared\n", |
|
135 }, |
|
136 #### |
|
137 # Property value followed by empty line and start of the binary contents |
|
138 ## |
|
139 { |
|
140 # New test |
|
141 diffName => "add svn:executable, followed by empty line and start of binary contents", |
|
142 inputText => <<'END', |
|
143 Property changes on: FileA |
|
144 ___________________________________________________________________ |
|
145 Added: svn:executable |
|
146 + * |
|
147 |
|
148 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
149 END |
|
150 expectedReturn => [ |
|
151 { |
|
152 propertyPath => "FileA", |
|
153 executableBitDelta => 1, |
|
154 }, |
|
155 "\n"], |
|
156 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n", |
|
157 }, |
|
158 { |
|
159 # New test |
|
160 diffName => "custom property followed by svn:executable, empty line and start of binary contents", |
|
161 inputText => <<'END', |
|
162 Property changes on: FileA |
|
163 ___________________________________________________________________ |
|
164 Added: documentation |
|
165 + This is an example sentence. |
|
166 Added: svn:executable |
|
167 + * |
|
168 |
|
169 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
170 END |
|
171 expectedReturn => [ |
|
172 { |
|
173 propertyPath => "FileA", |
|
174 executableBitDelta => 1, |
|
175 }, |
|
176 "\n"], |
|
177 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n", |
|
178 }, |
|
179 #### |
|
180 # Successive properties |
|
181 ## |
|
182 { |
|
183 # New test |
|
184 diffName => "svn:executable followed by custom property", |
|
185 inputText => <<'END', |
|
186 Property changes on: FileA |
|
187 ___________________________________________________________________ |
|
188 Added: svn:executable |
|
189 + * |
|
190 Added: documentation |
|
191 + This is an example sentence. |
|
192 END |
|
193 expectedReturn => [ |
|
194 { |
|
195 propertyPath => "FileA", |
|
196 executableBitDelta => 1, |
|
197 }, |
|
198 undef], |
|
199 expectedNextLine => undef, |
|
200 }, |
|
201 { |
|
202 # New test |
|
203 diffName => "custom property followed by svn:executable", |
|
204 inputText => <<'END', |
|
205 Property changes on: FileA |
|
206 ___________________________________________________________________ |
|
207 Added: documentation |
|
208 + This is an example sentence. |
|
209 Added: svn:executable |
|
210 + * |
|
211 END |
|
212 expectedReturn => [ |
|
213 { |
|
214 propertyPath => "FileA", |
|
215 executableBitDelta => 1, |
|
216 }, |
|
217 undef], |
|
218 expectedNextLine => undef, |
|
219 }, |
|
220 #### |
|
221 # Successive properties followed by empty line and start of next diff |
|
222 ## |
|
223 { |
|
224 # New test |
|
225 diffName => "custom property followed by svn:executable, empty line and start of next property diff", |
|
226 inputText => <<'END', |
|
227 Property changes on: FileA |
|
228 ___________________________________________________________________ |
|
229 Added: documentation |
|
230 + This is an example sentence. |
|
231 Added: svn:executable |
|
232 + * |
|
233 |
|
234 Property changes on: Makefile.shared |
|
235 END |
|
236 expectedReturn => [ |
|
237 { |
|
238 propertyPath => "FileA", |
|
239 executableBitDelta => 1, |
|
240 }, |
|
241 "\n"], |
|
242 expectedNextLine => "Property changes on: Makefile.shared\n", |
|
243 }, |
|
244 { |
|
245 # New test |
|
246 diffName => "custom property followed by svn:executable, empty line and start of next index diff", |
|
247 inputText => <<'END', |
|
248 Property changes on: FileA |
|
249 ___________________________________________________________________ |
|
250 Added: documentation |
|
251 + This is an example sentence. |
|
252 Added: svn:executable |
|
253 + * |
|
254 |
|
255 Index: Makefile.shared |
|
256 END |
|
257 expectedReturn => [ |
|
258 { |
|
259 propertyPath => "FileA", |
|
260 executableBitDelta => 1, |
|
261 }, |
|
262 "\n"], |
|
263 expectedNextLine => "Index: Makefile.shared\n", |
|
264 }, |
|
265 #### |
|
266 # Custom properties |
|
267 ## |
|
268 # FIXME: We do not support anything other than the svn:executable property. |
|
269 # We should add support for handling other properties. |
|
270 { |
|
271 # New test |
|
272 diffName => "simple: custom property", |
|
273 inputText => <<'END', |
|
274 Property changes on: FileA |
|
275 ___________________________________________________________________ |
|
276 Name: documentation |
|
277 + This is an example sentence. |
|
278 END |
|
279 expectedReturn => [ |
|
280 { |
|
281 propertyPath => "FileA", |
|
282 }, |
|
283 undef], |
|
284 expectedNextLine => undef, |
|
285 }, |
|
286 { |
|
287 # New test |
|
288 diffName => "custom property followed by custom property", |
|
289 inputText => <<'END', |
|
290 Property changes on: FileA |
|
291 ___________________________________________________________________ |
|
292 Added: copyright |
|
293 + Copyright (C) Research in Motion Limited 2010. All Rights Reserved. |
|
294 Added: documentation |
|
295 + This is an example sentence. |
|
296 END |
|
297 expectedReturn => [ |
|
298 { |
|
299 propertyPath => "FileA", |
|
300 }, |
|
301 undef], |
|
302 expectedNextLine => undef, |
|
303 }, |
|
304 #### |
|
305 # Malformed property diffs |
|
306 ## |
|
307 # We shouldn't encounter such diffs in practice. |
|
308 { |
|
309 # New test |
|
310 diffName => "svn:executable followed by custom property and svn:executable", |
|
311 inputText => <<'END', |
|
312 Property changes on: FileA |
|
313 ___________________________________________________________________ |
|
314 Added: svn:executable |
|
315 + * |
|
316 Added: documentation |
|
317 + This is an example sentence. |
|
318 Deleted: svn:executable |
|
319 - * |
|
320 END |
|
321 expectedReturn => [ |
|
322 { |
|
323 propertyPath => "FileA", |
|
324 executableBitDelta => -1, |
|
325 }, |
|
326 undef], |
|
327 expectedNextLine => undef, |
|
328 }, |
|
329 ); |
|
330 |
|
331 my $testCasesCount = @testCaseHashRefs; |
|
332 plan(tests => 2 * $testCasesCount); # Total number of assertions. |
|
333 |
|
334 foreach my $testCase (@testCaseHashRefs) { |
|
335 my $testNameStart = "parseSvnDiffProperties(): $testCase->{diffName}: comparing"; |
|
336 |
|
337 my $fileHandle; |
|
338 open($fileHandle, "<", \$testCase->{inputText}); |
|
339 my $line = <$fileHandle>; |
|
340 |
|
341 my @got = VCSUtils::parseSvnDiffProperties($fileHandle, $line); |
|
342 my $expectedReturn = $testCase->{expectedReturn}; |
|
343 |
|
344 is_deeply(\@got, $expectedReturn, "$testNameStart return value."); |
|
345 |
|
346 my $gotNextLine = <$fileHandle>; |
|
347 is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line."); |
|
348 } |