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 27use strict; 28use warnings; 29 30use Test::More; 31use VCSUtils; 32 33# The array of test cases. 34my @testCaseHashRefs = ( 35{ 36 # New test 37 diffName => "SVN: simple", 38 inputText => <<'END', 39Index: 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: 48END 49 expectedReturn => [ 50[{ 51 svnConvertedText => <<'END', # Same as input text 52Index: 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: 61END 62 indexPath => "Makefile", 63 isSvn => 1, 64 numTextChunks => 1, 65 sourceRevision => "53052", 66}], 67undef], 68 expectedNextLine => undef, 69}, 70{ 71 # New test 72 diffName => "SVN: binary file (isBinary true)", 73 inputText => <<'END', 74Index: test_file.swf 75=================================================================== 76Cannot display: file marked as a binary type. 77svn:mime-type = application/octet-stream 78 79Property changes on: test_file.swf 80___________________________________________________________________ 81Name: svn:mime-type 82 + application/octet-stream 83 84 85Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 86END 87 expectedReturn => [ 88[{ 89 svnConvertedText => <<'END', # Same as input text 90Index: test_file.swf 91=================================================================== 92Cannot display: file marked as a binary type. 93svn:mime-type = application/octet-stream 94 95 96 97Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 98END 99 indexPath => "test_file.swf", 100 isBinary => 1, 101 isSvn => 1, 102}], 103undef], 104 expectedNextLine => undef, 105}, 106{ 107 # New test 108 diffName => "SVN: binary file (isBinary true) using Windows line endings", 109 inputText => toWindowsLineEndings(<<'END', 110Index: test_file.swf 111=================================================================== 112Cannot display: file marked as a binary type. 113svn:mime-type = application/octet-stream 114 115Property changes on: test_file.swf 116___________________________________________________________________ 117Name: svn:mime-type 118 + application/octet-stream 119 120 121Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 122END 123), 124 expectedReturn => [ 125[{ 126 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 127Index: test_file.swf 128=================================================================== 129Cannot display: file marked as a binary type. 130svn:mime-type = application/octet-stream 131 132 133 134Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 135END 136), 137 indexPath => "test_file.swf", 138 isBinary => 1, 139 isSvn => 1, 140}], 141undef], 142 expectedNextLine => undef, 143}, 144{ 145 # New test 146 diffName => "SVN: leading junk", 147 inputText => <<'END', 148 149LEADING JUNK 150 151Index: Makefile 152=================================================================== 153--- Makefile (revision 53052) 154+++ Makefile (working copy) 155@@ -1,3 +1,4 @@ 156+ 157 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 158 159 all: 160END 161 expectedReturn => [ 162[{ 163 svnConvertedText => <<'END', # Same as input text 164 165LEADING JUNK 166 167Index: Makefile 168=================================================================== 169--- Makefile (revision 53052) 170+++ Makefile (working copy) 171@@ -1,3 +1,4 @@ 172+ 173 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 174 175 all: 176END 177 indexPath => "Makefile", 178 isSvn => 1, 179 numTextChunks => 1, 180 sourceRevision => "53052", 181}], 182undef], 183 expectedNextLine => undef, 184}, 185{ 186 # New test 187 diffName => "SVN: copied file", 188 inputText => <<'END', 189Index: Makefile_new 190=================================================================== 191--- Makefile_new (revision 53131) (from Makefile:53131) 192+++ Makefile_new (working copy) 193@@ -0,0 +1,1 @@ 194+MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 195END 196 expectedReturn => [ 197[{ 198 copiedFromPath => "Makefile", 199 indexPath => "Makefile_new", 200 sourceRevision => "53131", 201}], 202undef], 203 expectedNextLine => undef, 204}, 205{ 206 # New test 207 diffName => "SVN: two diffs", 208 inputText => <<'END', 209Index: Makefile 210=================================================================== 211--- Makefile (revision 53131) 212+++ Makefile (working copy) 213@@ -1,1 +0,0 @@ 214-MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 215Index: Makefile_new 216=================================================================== 217--- Makefile_new (revision 53131) (from Makefile:53131) 218END 219 expectedReturn => [ 220[{ 221 svnConvertedText => <<'END', 222Index: Makefile 223=================================================================== 224--- Makefile (revision 53131) 225+++ Makefile (working copy) 226@@ -1,1 +0,0 @@ 227-MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 228END 229 indexPath => "Makefile", 230 isSvn => 1, 231 numTextChunks => 1, 232 sourceRevision => "53131", 233}], 234"Index: Makefile_new\n"], 235 expectedNextLine => "===================================================================\n", 236}, 237{ 238 # New test 239 diffName => "SVN: SVN diff followed by Git diff", # Should not recognize Git start 240 inputText => <<'END', 241Index: Makefile 242=================================================================== 243--- Makefile (revision 53131) 244+++ Makefile (working copy) 245@@ -1,1 +0,0 @@ 246-MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 247diff --git a/Makefile b/Makefile 248index f5d5e74..3b6aa92 100644 249--- a/Makefile 250+++ b/Makefile 251@@ -1,1 1,1 @@ public: 252END 253 expectedReturn => [ 254[{ 255 svnConvertedText => <<'END', # Same as input text 256Index: Makefile 257=================================================================== 258--- Makefile (revision 53131) 259+++ Makefile (working copy) 260@@ -1,1 +0,0 @@ 261-MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 262diff --git a/Makefile b/Makefile 263index f5d5e74..3b6aa92 100644 264--- a/Makefile 265+++ b/Makefile 266@@ -1,1 1,1 @@ public: 267END 268 indexPath => "Makefile", 269 isSvn => 1, 270 numTextChunks => 1, 271 sourceRevision => "53131", 272}], 273undef], 274 expectedNextLine => undef, 275}, 276#### 277# Property Changes: Simple 278## 279{ 280 # New test 281 diffName => "SVN: file change diff with property change diff", 282 inputText => <<'END', 283Index: Makefile 284=================================================================== 285--- Makefile (revision 60021) 286+++ Makefile (working copy) 287@@ -1,3 +1,4 @@ 288+ 289 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 290 291 all: 292 293Property changes on: Makefile 294___________________________________________________________________ 295Name: svn:executable 296 + * 297END 298 expectedReturn => [ 299[{ 300 svnConvertedText => <<'END', # Same as input text 301Index: Makefile 302=================================================================== 303--- Makefile (revision 60021) 304+++ Makefile (working copy) 305@@ -1,3 +1,4 @@ 306+ 307 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 308 309 all: 310 311END 312 executableBitDelta => 1, 313 indexPath => "Makefile", 314 isSvn => 1, 315 numTextChunks => 1, 316 sourceRevision => "60021", 317}], 318undef], 319 expectedNextLine => undef, 320}, 321{ 322 # New test 323 diffName => "SVN: file change diff, followed by property change diff on different file", 324 inputText => <<'END', 325Index: Makefile 326=================================================================== 327--- Makefile (revision 60021) 328+++ Makefile (working copy) 329@@ -1,3 +1,4 @@ 330+ 331 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 332 333 all: 334 335Property changes on: Makefile.shared 336___________________________________________________________________ 337Name: svn:executable 338 + * 339END 340 expectedReturn => [ 341[{ 342 svnConvertedText => <<'END', # Same as input text 343Index: Makefile 344=================================================================== 345--- Makefile (revision 60021) 346+++ Makefile (working copy) 347@@ -1,3 +1,4 @@ 348+ 349 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 350 351 all: 352 353END 354 indexPath => "Makefile", 355 isSvn => 1, 356 numTextChunks => 1, 357 sourceRevision => "60021", 358}], 359"Property changes on: Makefile.shared\n"], 360 expectedNextLine => "___________________________________________________________________\n", 361}, 362{ 363 # New test 364 diffName => "SVN: property diff, followed by file change diff", 365 inputText => <<'END', 366Property changes on: Makefile 367___________________________________________________________________ 368Deleted: svn:executable 369 - * 370 371Index: Makefile.shared 372=================================================================== 373--- Makefile.shared (revision 60021) 374+++ Makefile.shared (working copy) 375@@ -1,3 +1,4 @@ 376+ 377SCRIPTS_PATH ?= ../WebKitTools/Scripts 378XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 379END 380 expectedReturn => [ 381[{ 382 executableBitDelta => -1, 383 indexPath => "Makefile", 384 isSvn => 1, 385}], 386"Index: Makefile.shared\n"], 387 expectedNextLine => "===================================================================\n", 388}, 389{ 390 # New test 391 diffName => "SVN: property diff, followed by file change diff using Windows line endings", 392 inputText => toWindowsLineEndings(<<'END', 393Property changes on: Makefile 394___________________________________________________________________ 395Deleted: svn:executable 396 - * 397 398Index: Makefile.shared 399=================================================================== 400--- Makefile.shared (revision 60021) 401+++ Makefile.shared (working copy) 402@@ -1,3 +1,4 @@ 403+ 404SCRIPTS_PATH ?= ../WebKitTools/Scripts 405XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 406END 407), 408 expectedReturn => [ 409[{ 410 executableBitDelta => -1, 411 indexPath => "Makefile", 412 isSvn => 1, 413}], 414"Index: Makefile.shared\r\n"], 415 expectedNextLine => "===================================================================\r\n", 416}, 417{ 418 # New test 419 diffName => "SVN: copied file with property change", 420 inputText => <<'END', 421Index: NMakefile 422=================================================================== 423--- NMakefile (revision 60021) (from Makefile:60021) 424+++ NMakefile (working copy) 425@@ -0,0 +1,1 @@ 426+MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 427 428Property changes on: NMakefile 429___________________________________________________________________ 430Added: svn:executable 431 + * 432END 433 expectedReturn => [ 434[{ 435 copiedFromPath => "Makefile", 436 executableBitDelta => 1, 437 indexPath => "NMakefile", 438 sourceRevision => "60021", 439}], 440undef], 441 expectedNextLine => undef, 442}, 443{ 444 # New test 445 diffName => "SVN: two consecutive property diffs", 446 inputText => <<'END', 447Property changes on: Makefile 448___________________________________________________________________ 449Added: svn:executable 450 + * 451 452 453Property changes on: Makefile.shared 454___________________________________________________________________ 455Added: svn:executable 456 + * 457END 458 expectedReturn => [ 459[{ 460 executableBitDelta => 1, 461 indexPath => "Makefile", 462 isSvn => 1, 463}], 464"Property changes on: Makefile.shared\n"], 465 expectedNextLine => "___________________________________________________________________\n", 466}, 467{ 468 # New test 469 diffName => "SVN: two consecutive property diffs using Windows line endings", 470 inputText => toWindowsLineEndings(<<'END', 471Property changes on: Makefile 472___________________________________________________________________ 473Added: svn:executable 474 + * 475 476 477Property changes on: Makefile.shared 478___________________________________________________________________ 479Added: svn:executable 480 + * 481END 482), 483 expectedReturn => [ 484[{ 485 executableBitDelta => 1, 486 indexPath => "Makefile", 487 isSvn => 1, 488}], 489"Property changes on: Makefile.shared\r\n"], 490 expectedNextLine => "___________________________________________________________________\r\n", 491}, 492#### 493# Property Changes: Binary files 494## 495{ 496 # New test 497 diffName => "SVN: binary file with executable bit change", 498 inputText => <<'END', 499Index: test_file.swf 500=================================================================== 501Cannot display: file marked as a binary type. 502svn:mime-type = application/octet-stream 503 504Property changes on: test_file.swf 505___________________________________________________________________ 506Name: svn:mime-type 507 + application/octet-stream 508Name: svn:executable 509 + * 510 511 512Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 513END 514 expectedReturn => [ 515[{ 516 svnConvertedText => <<'END', # Same as input text 517Index: test_file.swf 518=================================================================== 519Cannot display: file marked as a binary type. 520svn:mime-type = application/octet-stream 521 522 523 524Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 525END 526 executableBitDelta => 1, 527 indexPath => "test_file.swf", 528 isBinary => 1, 529 isSvn => 1, 530}], 531undef], 532 expectedNextLine => undef, 533}, 534{ 535 # New test 536 diffName => "SVN: binary file with executable bit change usng Windows line endings", 537 inputText => toWindowsLineEndings(<<'END', 538Index: test_file.swf 539=================================================================== 540Cannot display: file marked as a binary type. 541svn:mime-type = application/octet-stream 542 543Property changes on: test_file.swf 544___________________________________________________________________ 545Name: svn:mime-type 546 + application/octet-stream 547Name: svn:executable 548 + * 549 550 551Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 552END 553), 554 expectedReturn => [ 555[{ 556 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 557Index: test_file.swf 558=================================================================== 559Cannot display: file marked as a binary type. 560svn:mime-type = application/octet-stream 561 562 563 564Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 565END 566), 567 executableBitDelta => 1, 568 indexPath => "test_file.swf", 569 isBinary => 1, 570 isSvn => 1, 571}], 572undef], 573 expectedNextLine => undef, 574}, 575{ 576 # New test 577 diffName => "SVN: binary file followed by property change on different file", 578 inputText => <<'END', 579Index: test_file.swf 580=================================================================== 581Cannot display: file marked as a binary type. 582svn:mime-type = application/octet-stream 583 584Property changes on: test_file.swf 585___________________________________________________________________ 586Name: svn:mime-type 587 + application/octet-stream 588 589 590Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 591 592Property changes on: Makefile 593___________________________________________________________________ 594Added: svn:executable 595 + * 596END 597 expectedReturn => [ 598[{ 599 svnConvertedText => <<'END', # Same as input text 600Index: test_file.swf 601=================================================================== 602Cannot display: file marked as a binary type. 603svn:mime-type = application/octet-stream 604 605 606 607Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 608 609END 610 indexPath => "test_file.swf", 611 isBinary => 1, 612 isSvn => 1, 613}], 614"Property changes on: Makefile\n"], 615 expectedNextLine => "___________________________________________________________________\n", 616}, 617{ 618 # New test 619 diffName => "SVN: binary file followed by property change on different file using Windows line endings", 620 inputText => toWindowsLineEndings(<<'END', 621Index: test_file.swf 622=================================================================== 623Cannot display: file marked as a binary type. 624svn:mime-type = application/octet-stream 625 626Property changes on: test_file.swf 627___________________________________________________________________ 628Name: svn:mime-type 629 + application/octet-stream 630 631 632Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 633 634Property changes on: Makefile 635___________________________________________________________________ 636Added: svn:executable 637 + * 638END 639), 640 expectedReturn => [ 641[{ 642 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 643Index: test_file.swf 644=================================================================== 645Cannot display: file marked as a binary type. 646svn:mime-type = application/octet-stream 647 648 649 650Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 651 652END 653), 654 indexPath => "test_file.swf", 655 isBinary => 1, 656 isSvn => 1, 657}], 658"Property changes on: Makefile\r\n"], 659 expectedNextLine => "___________________________________________________________________\r\n", 660}, 661{ 662 # New test 663 diffName => "SVN: binary file followed by file change on different file", 664 inputText => <<'END', 665Index: test_file.swf 666=================================================================== 667Cannot display: file marked as a binary type. 668svn:mime-type = application/octet-stream 669 670Property changes on: test_file.swf 671___________________________________________________________________ 672Name: svn:mime-type 673 + application/octet-stream 674 675 676Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 677 678Index: Makefile 679=================================================================== 680--- Makefile (revision 60021) 681+++ Makefile (working copy) 682@@ -1,3 +1,4 @@ 683+ 684 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 685 686 all: 687END 688 expectedReturn => [ 689[{ 690 svnConvertedText => <<'END', # Same as input text 691Index: test_file.swf 692=================================================================== 693Cannot display: file marked as a binary type. 694svn:mime-type = application/octet-stream 695 696 697 698Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 699 700END 701 indexPath => "test_file.swf", 702 isBinary => 1, 703 isSvn => 1, 704}], 705"Index: Makefile\n"], 706 expectedNextLine => "===================================================================\n", 707}, 708{ 709 # New test 710 diffName => "SVN: binary file followed by file change on different file using Windows line endings", 711 inputText => toWindowsLineEndings(<<'END', 712Index: test_file.swf 713=================================================================== 714Cannot display: file marked as a binary type. 715svn:mime-type = application/octet-stream 716 717Property changes on: test_file.swf 718___________________________________________________________________ 719Name: svn:mime-type 720 + application/octet-stream 721 722 723Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 724 725Index: Makefile 726=================================================================== 727--- Makefile (revision 60021) 728+++ Makefile (working copy) 729@@ -1,3 +1,4 @@ 730+ 731 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 732 733 all: 734END 735), 736 expectedReturn => [ 737[{ 738 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 739Index: test_file.swf 740=================================================================== 741Cannot display: file marked as a binary type. 742svn:mime-type = application/octet-stream 743 744 745 746Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 747 748END 749), 750 indexPath => "test_file.swf", 751 isBinary => 1, 752 isSvn => 1, 753}], 754"Index: Makefile\r\n"], 755 expectedNextLine => "===================================================================\r\n", 756}, 757#### 758# Property Changes: File change with property change 759## 760{ 761 # New test 762 diffName => "SVN: file change diff with property change, followed by property change diff", 763 inputText => <<'END', 764Index: Makefile 765=================================================================== 766--- Makefile (revision 60021) 767+++ Makefile (working copy) 768@@ -1,3 +1,4 @@ 769+ 770 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 771 772 all: 773 774Property changes on: Makefile 775___________________________________________________________________ 776Added: svn:executable 777 + * 778 779 780Property changes on: Makefile.shared 781___________________________________________________________________ 782Deleted: svn:executable 783 - * 784END 785 expectedReturn => [ 786[{ 787 svnConvertedText => <<'END', # Same as input text 788Index: Makefile 789=================================================================== 790--- Makefile (revision 60021) 791+++ Makefile (working copy) 792@@ -1,3 +1,4 @@ 793+ 794 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 795 796 all: 797 798 799 800END 801 executableBitDelta => 1, 802 indexPath => "Makefile", 803 isSvn => 1, 804 numTextChunks => 1, 805 sourceRevision => "60021", 806}], 807"Property changes on: Makefile.shared\n"], 808 expectedNextLine => "___________________________________________________________________\n", 809}, 810{ 811 # New test 812 diffName => "SVN: file change diff with property change, followed by property change diff using Windows line endings", 813 inputText => toWindowsLineEndings(<<'END', 814Index: Makefile 815=================================================================== 816--- Makefile (revision 60021) 817+++ Makefile (working copy) 818@@ -1,3 +1,4 @@ 819+ 820 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 821 822 all: 823 824Property changes on: Makefile 825___________________________________________________________________ 826Added: svn:executable 827 + * 828 829 830Property changes on: Makefile.shared 831___________________________________________________________________ 832Deleted: svn:executable 833 - * 834END 835), 836 expectedReturn => [ 837[{ 838 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 839Index: Makefile 840=================================================================== 841--- Makefile (revision 60021) 842+++ Makefile (working copy) 843@@ -1,3 +1,4 @@ 844+ 845 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 846 847 all: 848 849 850 851END 852), 853 executableBitDelta => 1, 854 indexPath => "Makefile", 855 isSvn => 1, 856 numTextChunks => 1, 857 sourceRevision => "60021", 858}], 859"Property changes on: Makefile.shared\r\n"], 860 expectedNextLine => "___________________________________________________________________\r\n", 861}, 862{ 863 # New test 864 diffName => "SVN: file change diff with property change, followed by file change diff", 865 inputText => <<'END', 866Index: Makefile 867=================================================================== 868--- Makefile (revision 60021) 869+++ Makefile (working copy) 870@@ -1,3 +1,4 @@ 871+ 872 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 873 874 all: 875 876Property changes on: Makefile 877___________________________________________________________________ 878Name: svn:executable 879 - * 880 881Index: Makefile.shared 882=================================================================== 883--- Makefile.shared (revision 60021) 884+++ Makefile.shared (working copy) 885@@ -1,3 +1,4 @@ 886+ 887SCRIPTS_PATH ?= ../WebKitTools/Scripts 888XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 889END 890 expectedReturn => [ 891[{ 892 svnConvertedText => <<'END', # Same as input text 893Index: Makefile 894=================================================================== 895--- Makefile (revision 60021) 896+++ Makefile (working copy) 897@@ -1,3 +1,4 @@ 898+ 899 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 900 901 all: 902 903 904END 905 executableBitDelta => -1, 906 indexPath => "Makefile", 907 isSvn => 1, 908 numTextChunks => 1, 909 sourceRevision => "60021", 910}], 911"Index: Makefile.shared\n"], 912 expectedNextLine => "===================================================================\n", 913}, 914{ 915 # New test 916 diffName => "SVN: file change diff with property change, followed by file change diff using Windows line endings", 917 inputText => toWindowsLineEndings(<<'END', 918Index: Makefile 919=================================================================== 920--- Makefile (revision 60021) 921+++ Makefile (working copy) 922@@ -1,3 +1,4 @@ 923+ 924 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 925 926 all: 927 928Property changes on: Makefile 929___________________________________________________________________ 930Name: svn:executable 931 - * 932 933Index: Makefile.shared 934=================================================================== 935--- Makefile.shared (revision 60021) 936+++ Makefile.shared (working copy) 937@@ -1,3 +1,4 @@ 938+ 939SCRIPTS_PATH ?= ../WebKitTools/Scripts 940XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 941END 942), 943 expectedReturn => [ 944[{ 945 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 946Index: Makefile 947=================================================================== 948--- Makefile (revision 60021) 949+++ Makefile (working copy) 950@@ -1,3 +1,4 @@ 951+ 952 MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKit2 WebKitTools 953 954 all: 955 956 957END 958), 959 executableBitDelta => -1, 960 indexPath => "Makefile", 961 isSvn => 1, 962 numTextChunks => 1, 963 sourceRevision => "60021", 964}], 965"Index: Makefile.shared\r\n"], 966 expectedNextLine => "===================================================================\r\n", 967}, 968#### 969# Git test cases 970## 971{ 972 # New test 973 diffName => "Git: simple", 974 inputText => <<'END', 975diff --git a/Makefile b/Makefile 976index f5d5e74..3b6aa92 100644 977--- a/Makefile 978+++ b/Makefile 979@@ -1,1 +1,1 @@ public: 980END 981 expectedReturn => [ 982[{ 983 svnConvertedText => <<'END', 984Index: Makefile 985index f5d5e74..3b6aa92 100644 986--- Makefile 987+++ Makefile 988@@ -1,1 +1,1 @@ public: 989END 990 indexPath => "Makefile", 991 isGit => 1, 992 numTextChunks => 1, 993}], 994undef], 995 expectedNextLine => undef, 996}, 997{ 998 # New test 999 diffName => "Git: Append new line to the end of an existing file", 1000 inputText => <<'END', 1001diff --git a/foo b/foo 1002index 863339f..db418b2 100644 1003--- a/foo 1004+++ b/foo 1005@@ -1 +1,2 @@ 1006 Passed 1007+ 1008END 1009 expectedReturn => [ 1010[{ 1011 svnConvertedText => <<'END', 1012Index: foo 1013index 863339f..db418b2 100644 1014--- foo 1015+++ foo 1016@@ -1 +1,2 @@ 1017 Passed 1018+ 1019END 1020 indexPath => "foo", 1021 isGit => 1, 1022 numTextChunks => 1, 1023}], 1024undef], 1025 expectedNextLine => undef, 1026}, 1027{ # New test 1028 diffName => "Git: new file", 1029 inputText => <<'END', 1030diff --git a/foo.h b/foo.h 1031new file mode 100644 1032index 0000000..3c9f114 1033--- /dev/null 1034+++ b/foo.h 1035@@ -0,0 +1,34 @@ 1036+<html> 1037diff --git a/bar b/bar 1038index d45dd40..3494526 100644 1039END 1040 expectedReturn => [ 1041[{ 1042 svnConvertedText => <<'END', 1043Index: foo.h 1044new file mode 100644 1045index 0000000..3c9f114 1046--- foo.h 1047+++ foo.h 1048@@ -0,0 +1,34 @@ 1049+<html> 1050END 1051 indexPath => "foo.h", 1052 isGit => 1, 1053 isNew => 1, 1054 numTextChunks => 1, 1055}], 1056"diff --git a/bar b/bar\n"], 1057 expectedNextLine => "index d45dd40..3494526 100644\n", 1058}, 1059{ # New test 1060 diffName => "Git: file deletion", 1061 inputText => <<'END', 1062diff --git a/foo b/foo 1063deleted file mode 100644 1064index 1e50d1d..0000000 1065--- a/foo 1066+++ /dev/null 1067@@ -1,1 +0,0 @@ 1068-line1 1069diff --git a/bar b/bar 1070index d45dd40..3494526 100644 1071END 1072 expectedReturn => [ 1073[{ 1074 svnConvertedText => <<'END', 1075Index: foo 1076deleted file mode 100644 1077index 1e50d1d..0000000 1078--- foo 1079+++ foo 1080@@ -1,1 +0,0 @@ 1081-line1 1082END 1083 indexPath => "foo", 1084 isDeletion => 1, 1085 isGit => 1, 1086 numTextChunks => 1, 1087}], 1088"diff --git a/bar b/bar\n"], 1089 expectedNextLine => "index d45dd40..3494526 100644\n", 1090}, 1091{ 1092 # New test 1093 diffName => "Git: Git diff followed by SVN diff", # Should not recognize SVN start 1094 inputText => <<'END', 1095diff --git a/Makefile b/Makefile 1096index f5d5e74..3b6aa92 100644 1097--- a/Makefile 1098+++ b/Makefile 1099@@ -1,1 +1,1 @@ public: 1100Index: Makefile_new 1101=================================================================== 1102--- Makefile_new (revision 53131) (from Makefile:53131) 1103END 1104 expectedReturn => [ 1105[{ 1106 svnConvertedText => <<'END', 1107Index: Makefile 1108index f5d5e74..3b6aa92 100644 1109--- Makefile 1110+++ Makefile 1111@@ -1,1 +1,1 @@ public: 1112Index: Makefile_new 1113=================================================================== 1114--- Makefile_new (revision 53131) (from Makefile:53131) 1115END 1116 indexPath => "Makefile", 1117 isGit => 1, 1118 numTextChunks => 1, 1119}], 1120undef], 1121 expectedNextLine => undef, 1122}, 1123{ 1124 # New test 1125 diffName => "Git: file that only has an executable bit change", 1126 inputText => <<'END', 1127diff --git a/foo b/foo 1128old mode 100644 1129new mode 100755 1130END 1131 expectedReturn => [ 1132[{ 1133 svnConvertedText => <<'END', 1134Index: foo 1135old mode 100644 1136new mode 100755 1137END 1138 executableBitDelta => 1, 1139 indexPath => "foo", 1140 isGit => 1, 1141 numTextChunks => 0, 1142}], 1143undef], 1144 expectedNextLine => undef, 1145}, 1146#### 1147# Git test cases: file moves (multiple return values) 1148## 1149{ 1150 diffName => "Git: rename (with similarity index 100%)", 1151 inputText => <<'END', 1152diff --git a/foo b/foo_new 1153similarity index 100% 1154rename from foo 1155rename to foo_new 1156diff --git a/bar b/bar 1157index d45dd40..3494526 100644 1158END 1159 expectedReturn => [ 1160[{ 1161 indexPath => "foo", 1162 isDeletion => 1, 1163}, 1164{ 1165 copiedFromPath => "foo", 1166 indexPath => "foo_new", 1167}], 1168"diff --git a/bar b/bar\n"], 1169 expectedNextLine => "index d45dd40..3494526 100644\n", 1170}, 1171{ 1172 diffName => "rename (with similarity index < 100%)", 1173 inputText => <<'END', 1174diff --git a/foo b/foo_new 1175similarity index 99% 1176rename from foo 1177rename to foo_new 1178index 1e50d1d..1459d21 100644 1179--- a/foo 1180+++ b/foo_new 1181@@ -15,3 +15,4 @@ release r deployment dep deploy: 1182 line1 1183 line2 1184 line3 1185+line4 1186diff --git a/bar b/bar 1187index d45dd40..3494526 100644 1188END 1189 expectedReturn => [ 1190[{ 1191 indexPath => "foo", 1192 isDeletion => 1, 1193}, 1194{ 1195 copiedFromPath => "foo", 1196 indexPath => "foo_new", 1197}, 1198{ 1199 indexPath => "foo_new", 1200 isGit => 1, 1201 numTextChunks => 1, 1202 svnConvertedText => <<'END', 1203Index: foo_new 1204similarity index 99% 1205rename from foo 1206rename to foo_new 1207index 1e50d1d..1459d21 100644 1208--- foo_new 1209+++ foo_new 1210@@ -15,3 +15,4 @@ release r deployment dep deploy: 1211 line1 1212 line2 1213 line3 1214+line4 1215END 1216}], 1217"diff --git a/bar b/bar\n"], 1218 expectedNextLine => "index d45dd40..3494526 100644\n", 1219}, 1220{ 1221 diffName => "rename (with executable bit change)", 1222 inputText => <<'END', 1223diff --git a/foo b/foo_new 1224old mode 100644 1225new mode 100755 1226similarity index 100% 1227rename from foo 1228rename to foo_new 1229diff --git a/bar b/bar 1230index d45dd40..3494526 100644 1231END 1232 expectedReturn => [ 1233[{ 1234 indexPath => "foo", 1235 isDeletion => 1, 1236}, 1237{ 1238 copiedFromPath => "foo", 1239 indexPath => "foo_new", 1240}, 1241{ 1242 executableBitDelta => 1, 1243 indexPath => "foo_new", 1244 isGit => 1, 1245 numTextChunks => 0, 1246 svnConvertedText => <<'END', 1247Index: foo_new 1248old mode 100644 1249new mode 100755 1250similarity index 100% 1251rename from foo 1252rename to foo_new 1253END 1254}], 1255"diff --git a/bar b/bar\n"], 1256 expectedNextLine => "index d45dd40..3494526 100644\n", 1257}, 1258); 1259 1260my $testCasesCount = @testCaseHashRefs; 1261plan(tests => 2 * $testCasesCount); # Total number of assertions. 1262 1263foreach my $testCase (@testCaseHashRefs) { 1264 my $testNameStart = "parseDiff(): $testCase->{diffName}: comparing"; 1265 1266 my $fileHandle; 1267 open($fileHandle, "<", \$testCase->{inputText}); 1268 my $line = <$fileHandle>; 1269 1270 my @got = VCSUtils::parseDiff($fileHandle, $line, {"shouldNotUseIndexPathEOL" => 1}); 1271 my $expectedReturn = $testCase->{expectedReturn}; 1272 1273 is_deeply(\@got, $expectedReturn, "$testNameStart return value."); 1274 1275 my $gotNextLine = <$fileHandle>; 1276 is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line."); 1277} 1278