1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
#!/usr/bin/perl
#
# Copyright (C) 2010 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Unit tests of VCSUtils::mergeChangeLogs().
use strict;
use Test::Simple tests => 16;
use File::Temp qw(tempfile);
use VCSUtils;
# Read contents of a file and return it.
sub readFile($)
{
my ($fileName) = @_;
local $/;
open(FH, "<", $fileName);
my $content = <FH>;
close(FH);
return $content;
}
# Write a temporary file and return the filename.
sub writeTempFile($$$)
{
my ($name, $extension, $content) = @_;
my ($FH, $fileName) = tempfile(
$name . "-XXXXXXXX",
DIR => ($ENV{'TMPDIR'} || $ENV{'TEMP'} || "/tmp"),
UNLINK => 0,
);
print $FH $content;
close $FH;
if ($extension) {
my $newFileName = $fileName . $extension;
rename($fileName, $newFileName);
$fileName = $newFileName;
}
return $fileName;
}
# --------------------------------------------------------------------------------
{
# New test
my $title = "mergeChangeLogs: traditional rejected patch success";
my $fileNewerContent = <<'EOF';
2010-01-29 Mark Rowe <mrowe@apple.com>
Fix the Mac build.
Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional".
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileNewer = writeTempFile("file", "", $fileNewerContent);
my $fileMineContent = <<'EOF';
***************
*** 1,3 ****
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
--- 1,9 ----
+ 2010-01-29 Oliver Hunt <oliver@apple.com>
+
+ Reviewed by Darin Adler.
+
+ JSC is failing to propagate anonymous slot count on some transitions
+
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
EOF
my $fileMine = writeTempFile("file", ".rej", $fileMineContent);
rename($fileMine, $fileNewer . ".rej");
$fileMine = $fileNewer . ".rej";
my $fileOlderContent = $fileNewerContent;
my $fileOlder = writeTempFile("file", ".orig", $fileOlderContent);
rename($fileOlder, $fileNewer . ".orig");
$fileOlder = $fileNewer . ".orig";
my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer);
# mergeChangeLogs() should return 1 since the patch succeeded.
ok($exitStatus == 1, "$title: should return 1 for success");
ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged");
ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged");
my $expectedContent = <<'EOF';
2010-01-29 Oliver Hunt <oliver@apple.com>
Reviewed by Darin Adler.
JSC is failing to propagate anonymous slot count on some transitions
EOF
$expectedContent .= $fileNewerContent;
ok(readFile($fileNewer) eq $expectedContent, "$title: \$fileNewer should be updated to include patch");
unlink($fileMine, $fileOlder, $fileNewer);
}
# --------------------------------------------------------------------------------
{
# New test
my $title = "mergeChangeLogs: traditional rejected patch failure";
my $fileNewerContent = <<'EOF';
2010-01-29 Mark Rowe <mrowe@apple.com>
Fix the Mac build.
Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional".
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileNewer = writeTempFile("file", "", $fileNewerContent);
my $fileMineContent = <<'EOF';
***************
*** 1,9 ****
- 2010-01-29 Oliver Hunt <oliver@apple.com>
-
- Reviewed by Darin Adler.
-
- JSC is failing to propagate anonymous slot count on some transitions
-
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
--- 1,3 ----
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
EOF
my $fileMine = writeTempFile("file", ".rej", $fileMineContent);
rename($fileMine, $fileNewer . ".rej");
$fileMine = $fileNewer . ".rej";
my $fileOlderContent = $fileNewerContent;
my $fileOlder = writeTempFile("file", ".orig", $fileOlderContent);
rename($fileOlder, $fileNewer . ".orig");
$fileOlder = $fileNewer . ".orig";
my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer);
# mergeChangeLogs() should return 0 since the patch failed.
ok($exitStatus == 0, "$title: should return 0 for failure");
ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged");
ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged");
ok(readFile($fileNewer) eq $fileNewerContent, "$title: \$fileNewer should be unchanged");
unlink($fileMine, $fileOlder, $fileNewer);
}
# --------------------------------------------------------------------------------
{
# New test
my $title = "mergeChangeLogs: patch succeeds";
my $fileMineContent = <<'EOF';
2010-01-29 Oliver Hunt <oliver@apple.com>
Reviewed by Darin Adler.
JSC is failing to propagate anonymous slot count on some transitions
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileMine = writeTempFile("fileMine", "", $fileMineContent);
my $fileOlderContent = <<'EOF';
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileOlder = writeTempFile("fileOlder", "", $fileOlderContent);
my $fileNewerContent = <<'EOF';
2010-01-29 Mark Rowe <mrowe@apple.com>
Fix the Mac build.
Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional".
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileNewer = writeTempFile("fileNewer", "", $fileNewerContent);
my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer);
# mergeChangeLogs() should return 1 since the patch succeeded.
ok($exitStatus == 1, "$title: should return 1 for success");
ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged");
ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged");
my $expectedContent = <<'EOF';
2010-01-29 Oliver Hunt <oliver@apple.com>
Reviewed by Darin Adler.
JSC is failing to propagate anonymous slot count on some transitions
EOF
$expectedContent .= $fileNewerContent;
ok(readFile($fileNewer) eq $expectedContent, "$title: \$fileNewer should be patched");
unlink($fileMine, $fileOlder, $fileNewer);
}
# --------------------------------------------------------------------------------
{
# New test
my $title = "mergeChangeLogs: patch fails";
my $fileMineContent = <<'EOF';
2010-01-29 Mark Rowe <mrowe@apple.com>
Fix the Mac build.
Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional".
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileMine = writeTempFile("fileMine", "", $fileMineContent);
my $fileOlderContent = <<'EOF';
2010-01-29 Mark Rowe <mrowe@apple.com>
Fix the Mac build.
Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional".
2010-01-29 Oliver Hunt <oliver@apple.com>
Reviewed by Darin Adler.
JSC is failing to propagate anonymous slot count on some transitions
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileOlder = writeTempFile("fileOlder", "", $fileOlderContent);
my $fileNewerContent = <<'EOF';
2010-01-29 Oliver Hunt <oliver@apple.com>
Reviewed by Darin Adler.
JSC is failing to propagate anonymous slot count on some transitions
2010-01-29 Simon Hausmann <simon.hausmann@nokia.com>
Rubber-stamped by Maciej Stachowiak.
Fix the ARM build.
EOF
my $fileNewer = writeTempFile("fileNewer", "", $fileNewerContent);
my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer);
# mergeChangeLogs() should return a non-zero exit status since the patch failed.
ok($exitStatus == 0, "$title: return non-zero exit status for failure");
ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged");
ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged");
# $fileNewer should still exist unchanged because the patch failed
ok(readFile($fileNewer) eq $fileNewerContent, "$title: \$fileNewer should be unchanged");
unlink($fileMine, $fileOlder, $fileNewer);
}
# --------------------------------------------------------------------------------
|