|
1 #!/usr/bin/perl -w |
|
2 # |
|
3 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) |
|
4 # |
|
5 # Redistribution and use in source and binary forms, with or without |
|
6 # modification, are permitted provided that the following conditions |
|
7 # are met: |
|
8 # 1. Redistributions of source code must retain the above copyright |
|
9 # notice, this list of conditions and the following disclaimer. |
|
10 # 2. Redistributions in binary form must reproduce the above copyright |
|
11 # notice, this list of conditions and the following disclaimer in the |
|
12 # documentation and/or other materials provided with the distribution. |
|
13 # |
|
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
|
15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
16 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
17 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
19 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
20 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|
21 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
23 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 |
|
25 # Unit tests of parseDiff(). |
|
26 |
|
27 use strict; |
|
28 use warnings; |
|
29 |
|
30 use Test::More; |
|
31 use VCSUtils; |
|
32 |
|
33 # The array of test cases. |
|
34 my @testCaseHashRefs = ( |
|
35 { |
|
36 # New test |
|
37 diffName => "SVN: simple", |
|
38 inputText => <<'END', |
|
39 Index: Makefile |
|
40 =================================================================== |
|
41 --- Makefile (revision 53052) |
|
42 +++ Makefile (working copy) |
|
43 @@ -1,3 +1,4 @@ |
|
44 + |
|
45 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
46 |
|
47 all: |
|
48 END |
|
49 expectedReturn => [ |
|
50 [{ |
|
51 svnConvertedText => <<'END', # Same as input text |
|
52 Index: Makefile |
|
53 =================================================================== |
|
54 --- Makefile (revision 53052) |
|
55 +++ Makefile (working copy) |
|
56 @@ -1,3 +1,4 @@ |
|
57 + |
|
58 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
59 |
|
60 all: |
|
61 END |
|
62 indexPath => "Makefile", |
|
63 isSvn => 1, |
|
64 sourceRevision => "53052", |
|
65 }], |
|
66 undef], |
|
67 expectedNextLine => undef, |
|
68 }, |
|
69 { |
|
70 # New test |
|
71 diffName => "SVN: binary file (isBinary true)", |
|
72 inputText => <<'END', |
|
73 Index: test_file.swf |
|
74 =================================================================== |
|
75 Cannot display: file marked as a binary type. |
|
76 svn:mime-type = application/octet-stream |
|
77 |
|
78 Property changes on: test_file.swf |
|
79 ___________________________________________________________________ |
|
80 Name: svn:mime-type |
|
81 + application/octet-stream |
|
82 |
|
83 |
|
84 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
85 END |
|
86 expectedReturn => [ |
|
87 [{ |
|
88 svnConvertedText => <<'END', # Same as input text |
|
89 Index: test_file.swf |
|
90 =================================================================== |
|
91 Cannot display: file marked as a binary type. |
|
92 svn:mime-type = application/octet-stream |
|
93 |
|
94 |
|
95 |
|
96 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
97 END |
|
98 indexPath => "test_file.swf", |
|
99 isBinary => 1, |
|
100 isSvn => 1, |
|
101 }], |
|
102 undef], |
|
103 expectedNextLine => undef, |
|
104 }, |
|
105 { |
|
106 # New test |
|
107 diffName => "SVN: leading junk", |
|
108 inputText => <<'END', |
|
109 |
|
110 LEADING JUNK |
|
111 |
|
112 Index: Makefile |
|
113 =================================================================== |
|
114 --- Makefile (revision 53052) |
|
115 +++ Makefile (working copy) |
|
116 @@ -1,3 +1,4 @@ |
|
117 + |
|
118 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
119 |
|
120 all: |
|
121 END |
|
122 expectedReturn => [ |
|
123 [{ |
|
124 svnConvertedText => <<'END', # Same as input text |
|
125 |
|
126 LEADING JUNK |
|
127 |
|
128 Index: Makefile |
|
129 =================================================================== |
|
130 --- Makefile (revision 53052) |
|
131 +++ Makefile (working copy) |
|
132 @@ -1,3 +1,4 @@ |
|
133 + |
|
134 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
135 |
|
136 all: |
|
137 END |
|
138 indexPath => "Makefile", |
|
139 isSvn => 1, |
|
140 sourceRevision => "53052", |
|
141 }], |
|
142 undef], |
|
143 expectedNextLine => undef, |
|
144 }, |
|
145 { |
|
146 # New test |
|
147 diffName => "SVN: copied file", |
|
148 inputText => <<'END', |
|
149 Index: Makefile_new |
|
150 =================================================================== |
|
151 --- Makefile_new (revision 53131) (from Makefile:53131) |
|
152 +++ Makefile_new (working copy) |
|
153 @@ -0,0 +1,1 @@ |
|
154 +MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
155 END |
|
156 expectedReturn => [ |
|
157 [{ |
|
158 copiedFromPath => "Makefile", |
|
159 indexPath => "Makefile_new", |
|
160 sourceRevision => "53131", |
|
161 }], |
|
162 undef], |
|
163 expectedNextLine => undef, |
|
164 }, |
|
165 { |
|
166 # New test |
|
167 diffName => "SVN: two diffs", |
|
168 inputText => <<'END', |
|
169 Index: Makefile |
|
170 =================================================================== |
|
171 --- Makefile (revision 53131) |
|
172 +++ Makefile (working copy) |
|
173 @@ -1,1 +0,0 @@ |
|
174 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
175 Index: Makefile_new |
|
176 =================================================================== |
|
177 --- Makefile_new (revision 53131) (from Makefile:53131) |
|
178 END |
|
179 expectedReturn => [ |
|
180 [{ |
|
181 svnConvertedText => <<'END', |
|
182 Index: Makefile |
|
183 =================================================================== |
|
184 --- Makefile (revision 53131) |
|
185 +++ Makefile (working copy) |
|
186 @@ -1,1 +0,0 @@ |
|
187 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
188 END |
|
189 indexPath => "Makefile", |
|
190 isSvn => 1, |
|
191 sourceRevision => "53131", |
|
192 }], |
|
193 "Index: Makefile_new\n"], |
|
194 expectedNextLine => "===================================================================\n", |
|
195 }, |
|
196 { |
|
197 # New test |
|
198 diffName => "SVN: SVN diff followed by Git diff", # Should not recognize Git start |
|
199 inputText => <<'END', |
|
200 Index: Makefile |
|
201 =================================================================== |
|
202 --- Makefile (revision 53131) |
|
203 +++ Makefile (working copy) |
|
204 @@ -1,1 +0,0 @@ |
|
205 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
206 diff --git a/Makefile b/Makefile |
|
207 index f5d5e74..3b6aa92 100644 |
|
208 --- a/Makefile |
|
209 +++ b/Makefile |
|
210 @@ -1,1 1,1 @@ public: |
|
211 END |
|
212 expectedReturn => [ |
|
213 [{ |
|
214 svnConvertedText => <<'END', # Same as input text |
|
215 Index: Makefile |
|
216 =================================================================== |
|
217 --- Makefile (revision 53131) |
|
218 +++ Makefile (working copy) |
|
219 @@ -1,1 +0,0 @@ |
|
220 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools |
|
221 diff --git a/Makefile b/Makefile |
|
222 index f5d5e74..3b6aa92 100644 |
|
223 --- a/Makefile |
|
224 +++ b/Makefile |
|
225 @@ -1,1 1,1 @@ public: |
|
226 END |
|
227 indexPath => "Makefile", |
|
228 isSvn => 1, |
|
229 sourceRevision => "53131", |
|
230 }], |
|
231 undef], |
|
232 expectedNextLine => undef, |
|
233 }, |
|
234 #### |
|
235 # Property Changes: Simple |
|
236 ## |
|
237 { |
|
238 # New test |
|
239 diffName => "SVN: file change diff with property change diff", |
|
240 inputText => <<'END', |
|
241 Index: Makefile |
|
242 =================================================================== |
|
243 --- Makefile (revision 60021) |
|
244 +++ Makefile (working copy) |
|
245 @@ -1,3 +1,4 @@ |
|
246 + |
|
247 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
248 |
|
249 all: |
|
250 |
|
251 Property changes on: Makefile |
|
252 ___________________________________________________________________ |
|
253 Name: svn:executable |
|
254 + * |
|
255 END |
|
256 expectedReturn => [ |
|
257 [{ |
|
258 svnConvertedText => <<'END', # Same as input text |
|
259 Index: Makefile |
|
260 =================================================================== |
|
261 --- Makefile (revision 60021) |
|
262 +++ Makefile (working copy) |
|
263 @@ -1,3 +1,4 @@ |
|
264 + |
|
265 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
266 |
|
267 all: |
|
268 |
|
269 END |
|
270 executableBitDelta => 1, |
|
271 indexPath => "Makefile", |
|
272 isSvn => 1, |
|
273 sourceRevision => "60021", |
|
274 }], |
|
275 undef], |
|
276 expectedNextLine => undef, |
|
277 }, |
|
278 { |
|
279 # New test |
|
280 diffName => "SVN: file change diff, followed by property change diff on different file", |
|
281 inputText => <<'END', |
|
282 Index: Makefile |
|
283 =================================================================== |
|
284 --- Makefile (revision 60021) |
|
285 +++ Makefile (working copy) |
|
286 @@ -1,3 +1,4 @@ |
|
287 + |
|
288 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
289 |
|
290 all: |
|
291 |
|
292 Property changes on: Makefile.shared |
|
293 ___________________________________________________________________ |
|
294 Name: svn:executable |
|
295 + * |
|
296 END |
|
297 expectedReturn => [ |
|
298 [{ |
|
299 svnConvertedText => <<'END', # Same as input text |
|
300 Index: Makefile |
|
301 =================================================================== |
|
302 --- Makefile (revision 60021) |
|
303 +++ Makefile (working copy) |
|
304 @@ -1,3 +1,4 @@ |
|
305 + |
|
306 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
307 |
|
308 all: |
|
309 |
|
310 END |
|
311 indexPath => "Makefile", |
|
312 isSvn => 1, |
|
313 sourceRevision => "60021", |
|
314 }], |
|
315 "Property changes on: Makefile.shared\n"], |
|
316 expectedNextLine => "___________________________________________________________________\n", |
|
317 }, |
|
318 { |
|
319 # New test |
|
320 diffName => "SVN: property diff, followed by file change diff", |
|
321 inputText => <<'END', |
|
322 Property changes on: Makefile |
|
323 ___________________________________________________________________ |
|
324 Deleted: svn:executable |
|
325 - * |
|
326 |
|
327 Index: Makefile.shared |
|
328 =================================================================== |
|
329 --- Makefile.shared (revision 60021) |
|
330 +++ Makefile.shared (working copy) |
|
331 @@ -1,3 +1,4 @@ |
|
332 + |
|
333 SCRIPTS_PATH ?= ../WebKitTools/Scripts |
|
334 XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) |
|
335 END |
|
336 expectedReturn => [ |
|
337 [{ |
|
338 executableBitDelta => -1, |
|
339 indexPath => "Makefile", |
|
340 isSvn => 1, |
|
341 }], |
|
342 "Index: Makefile.shared\n"], |
|
343 expectedNextLine => "===================================================================\n", |
|
344 }, |
|
345 { |
|
346 # New test |
|
347 diffName => "SVN: copied file with property change", |
|
348 inputText => <<'END', |
|
349 Index: NMakefile |
|
350 =================================================================== |
|
351 --- NMakefile (revision 60021) (from Makefile:60021) |
|
352 +++ NMakefile (working copy) |
|
353 @@ -0,0 +1,1 @@ |
|
354 +MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
355 |
|
356 Property changes on: NMakefile |
|
357 ___________________________________________________________________ |
|
358 Added: svn:executable |
|
359 + * |
|
360 END |
|
361 expectedReturn => [ |
|
362 [{ |
|
363 copiedFromPath => "Makefile", |
|
364 executableBitDelta => 1, |
|
365 indexPath => "NMakefile", |
|
366 sourceRevision => "60021", |
|
367 }], |
|
368 undef], |
|
369 expectedNextLine => undef, |
|
370 }, |
|
371 { |
|
372 # New test |
|
373 diffName => "SVN: two consecutive property diffs", |
|
374 inputText => <<'END', |
|
375 Property changes on: Makefile |
|
376 ___________________________________________________________________ |
|
377 Added: svn:executable |
|
378 + * |
|
379 |
|
380 |
|
381 Property changes on: Makefile.shared |
|
382 ___________________________________________________________________ |
|
383 Added: svn:executable |
|
384 + * |
|
385 END |
|
386 expectedReturn => [ |
|
387 [{ |
|
388 executableBitDelta => 1, |
|
389 indexPath => "Makefile", |
|
390 isSvn => 1, |
|
391 }], |
|
392 "Property changes on: Makefile.shared\n"], |
|
393 expectedNextLine => "___________________________________________________________________\n", |
|
394 }, |
|
395 #### |
|
396 # Property Changes: Binary files |
|
397 ## |
|
398 { |
|
399 # New test |
|
400 diffName => "SVN: binary file with executable bit change", |
|
401 inputText => <<'END', |
|
402 Index: test_file.swf |
|
403 =================================================================== |
|
404 Cannot display: file marked as a binary type. |
|
405 svn:mime-type = application/octet-stream |
|
406 |
|
407 Property changes on: test_file.swf |
|
408 ___________________________________________________________________ |
|
409 Name: svn:mime-type |
|
410 + application/octet-stream |
|
411 Name: svn:executable |
|
412 + * |
|
413 |
|
414 |
|
415 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
416 END |
|
417 expectedReturn => [ |
|
418 [{ |
|
419 svnConvertedText => <<'END', # Same as input text |
|
420 Index: test_file.swf |
|
421 =================================================================== |
|
422 Cannot display: file marked as a binary type. |
|
423 svn:mime-type = application/octet-stream |
|
424 |
|
425 |
|
426 |
|
427 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
428 END |
|
429 executableBitDelta => 1, |
|
430 indexPath => "test_file.swf", |
|
431 isBinary => 1, |
|
432 isSvn => 1, |
|
433 }], |
|
434 undef], |
|
435 expectedNextLine => undef, |
|
436 }, |
|
437 { |
|
438 # New test |
|
439 diffName => "SVN: binary file followed by property change on different file", |
|
440 inputText => <<'END', |
|
441 Index: test_file.swf |
|
442 =================================================================== |
|
443 Cannot display: file marked as a binary type. |
|
444 svn:mime-type = application/octet-stream |
|
445 |
|
446 Property changes on: test_file.swf |
|
447 ___________________________________________________________________ |
|
448 Name: svn:mime-type |
|
449 + application/octet-stream |
|
450 |
|
451 |
|
452 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
453 |
|
454 Property changes on: Makefile |
|
455 ___________________________________________________________________ |
|
456 Added: svn:executable |
|
457 + * |
|
458 END |
|
459 expectedReturn => [ |
|
460 [{ |
|
461 svnConvertedText => <<'END', # Same as input text |
|
462 Index: test_file.swf |
|
463 =================================================================== |
|
464 Cannot display: file marked as a binary type. |
|
465 svn:mime-type = application/octet-stream |
|
466 |
|
467 |
|
468 |
|
469 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
470 |
|
471 END |
|
472 indexPath => "test_file.swf", |
|
473 isBinary => 1, |
|
474 isSvn => 1, |
|
475 }], |
|
476 "Property changes on: Makefile\n"], |
|
477 expectedNextLine => "___________________________________________________________________\n", |
|
478 }, |
|
479 { |
|
480 # New test |
|
481 diffName => "SVN: binary file followed by file change on different file", |
|
482 inputText => <<'END', |
|
483 Index: test_file.swf |
|
484 =================================================================== |
|
485 Cannot display: file marked as a binary type. |
|
486 svn:mime-type = application/octet-stream |
|
487 |
|
488 Property changes on: test_file.swf |
|
489 ___________________________________________________________________ |
|
490 Name: svn:mime-type |
|
491 + application/octet-stream |
|
492 |
|
493 |
|
494 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
495 |
|
496 Index: Makefile |
|
497 =================================================================== |
|
498 --- Makefile (revision 60021) |
|
499 +++ Makefile (working copy) |
|
500 @@ -1,3 +1,4 @@ |
|
501 + |
|
502 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
503 |
|
504 all: |
|
505 END |
|
506 expectedReturn => [ |
|
507 [{ |
|
508 svnConvertedText => <<'END', # Same as input text |
|
509 Index: test_file.swf |
|
510 =================================================================== |
|
511 Cannot display: file marked as a binary type. |
|
512 svn:mime-type = application/octet-stream |
|
513 |
|
514 |
|
515 |
|
516 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== |
|
517 |
|
518 END |
|
519 indexPath => "test_file.swf", |
|
520 isBinary => 1, |
|
521 isSvn => 1, |
|
522 }], |
|
523 "Index: Makefile\n"], |
|
524 expectedNextLine => "===================================================================\n", |
|
525 }, |
|
526 #### |
|
527 # Property Changes: File change with property change |
|
528 ## |
|
529 { |
|
530 # New test |
|
531 diffName => "SVN: file change diff with property change, followed by property change diff", |
|
532 inputText => <<'END', |
|
533 Index: Makefile |
|
534 =================================================================== |
|
535 --- Makefile (revision 60021) |
|
536 +++ Makefile (working copy) |
|
537 @@ -1,3 +1,4 @@ |
|
538 + |
|
539 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
540 |
|
541 all: |
|
542 |
|
543 Property changes on: Makefile |
|
544 ___________________________________________________________________ |
|
545 Added: svn:executable |
|
546 + * |
|
547 |
|
548 |
|
549 Property changes on: Makefile.shared |
|
550 ___________________________________________________________________ |
|
551 Deleted: svn:executable |
|
552 - * |
|
553 END |
|
554 expectedReturn => [ |
|
555 [{ |
|
556 svnConvertedText => <<'END', # Same as input text |
|
557 Index: Makefile |
|
558 =================================================================== |
|
559 --- Makefile (revision 60021) |
|
560 +++ Makefile (working copy) |
|
561 @@ -1,3 +1,4 @@ |
|
562 + |
|
563 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
564 |
|
565 all: |
|
566 |
|
567 |
|
568 |
|
569 END |
|
570 executableBitDelta => 1, |
|
571 indexPath => "Makefile", |
|
572 isSvn => 1, |
|
573 sourceRevision => "60021", |
|
574 }], |
|
575 "Property changes on: Makefile.shared\n"], |
|
576 expectedNextLine => "___________________________________________________________________\n", |
|
577 }, |
|
578 { |
|
579 # New test |
|
580 diffName => "SVN: file change diff with property change, followed by file change diff", |
|
581 inputText => <<'END', |
|
582 Index: Makefile |
|
583 =================================================================== |
|
584 --- Makefile (revision 60021) |
|
585 +++ Makefile (working copy) |
|
586 @@ -1,3 +1,4 @@ |
|
587 + |
|
588 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
589 |
|
590 all: |
|
591 |
|
592 Property changes on: Makefile |
|
593 ___________________________________________________________________ |
|
594 Name: svn:executable |
|
595 - * |
|
596 |
|
597 Index: Makefile.shared |
|
598 =================================================================== |
|
599 --- Makefile.shared (revision 60021) |
|
600 +++ Makefile.shared (working copy) |
|
601 @@ -1,3 +1,4 @@ |
|
602 + |
|
603 SCRIPTS_PATH ?= ../WebKitTools/Scripts |
|
604 XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) |
|
605 END |
|
606 expectedReturn => [ |
|
607 [{ |
|
608 svnConvertedText => <<'END', # Same as input text |
|
609 Index: Makefile |
|
610 =================================================================== |
|
611 --- Makefile (revision 60021) |
|
612 +++ Makefile (working copy) |
|
613 @@ -1,3 +1,4 @@ |
|
614 + |
|
615 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools |
|
616 |
|
617 all: |
|
618 |
|
619 |
|
620 END |
|
621 executableBitDelta => -1, |
|
622 indexPath => "Makefile", |
|
623 isSvn => 1, |
|
624 sourceRevision => "60021", |
|
625 }], |
|
626 "Index: Makefile.shared\n"], |
|
627 expectedNextLine => "===================================================================\n", |
|
628 }, |
|
629 #### |
|
630 # Git test cases |
|
631 ## |
|
632 { |
|
633 # New test |
|
634 diffName => "Git: simple", |
|
635 inputText => <<'END', |
|
636 diff --git a/Makefile b/Makefile |
|
637 index f5d5e74..3b6aa92 100644 |
|
638 --- a/Makefile |
|
639 +++ b/Makefile |
|
640 @@ -1,1 1,1 @@ public: |
|
641 END |
|
642 expectedReturn => [ |
|
643 [{ |
|
644 svnConvertedText => <<'END', |
|
645 Index: Makefile |
|
646 index f5d5e74..3b6aa92 100644 |
|
647 --- Makefile |
|
648 +++ Makefile |
|
649 @@ -1,1 1,1 @@ public: |
|
650 END |
|
651 indexPath => "Makefile", |
|
652 isGit => 1, |
|
653 }], |
|
654 undef], |
|
655 expectedNextLine => undef, |
|
656 }, |
|
657 { # New test |
|
658 diffName => "Git: new file", |
|
659 inputText => <<'END', |
|
660 diff --git a/foo.h b/foo.h |
|
661 new file mode 100644 |
|
662 index 0000000..3c9f114 |
|
663 --- /dev/null |
|
664 +++ b/foo.h |
|
665 @@ -0,0 +1,34 @@ |
|
666 +<html> |
|
667 diff --git a/bar b/bar |
|
668 index d45dd40..3494526 100644 |
|
669 END |
|
670 expectedReturn => [ |
|
671 [{ |
|
672 svnConvertedText => <<'END', |
|
673 Index: foo.h |
|
674 new file mode 100644 |
|
675 index 0000000..3c9f114 |
|
676 --- foo.h |
|
677 +++ foo.h |
|
678 @@ -0,0 +1,34 @@ |
|
679 +<html> |
|
680 END |
|
681 indexPath => "foo.h", |
|
682 isGit => 1, |
|
683 isNew => 1, |
|
684 }], |
|
685 "diff --git a/bar b/bar\n"], |
|
686 expectedNextLine => "index d45dd40..3494526 100644\n", |
|
687 }, |
|
688 { # New test |
|
689 diffName => "Git: file deletion", |
|
690 inputText => <<'END', |
|
691 diff --git a/foo b/foo |
|
692 deleted file mode 100644 |
|
693 index 1e50d1d..0000000 |
|
694 --- a/foo |
|
695 +++ /dev/null |
|
696 @@ -1,1 +0,0 @@ |
|
697 -line1 |
|
698 diff --git a/bar b/bar |
|
699 index d45dd40..3494526 100644 |
|
700 END |
|
701 expectedReturn => [ |
|
702 [{ |
|
703 svnConvertedText => <<'END', |
|
704 Index: foo |
|
705 deleted file mode 100644 |
|
706 index 1e50d1d..0000000 |
|
707 --- foo |
|
708 +++ foo |
|
709 @@ -1,1 +0,0 @@ |
|
710 -line1 |
|
711 END |
|
712 indexPath => "foo", |
|
713 isDeletion => 1, |
|
714 isGit => 1, |
|
715 }], |
|
716 "diff --git a/bar b/bar\n"], |
|
717 expectedNextLine => "index d45dd40..3494526 100644\n", |
|
718 }, |
|
719 { |
|
720 # New test |
|
721 diffName => "Git: Git diff followed by SVN diff", # Should not recognize SVN start |
|
722 inputText => <<'END', |
|
723 diff --git a/Makefile b/Makefile |
|
724 index f5d5e74..3b6aa92 100644 |
|
725 --- a/Makefile |
|
726 +++ b/Makefile |
|
727 @@ -1,1 1,1 @@ public: |
|
728 Index: Makefile_new |
|
729 =================================================================== |
|
730 --- Makefile_new (revision 53131) (from Makefile:53131) |
|
731 END |
|
732 expectedReturn => [ |
|
733 [{ |
|
734 svnConvertedText => <<'END', |
|
735 Index: Makefile |
|
736 index f5d5e74..3b6aa92 100644 |
|
737 --- Makefile |
|
738 +++ Makefile |
|
739 @@ -1,1 1,1 @@ public: |
|
740 Index: Makefile_new |
|
741 =================================================================== |
|
742 --- Makefile_new (revision 53131) (from Makefile:53131) |
|
743 END |
|
744 indexPath => "Makefile", |
|
745 isGit => 1, |
|
746 }], |
|
747 undef], |
|
748 expectedNextLine => undef, |
|
749 }, |
|
750 #### |
|
751 # Git test cases: file moves (multiple return values) |
|
752 ## |
|
753 { |
|
754 diffName => "Git: rename (with similarity index 100%)", |
|
755 inputText => <<'END', |
|
756 diff --git a/foo b/foo_new |
|
757 similarity index 100% |
|
758 rename from foo |
|
759 rename to foo_new |
|
760 diff --git a/bar b/bar |
|
761 index d45dd40..3494526 100644 |
|
762 END |
|
763 expectedReturn => [ |
|
764 [{ |
|
765 indexPath => "foo", |
|
766 isDeletion => 1, |
|
767 }, |
|
768 { |
|
769 copiedFromPath => "foo", |
|
770 indexPath => "foo_new", |
|
771 }], |
|
772 "diff --git a/bar b/bar\n"], |
|
773 expectedNextLine => "index d45dd40..3494526 100644\n", |
|
774 }, |
|
775 { |
|
776 diffName => "rename (with similarity index < 100%)", |
|
777 inputText => <<'END', |
|
778 diff --git a/foo b/foo_new |
|
779 similarity index 99% |
|
780 rename from foo |
|
781 rename to foo_new |
|
782 index 1e50d1d..1459d21 100644 |
|
783 --- a/foo |
|
784 +++ b/foo_new |
|
785 @@ -15,3 +15,4 @@ release r deployment dep deploy: |
|
786 line1 |
|
787 line2 |
|
788 line3 |
|
789 +line4 |
|
790 diff --git a/bar b/bar |
|
791 index d45dd40..3494526 100644 |
|
792 END |
|
793 expectedReturn => [ |
|
794 [{ |
|
795 indexPath => "foo", |
|
796 isDeletion => 1, |
|
797 }, |
|
798 { |
|
799 copiedFromPath => "foo", |
|
800 indexPath => "foo_new", |
|
801 }, |
|
802 { |
|
803 indexPath => "foo_new", |
|
804 isGit => 1, |
|
805 svnConvertedText => <<'END', |
|
806 Index: foo_new |
|
807 similarity index 99% |
|
808 rename from foo |
|
809 rename to foo_new |
|
810 index 1e50d1d..1459d21 100644 |
|
811 --- foo_new |
|
812 +++ foo_new |
|
813 @@ -15,3 +15,4 @@ release r deployment dep deploy: |
|
814 line1 |
|
815 line2 |
|
816 line3 |
|
817 +line4 |
|
818 END |
|
819 }], |
|
820 "diff --git a/bar b/bar\n"], |
|
821 expectedNextLine => "index d45dd40..3494526 100644\n", |
|
822 }, |
|
823 { |
|
824 diffName => "rename (with executable bit change)", |
|
825 inputText => <<'END', |
|
826 diff --git a/foo b/foo_new |
|
827 old mode 100644 |
|
828 new mode 100755 |
|
829 similarity index 100% |
|
830 rename from foo |
|
831 rename to foo_new |
|
832 diff --git a/bar b/bar |
|
833 index d45dd40..3494526 100644 |
|
834 END |
|
835 expectedReturn => [ |
|
836 [{ |
|
837 indexPath => "foo", |
|
838 isDeletion => 1, |
|
839 }, |
|
840 { |
|
841 copiedFromPath => "foo", |
|
842 indexPath => "foo_new", |
|
843 }, |
|
844 { |
|
845 executableBitDelta => 1, |
|
846 indexPath => "foo_new", |
|
847 isGit => 1, |
|
848 svnConvertedText => <<'END', |
|
849 Index: foo_new |
|
850 old mode 100644 |
|
851 new mode 100755 |
|
852 similarity index 100% |
|
853 rename from foo |
|
854 rename to foo_new |
|
855 END |
|
856 }], |
|
857 "diff --git a/bar b/bar\n"], |
|
858 expectedNextLine => "index d45dd40..3494526 100644\n", |
|
859 }, |
|
860 ); |
|
861 |
|
862 my $testCasesCount = @testCaseHashRefs; |
|
863 plan(tests => 2 * $testCasesCount); # Total number of assertions. |
|
864 |
|
865 foreach my $testCase (@testCaseHashRefs) { |
|
866 my $testNameStart = "parseDiff(): $testCase->{diffName}: comparing"; |
|
867 |
|
868 my $fileHandle; |
|
869 open($fileHandle, "<", \$testCase->{inputText}); |
|
870 my $line = <$fileHandle>; |
|
871 |
|
872 my @got = VCSUtils::parseDiff($fileHandle, $line); |
|
873 my $expectedReturn = $testCase->{expectedReturn}; |
|
874 |
|
875 is_deeply(\@got, $expectedReturn, "$testNameStart return value."); |
|
876 |
|
877 my $gotNextLine = <$fileHandle>; |
|
878 is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line."); |
|
879 } |