WebKitTools/Scripts/webkitperl/VCSUtils_unittest/fixChangeLogPatch.pl
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 #!/usr/bin/perl
       
     2 #
       
     3 # Copyright (C) 2009, 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 are
       
     7 # met:
       
     8 # 
       
     9 #     * Redistributions of source code must retain the above copyright
       
    10 # notice, this list of conditions and the following disclaimer.
       
    11 #     * Redistributions in binary form must reproduce the above
       
    12 # copyright notice, this list of conditions and the following disclaimer
       
    13 # in the documentation and/or other materials provided with the
       
    14 # distribution.
       
    15 #     * Neither the name of Google Inc. nor the names of its
       
    16 # contributors may be used to endorse or promote products derived from
       
    17 # this software without specific prior written permission.
       
    18 # 
       
    19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    30 
       
    31 # Unit tests of VCSUtils::fixChangeLogPatch().
       
    32 
       
    33 use Test::Simple tests => 8;
       
    34 use VCSUtils;
       
    35 
       
    36 # The source ChangeLog for these tests is the following:
       
    37 # 
       
    38 # 2009-12-22  Alice  <alice@email.address>
       
    39 # 
       
    40 #         Reviewed by Ray.
       
    41 # 
       
    42 #         Changed some code on 2009-12-22.
       
    43 # 
       
    44 #         * File:
       
    45 #         * File2:
       
    46 # 
       
    47 # 2009-12-21  Alice  <alice@email.address>
       
    48 # 
       
    49 #         Reviewed by Ray.
       
    50 # 
       
    51 #         Changed some code on 2009-12-21.
       
    52 # 
       
    53 #         * File:
       
    54 #         * File2:
       
    55 
       
    56 my $title;
       
    57 my $in;
       
    58 my $out;
       
    59 
       
    60 # New test
       
    61 $title = "fixChangeLogPatch: [no change] First line is new line.";
       
    62 
       
    63 $in = <<'END';
       
    64 --- ChangeLog
       
    65 +++ ChangeLog
       
    66 @@ -1,3 +1,11 @@
       
    67 +2009-12-22  Bob  <bob@email.address>
       
    68 +
       
    69 +        Reviewed by Ray.
       
    70 +
       
    71 +        Changed some more code on 2009-12-22.
       
    72 +
       
    73 +        * File:
       
    74 +
       
    75  2009-12-22  Alice  <alice@email.address>
       
    76  
       
    77          Reviewed by Ray.
       
    78 END
       
    79 
       
    80 ok(fixChangeLogPatch($in) eq $in, $title);
       
    81 
       
    82 # New test
       
    83 $title = "fixChangeLogPatch: [no change] No date string.";
       
    84 
       
    85 $in = <<'END';
       
    86 --- ChangeLog
       
    87 +++ ChangeLog
       
    88 @@ -6,6 +6,7 @@
       
    89  
       
    90          * File:
       
    91          * File2:
       
    92 +        * File3:
       
    93  
       
    94  2009-12-21  Alice  <alice@email.address>
       
    95  
       
    96 END
       
    97 
       
    98 ok(fixChangeLogPatch($in) eq $in, $title);
       
    99 
       
   100 # New test
       
   101 $title = "fixChangeLogPatch: [no change] New entry inserted in middle.";
       
   102 
       
   103 $in = <<'END';
       
   104 --- ChangeLog
       
   105 +++ ChangeLog
       
   106 @@ -11,6 +11,14 @@
       
   107  
       
   108          Reviewed by Ray.
       
   109  
       
   110 +        Changed some more code on 2009-12-21.
       
   111 +
       
   112 +        * File:
       
   113 +
       
   114 +2009-12-21  Alice  <alice@email.address>
       
   115 +
       
   116 +        Reviewed by Ray.
       
   117 +
       
   118          Changed some code on 2009-12-21.
       
   119  
       
   120          * File:
       
   121 END
       
   122 
       
   123 ok(fixChangeLogPatch($in) eq $in, $title);
       
   124 
       
   125 # New test
       
   126 $title = "fixChangeLogPatch: [no change] New entry inserted earlier in the file, but after an entry with the same author and date.";
       
   127 
       
   128 $in = <<'END';
       
   129 --- ChangeLog
       
   130 +++ ChangeLog
       
   131 @@ -70,6 +70,14 @@
       
   132  
       
   133  2009-12-22  Alice  <alice@email.address>
       
   134  
       
   135 +        Reviewed by Sue.
       
   136 +
       
   137 +        Changed some more code on 2009-12-22.
       
   138 +
       
   139 +        * File:
       
   140 +
       
   141 +2009-12-22  Alice  <alice@email.address>
       
   142 +
       
   143          Reviewed by Ray.
       
   144  
       
   145          Changed some code on 2009-12-22.
       
   146 END
       
   147 
       
   148 ok(fixChangeLogPatch($in) eq $in, $title);
       
   149 
       
   150 # New test
       
   151 $title = "fixChangeLogPatch: Leading context includes first line.";
       
   152 
       
   153 $in = <<'END';
       
   154 --- ChangeLog
       
   155 +++ ChangeLog
       
   156 @@ -1,5 +1,13 @@
       
   157  2009-12-22  Alice  <alice@email.address>
       
   158  
       
   159 +        Reviewed by Sue.
       
   160 +
       
   161 +        Changed some more code on 2009-12-22.
       
   162 +
       
   163 +        * File:
       
   164 +
       
   165 +2009-12-22  Alice  <alice@email.address>
       
   166 +
       
   167          Reviewed by Ray.
       
   168  
       
   169          Changed some code on 2009-12-22.
       
   170 END
       
   171 
       
   172 $out = <<'END';
       
   173 --- ChangeLog
       
   174 +++ ChangeLog
       
   175 @@ -1,3 +1,11 @@
       
   176 +2009-12-22  Alice  <alice@email.address>
       
   177 +
       
   178 +        Reviewed by Sue.
       
   179 +
       
   180 +        Changed some more code on 2009-12-22.
       
   181 +
       
   182 +        * File:
       
   183 +
       
   184  2009-12-22  Alice  <alice@email.address>
       
   185  
       
   186          Reviewed by Ray.
       
   187 END
       
   188 
       
   189 ok(fixChangeLogPatch($in) eq $out, $title);
       
   190 
       
   191 # New test
       
   192 $title = "fixChangeLogPatch: Leading context does not include first line.";
       
   193 
       
   194 $in = <<'END';
       
   195 @@ -2,6 +2,14 @@
       
   196  
       
   197          Reviewed by Ray.
       
   198  
       
   199 +        Changed some more code on 2009-12-22.
       
   200 +
       
   201 +        * File:
       
   202 +
       
   203 +2009-12-22  Alice  <alice@email.address>
       
   204 +
       
   205 +        Reviewed by Ray.
       
   206 +
       
   207          Changed some code on 2009-12-22.
       
   208  
       
   209          * File:
       
   210 END
       
   211 
       
   212 $out = <<'END';
       
   213 @@ -1,3 +1,11 @@
       
   214 +2009-12-22  Alice  <alice@email.address>
       
   215 +
       
   216 +        Reviewed by Ray.
       
   217 +
       
   218 +        Changed some more code on 2009-12-22.
       
   219 +
       
   220 +        * File:
       
   221 +
       
   222  2009-12-22  Alice  <alice@email.address>
       
   223  
       
   224          Reviewed by Ray.
       
   225 END
       
   226 
       
   227 ok(fixChangeLogPatch($in) eq $out, $title);
       
   228 
       
   229 # New test
       
   230 $title = "fixChangeLogPatch: Non-consecutive line additions.";
       
   231 
       
   232 # This can occur, for example, if the new ChangeLog entry includes
       
   233 # trailing white space in the first blank line but not the second.
       
   234 # A diff command can then match the second blank line of the new
       
   235 # ChangeLog entry with the first blank line of the old.
       
   236 # The svn diff command with the default --diff-cmd has done this.
       
   237 $in = <<'END';
       
   238 @@ -1,5 +1,11 @@
       
   239  2009-12-22  Alice  <alice@email.address>
       
   240 + <pretend-whitespace>
       
   241 +        Reviewed by Ray.
       
   242  
       
   243 +        Changed some more code on 2009-12-22.
       
   244 +
       
   245 +2009-12-22  Alice  <alice@email.address>
       
   246 +
       
   247          Reviewed by Ray.
       
   248  
       
   249          Changed some code on 2009-12-22.
       
   250 END
       
   251 
       
   252 $out = <<'END';
       
   253 @@ -1,3 +1,9 @@
       
   254 +2009-12-22  Alice  <alice@email.address>
       
   255 + <pretend-whitespace>
       
   256 +        Reviewed by Ray.
       
   257 +
       
   258 +        Changed some more code on 2009-12-22.
       
   259 +
       
   260  2009-12-22  Alice  <alice@email.address>
       
   261  
       
   262          Reviewed by Ray.
       
   263 END
       
   264 
       
   265 ok(fixChangeLogPatch($in) eq $out, $title);
       
   266 
       
   267 # New test
       
   268 $title = "fixChangeLogPatch: Additional edits after new entry.";
       
   269 
       
   270 $in = <<'END';
       
   271 @@ -2,10 +2,17 @@
       
   272  
       
   273          Reviewed by Ray.
       
   274  
       
   275 +        Changed some more code on 2009-12-22.
       
   276 +
       
   277 +        * File:
       
   278 +
       
   279 +2009-12-22  Alice  <alice@email.address>
       
   280 +
       
   281 +        Reviewed by Ray.
       
   282 +
       
   283          Changed some code on 2009-12-22.
       
   284  
       
   285          * File:
       
   286 -        * File2:
       
   287  
       
   288  2009-12-21  Alice  <alice@email.address>
       
   289  
       
   290 END
       
   291 
       
   292 $out = <<'END';
       
   293 @@ -1,11 +1,18 @@
       
   294 +2009-12-22  Alice  <alice@email.address>
       
   295 +
       
   296 +        Reviewed by Ray.
       
   297 +
       
   298 +        Changed some more code on 2009-12-22.
       
   299 +
       
   300 +        * File:
       
   301 +
       
   302  2009-12-22  Alice  <alice@email.address>
       
   303  
       
   304          Reviewed by Ray.
       
   305  
       
   306          Changed some code on 2009-12-22.
       
   307  
       
   308          * File:
       
   309 -        * File2:
       
   310  
       
   311  2009-12-21  Alice  <alice@email.address>
       
   312  
       
   313 END
       
   314 
       
   315 ok(fixChangeLogPatch($in) eq $out, $title);