1 #!/usr/bin/perl -w 2 # 3 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek (at] 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: binary file (isBinary true) using Windows line endings", 108 inputText => toWindowsLineEndings(<<'END', 109 Index: test_file.swf 110 =================================================================== 111 Cannot display: file marked as a binary type. 112 svn:mime-type = application/octet-stream 113 114 Property changes on: test_file.swf 115 ___________________________________________________________________ 116 Name: svn:mime-type 117 + application/octet-stream 118 119 120 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 121 END 122 ), 123 expectedReturn => [ 124 [{ 125 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 126 Index: test_file.swf 127 =================================================================== 128 Cannot display: file marked as a binary type. 129 svn:mime-type = application/octet-stream 130 131 132 133 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 134 END 135 ), 136 indexPath => "test_file.swf", 137 isBinary => 1, 138 isSvn => 1, 139 }], 140 undef], 141 expectedNextLine => undef, 142 }, 143 { 144 # New test 145 diffName => "SVN: leading junk", 146 inputText => <<'END', 147 148 LEADING JUNK 149 150 Index: 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: 159 END 160 expectedReturn => [ 161 [{ 162 svnConvertedText => <<'END', # Same as input text 163 164 LEADING JUNK 165 166 Index: 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: 175 END 176 indexPath => "Makefile", 177 isSvn => 1, 178 sourceRevision => "53052", 179 }], 180 undef], 181 expectedNextLine => undef, 182 }, 183 { 184 # New test 185 diffName => "SVN: copied file", 186 inputText => <<'END', 187 Index: 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 193 END 194 expectedReturn => [ 195 [{ 196 copiedFromPath => "Makefile", 197 indexPath => "Makefile_new", 198 sourceRevision => "53131", 199 }], 200 undef], 201 expectedNextLine => undef, 202 }, 203 { 204 # New test 205 diffName => "SVN: two diffs", 206 inputText => <<'END', 207 Index: Makefile 208 =================================================================== 209 --- Makefile (revision 53131) 210 +++ Makefile (working copy) 211 @@ -1,1 +0,0 @@ 212 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 213 Index: Makefile_new 214 =================================================================== 215 --- Makefile_new (revision 53131) (from Makefile:53131) 216 END 217 expectedReturn => [ 218 [{ 219 svnConvertedText => <<'END', 220 Index: Makefile 221 =================================================================== 222 --- Makefile (revision 53131) 223 +++ Makefile (working copy) 224 @@ -1,1 +0,0 @@ 225 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 226 END 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', 238 Index: Makefile 239 =================================================================== 240 --- Makefile (revision 53131) 241 +++ Makefile (working copy) 242 @@ -1,1 +0,0 @@ 243 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 244 diff --git a/Makefile b/Makefile 245 index f5d5e74..3b6aa92 100644 246 --- a/Makefile 247 +++ b/Makefile 248 @@ -1,1 1,1 @@ public: 249 END 250 expectedReturn => [ 251 [{ 252 svnConvertedText => <<'END', # Same as input text 253 Index: Makefile 254 =================================================================== 255 --- Makefile (revision 53131) 256 +++ Makefile (working copy) 257 @@ -1,1 +0,0 @@ 258 -MODULES = JavaScriptCore JavaScriptGlue WebCore WebKit WebKitTools 259 diff --git a/Makefile b/Makefile 260 index f5d5e74..3b6aa92 100644 261 --- a/Makefile 262 +++ b/Makefile 263 @@ -1,1 1,1 @@ public: 264 END 265 indexPath => "Makefile", 266 isSvn => 1, 267 sourceRevision => "53131", 268 }], 269 undef], 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', 279 Index: 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 289 Property changes on: Makefile 290 ___________________________________________________________________ 291 Name: svn:executable 292 + * 293 END 294 expectedReturn => [ 295 [{ 296 svnConvertedText => <<'END', # Same as input text 297 Index: 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 307 END 308 executableBitDelta => 1, 309 indexPath => "Makefile", 310 isSvn => 1, 311 sourceRevision => "60021", 312 }], 313 undef], 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', 320 Index: 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 330 Property changes on: Makefile.shared 331 ___________________________________________________________________ 332 Name: svn:executable 333 + * 334 END 335 expectedReturn => [ 336 [{ 337 svnConvertedText => <<'END', # Same as input text 338 Index: 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 348 END 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', 360 Property changes on: Makefile 361 ___________________________________________________________________ 362 Deleted: svn:executable 363 - * 364 365 Index: Makefile.shared 366 =================================================================== 367 --- Makefile.shared (revision 60021) 368 +++ Makefile.shared (working copy) 369 @@ -1,3 +1,4 @@ 370 + 371 SCRIPTS_PATH ?= ../WebKitTools/Scripts 372 XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 373 END 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', 387 Property changes on: Makefile 388 ___________________________________________________________________ 389 Deleted: svn:executable 390 - * 391 392 Index: Makefile.shared 393 =================================================================== 394 --- Makefile.shared (revision 60021) 395 +++ Makefile.shared (working copy) 396 @@ -1,3 +1,4 @@ 397 + 398 SCRIPTS_PATH ?= ../WebKitTools/Scripts 399 XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 400 END 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', 415 Index: 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 422 Property changes on: NMakefile 423 ___________________________________________________________________ 424 Added: svn:executable 425 + * 426 END 427 expectedReturn => [ 428 [{ 429 copiedFromPath => "Makefile", 430 executableBitDelta => 1, 431 indexPath => "NMakefile", 432 sourceRevision => "60021", 433 }], 434 undef], 435 expectedNextLine => undef, 436 }, 437 { 438 # New test 439 diffName => "SVN: two consecutive property diffs", 440 inputText => <<'END', 441 Property changes on: Makefile 442 ___________________________________________________________________ 443 Added: svn:executable 444 + * 445 446 447 Property changes on: Makefile.shared 448 ___________________________________________________________________ 449 Added: svn:executable 450 + * 451 END 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', 465 Property changes on: Makefile 466 ___________________________________________________________________ 467 Added: svn:executable 468 + * 469 470 471 Property changes on: Makefile.shared 472 ___________________________________________________________________ 473 Added: svn:executable 474 + * 475 END 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', 493 Index: test_file.swf 494 =================================================================== 495 Cannot display: file marked as a binary type. 496 svn:mime-type = application/octet-stream 497 498 Property changes on: test_file.swf 499 ___________________________________________________________________ 500 Name: svn:mime-type 501 + application/octet-stream 502 Name: svn:executable 503 + * 504 505 506 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 507 END 508 expectedReturn => [ 509 [{ 510 svnConvertedText => <<'END', # Same as input text 511 Index: test_file.swf 512 =================================================================== 513 Cannot display: file marked as a binary type. 514 svn:mime-type = application/octet-stream 515 516 517 518 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 519 END 520 executableBitDelta => 1, 521 indexPath => "test_file.swf", 522 isBinary => 1, 523 isSvn => 1, 524 }], 525 undef], 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', 532 Index: test_file.swf 533 =================================================================== 534 Cannot display: file marked as a binary type. 535 svn:mime-type = application/octet-stream 536 537 Property changes on: test_file.swf 538 ___________________________________________________________________ 539 Name: svn:mime-type 540 + application/octet-stream 541 Name: svn:executable 542 + * 543 544 545 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 546 END 547 ), 548 expectedReturn => [ 549 [{ 550 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 551 Index: test_file.swf 552 =================================================================== 553 Cannot display: file marked as a binary type. 554 svn:mime-type = application/octet-stream 555 556 557 558 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 559 END 560 ), 561 executableBitDelta => 1, 562 indexPath => "test_file.swf", 563 isBinary => 1, 564 isSvn => 1, 565 }], 566 undef], 567 expectedNextLine => undef, 568 }, 569 { 570 # New test 571 diffName => "SVN: binary file followed by property change on different file", 572 inputText => <<'END', 573 Index: test_file.swf 574 =================================================================== 575 Cannot display: file marked as a binary type. 576 svn:mime-type = application/octet-stream 577 578 Property changes on: test_file.swf 579 ___________________________________________________________________ 580 Name: svn:mime-type 581 + application/octet-stream 582 583 584 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 585 586 Property changes on: Makefile 587 ___________________________________________________________________ 588 Added: svn:executable 589 + * 590 END 591 expectedReturn => [ 592 [{ 593 svnConvertedText => <<'END', # Same as input text 594 Index: test_file.swf 595 =================================================================== 596 Cannot display: file marked as a binary type. 597 svn:mime-type = application/octet-stream 598 599 600 601 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 602 603 END 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', 615 Index: test_file.swf 616 =================================================================== 617 Cannot display: file marked as a binary type. 618 svn:mime-type = application/octet-stream 619 620 Property changes on: test_file.swf 621 ___________________________________________________________________ 622 Name: svn:mime-type 623 + application/octet-stream 624 625 626 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 627 628 Property changes on: Makefile 629 ___________________________________________________________________ 630 Added: svn:executable 631 + * 632 END 633 ), 634 expectedReturn => [ 635 [{ 636 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 637 Index: test_file.swf 638 =================================================================== 639 Cannot display: file marked as a binary type. 640 svn:mime-type = application/octet-stream 641 642 643 644 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 645 646 END 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', 659 Index: test_file.swf 660 =================================================================== 661 Cannot display: file marked as a binary type. 662 svn:mime-type = application/octet-stream 663 664 Property changes on: test_file.swf 665 ___________________________________________________________________ 666 Name: svn:mime-type 667 + application/octet-stream 668 669 670 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 671 672 Index: 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: 681 END 682 expectedReturn => [ 683 [{ 684 svnConvertedText => <<'END', # Same as input text 685 Index: test_file.swf 686 =================================================================== 687 Cannot display: file marked as a binary type. 688 svn:mime-type = application/octet-stream 689 690 691 692 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 693 694 END 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', 706 Index: test_file.swf 707 =================================================================== 708 Cannot display: file marked as a binary type. 709 svn:mime-type = application/octet-stream 710 711 Property changes on: test_file.swf 712 ___________________________________________________________________ 713 Name: svn:mime-type 714 + application/octet-stream 715 716 717 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 718 719 Index: 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: 728 END 729 ), 730 expectedReturn => [ 731 [{ 732 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 733 Index: test_file.swf 734 =================================================================== 735 Cannot display: file marked as a binary type. 736 svn:mime-type = application/octet-stream 737 738 739 740 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 741 742 END 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', 758 Index: 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 768 Property changes on: Makefile 769 ___________________________________________________________________ 770 Added: svn:executable 771 + * 772 773 774 Property changes on: Makefile.shared 775 ___________________________________________________________________ 776 Deleted: svn:executable 777 - * 778 END 779 expectedReturn => [ 780 [{ 781 svnConvertedText => <<'END', # Same as input text 782 Index: 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 794 END 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', 807 Index: 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 817 Property changes on: Makefile 818 ___________________________________________________________________ 819 Added: svn:executable 820 + * 821 822 823 Property changes on: Makefile.shared 824 ___________________________________________________________________ 825 Deleted: svn:executable 826 - * 827 END 828 ), 829 expectedReturn => [ 830 [{ 831 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 832 Index: 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 844 END 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', 858 Index: 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 868 Property changes on: Makefile 869 ___________________________________________________________________ 870 Name: svn:executable 871 - * 872 873 Index: Makefile.shared 874 =================================================================== 875 --- Makefile.shared (revision 60021) 876 +++ Makefile.shared (working copy) 877 @@ -1,3 +1,4 @@ 878 + 879 SCRIPTS_PATH ?= ../WebKitTools/Scripts 880 XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 881 END 882 expectedReturn => [ 883 [{ 884 svnConvertedText => <<'END', # Same as input text 885 Index: 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 896 END 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', 909 Index: 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 919 Property changes on: Makefile 920 ___________________________________________________________________ 921 Name: svn:executable 922 - * 923 924 Index: Makefile.shared 925 =================================================================== 926 --- Makefile.shared (revision 60021) 927 +++ Makefile.shared (working copy) 928 @@ -1,3 +1,4 @@ 929 + 930 SCRIPTS_PATH ?= ../WebKitTools/Scripts 931 XCODE_OPTIONS = `perl -I$(SCRIPTS_PATH) -Mwebkitdirs -e 'print XcodeOptionString()'` $(ARGS) 932 END 933 ), 934 expectedReturn => [ 935 [{ 936 svnConvertedText => toWindowsLineEndings(<<'END', # Same as input text 937 Index: 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 948 END 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', 965 diff --git a/Makefile b/Makefile 966 index f5d5e74..3b6aa92 100644 967 --- a/Makefile 968 +++ b/Makefile 969 @@ -1,1 1,1 @@ public: 970 END 971 expectedReturn => [ 972 [{ 973 svnConvertedText => <<'END', 974 Index: Makefile 975 index f5d5e74..3b6aa92 100644 976 --- Makefile 977 +++ Makefile 978 @@ -1,1 1,1 @@ public: 979 END 980 indexPath => "Makefile", 981 isGit => 1, 982 }], 983 undef], 984 expectedNextLine => undef, 985 }, 986 { # New test 987 diffName => "Git: new file", 988 inputText => <<'END', 989 diff --git a/foo.h b/foo.h 990 new file mode 100644 991 index 0000000..3c9f114 992 --- /dev/null 993 +++ b/foo.h 994 @@ -0,0 +1,34 @@ 995 +<html> 996 diff --git a/bar b/bar 997 index d45dd40..3494526 100644 998 END 999 expectedReturn => [ 1000 [{ 1001 svnConvertedText => <<'END', 1002 Index: foo.h 1003 new file mode 100644 1004 index 0000000..3c9f114 1005 --- foo.h 1006 +++ foo.h 1007 @@ -0,0 +1,34 @@ 1008 +<html> 1009 END 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', 1020 diff --git a/foo b/foo 1021 deleted file mode 100644 1022 index 1e50d1d..0000000 1023 --- a/foo 1024 +++ /dev/null 1025 @@ -1,1 +0,0 @@ 1026 -line1 1027 diff --git a/bar b/bar 1028 index d45dd40..3494526 100644 1029 END 1030 expectedReturn => [ 1031 [{ 1032 svnConvertedText => <<'END', 1033 Index: foo 1034 deleted file mode 100644 1035 index 1e50d1d..0000000 1036 --- foo 1037 +++ foo 1038 @@ -1,1 +0,0 @@ 1039 -line1 1040 END 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', 1052 diff --git a/Makefile b/Makefile 1053 index f5d5e74..3b6aa92 100644 1054 --- a/Makefile 1055 +++ b/Makefile 1056 @@ -1,1 1,1 @@ public: 1057 Index: Makefile_new 1058 =================================================================== 1059 --- Makefile_new (revision 53131) (from Makefile:53131) 1060 END 1061 expectedReturn => [ 1062 [{ 1063 svnConvertedText => <<'END', 1064 Index: Makefile 1065 index f5d5e74..3b6aa92 100644 1066 --- Makefile 1067 +++ Makefile 1068 @@ -1,1 1,1 @@ public: 1069 Index: Makefile_new 1070 =================================================================== 1071 --- Makefile_new (revision 53131) (from Makefile:53131) 1072 END 1073 indexPath => "Makefile", 1074 isGit => 1, 1075 }], 1076 undef], 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', 1085 diff --git a/foo b/foo_new 1086 similarity index 100% 1087 rename from foo 1088 rename to foo_new 1089 diff --git a/bar b/bar 1090 index d45dd40..3494526 100644 1091 END 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', 1107 diff --git a/foo b/foo_new 1108 similarity index 99% 1109 rename from foo 1110 rename to foo_new 1111 index 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 1119 diff --git a/bar b/bar 1120 index d45dd40..3494526 100644 1121 END 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', 1135 Index: foo_new 1136 similarity index 99% 1137 rename from foo 1138 rename to foo_new 1139 index 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 1147 END 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', 1155 diff --git a/foo b/foo_new 1156 old mode 100644 1157 new mode 100755 1158 similarity index 100% 1159 rename from foo 1160 rename to foo_new 1161 diff --git a/bar b/bar 1162 index d45dd40..3494526 100644 1163 END 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', 1178 Index: foo_new 1179 old mode 100644 1180 new mode 100755 1181 similarity index 100% 1182 rename from foo 1183 rename to foo_new 1184 END 1185 }], 1186 "diff --git a/bar b/bar\n"], 1187 expectedNextLine => "index d45dd40..3494526 100644\n", 1188 }, 1189 ); 1190 1191 my $testCasesCount = @testCaseHashRefs; 1192 plan(tests => 2 * $testCasesCount); # Total number of assertions. 1193 1194 foreach 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