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