|
1 #!/usr/bin/perl |
|
2 # |
|
3 # Copyright (C) 2010 Apple Inc. All rights reserved. |
|
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 VCSUtils::mergeChangeLogs(). |
|
26 |
|
27 use strict; |
|
28 |
|
29 use Test::Simple tests => 16; |
|
30 use File::Temp qw(tempfile); |
|
31 use VCSUtils; |
|
32 |
|
33 # Read contents of a file and return it. |
|
34 sub readFile($) |
|
35 { |
|
36 my ($fileName) = @_; |
|
37 |
|
38 local $/; |
|
39 open(FH, "<", $fileName); |
|
40 my $content = <FH>; |
|
41 close(FH); |
|
42 |
|
43 return $content; |
|
44 } |
|
45 |
|
46 # Write a temporary file and return the filename. |
|
47 sub writeTempFile($$$) |
|
48 { |
|
49 my ($name, $extension, $content) = @_; |
|
50 |
|
51 my ($FH, $fileName) = tempfile( |
|
52 $name . "-XXXXXXXX", |
|
53 DIR => ($ENV{'TMPDIR'} || "/tmp"), |
|
54 UNLINK => 0, |
|
55 ); |
|
56 print $FH $content; |
|
57 close $FH; |
|
58 |
|
59 if ($extension) { |
|
60 my $newFileName = $fileName . $extension; |
|
61 rename($fileName, $newFileName); |
|
62 $fileName = $newFileName; |
|
63 } |
|
64 |
|
65 return $fileName; |
|
66 } |
|
67 |
|
68 # -------------------------------------------------------------------------------- |
|
69 |
|
70 { |
|
71 # New test |
|
72 my $title = "mergeChangeLogs: traditional rejected patch success"; |
|
73 |
|
74 my $fileNewerContent = <<'EOF'; |
|
75 2010-01-29 Mark Rowe <mrowe@apple.com> |
|
76 |
|
77 Fix the Mac build. |
|
78 |
|
79 Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional". |
|
80 |
|
81 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
82 |
|
83 Rubber-stamped by Maciej Stachowiak. |
|
84 |
|
85 Fix the ARM build. |
|
86 EOF |
|
87 my $fileNewer = writeTempFile("file", "", $fileNewerContent); |
|
88 |
|
89 my $fileMineContent = <<'EOF'; |
|
90 *************** |
|
91 *** 1,3 **** |
|
92 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
93 |
|
94 Rubber-stamped by Maciej Stachowiak. |
|
95 --- 1,9 ---- |
|
96 + 2010-01-29 Oliver Hunt <oliver@apple.com> |
|
97 + |
|
98 + Reviewed by Darin Adler. |
|
99 + |
|
100 + JSC is failing to propagate anonymous slot count on some transitions |
|
101 + |
|
102 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
103 |
|
104 Rubber-stamped by Maciej Stachowiak. |
|
105 EOF |
|
106 my $fileMine = writeTempFile("file", ".rej", $fileMineContent); |
|
107 rename($fileMine, $fileNewer . ".rej"); |
|
108 $fileMine = $fileNewer . ".rej"; |
|
109 |
|
110 my $fileOlderContent = $fileNewerContent; |
|
111 my $fileOlder = writeTempFile("file", ".orig", $fileOlderContent); |
|
112 rename($fileOlder, $fileNewer . ".orig"); |
|
113 $fileOlder = $fileNewer . ".orig"; |
|
114 |
|
115 my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer); |
|
116 |
|
117 # mergeChangeLogs() should return 1 since the patch succeeded. |
|
118 ok($exitStatus == 1, "$title: should return 1 for success"); |
|
119 |
|
120 ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged"); |
|
121 ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged"); |
|
122 |
|
123 my $expectedContent = <<'EOF'; |
|
124 2010-01-29 Oliver Hunt <oliver@apple.com> |
|
125 |
|
126 Reviewed by Darin Adler. |
|
127 |
|
128 JSC is failing to propagate anonymous slot count on some transitions |
|
129 |
|
130 EOF |
|
131 $expectedContent .= $fileNewerContent; |
|
132 ok(readFile($fileNewer) eq $expectedContent, "$title: \$fileNewer should be updated to include patch"); |
|
133 |
|
134 unlink($fileMine, $fileOlder, $fileNewer); |
|
135 } |
|
136 |
|
137 # -------------------------------------------------------------------------------- |
|
138 |
|
139 { |
|
140 # New test |
|
141 my $title = "mergeChangeLogs: traditional rejected patch failure"; |
|
142 |
|
143 my $fileNewerContent = <<'EOF'; |
|
144 2010-01-29 Mark Rowe <mrowe@apple.com> |
|
145 |
|
146 Fix the Mac build. |
|
147 |
|
148 Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional". |
|
149 |
|
150 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
151 |
|
152 Rubber-stamped by Maciej Stachowiak. |
|
153 |
|
154 Fix the ARM build. |
|
155 EOF |
|
156 my $fileNewer = writeTempFile("file", "", $fileNewerContent); |
|
157 |
|
158 my $fileMineContent = <<'EOF'; |
|
159 *************** |
|
160 *** 1,9 **** |
|
161 - 2010-01-29 Oliver Hunt <oliver@apple.com> |
|
162 - |
|
163 - Reviewed by Darin Adler. |
|
164 - |
|
165 - JSC is failing to propagate anonymous slot count on some transitions |
|
166 - |
|
167 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
168 |
|
169 Rubber-stamped by Maciej Stachowiak. |
|
170 --- 1,3 ---- |
|
171 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
172 |
|
173 Rubber-stamped by Maciej Stachowiak. |
|
174 EOF |
|
175 my $fileMine = writeTempFile("file", ".rej", $fileMineContent); |
|
176 rename($fileMine, $fileNewer . ".rej"); |
|
177 $fileMine = $fileNewer . ".rej"; |
|
178 |
|
179 my $fileOlderContent = $fileNewerContent; |
|
180 my $fileOlder = writeTempFile("file", ".orig", $fileOlderContent); |
|
181 rename($fileOlder, $fileNewer . ".orig"); |
|
182 $fileOlder = $fileNewer . ".orig"; |
|
183 |
|
184 my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer); |
|
185 |
|
186 # mergeChangeLogs() should return 0 since the patch failed. |
|
187 ok($exitStatus == 0, "$title: should return 0 for failure"); |
|
188 |
|
189 ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged"); |
|
190 ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged"); |
|
191 ok(readFile($fileNewer) eq $fileNewerContent, "$title: \$fileNewer should be unchanged"); |
|
192 |
|
193 unlink($fileMine, $fileOlder, $fileNewer); |
|
194 } |
|
195 |
|
196 # -------------------------------------------------------------------------------- |
|
197 |
|
198 { |
|
199 # New test |
|
200 my $title = "mergeChangeLogs: patch succeeds"; |
|
201 |
|
202 my $fileMineContent = <<'EOF'; |
|
203 2010-01-29 Oliver Hunt <oliver@apple.com> |
|
204 |
|
205 Reviewed by Darin Adler. |
|
206 |
|
207 JSC is failing to propagate anonymous slot count on some transitions |
|
208 |
|
209 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
210 |
|
211 Rubber-stamped by Maciej Stachowiak. |
|
212 |
|
213 Fix the ARM build. |
|
214 EOF |
|
215 my $fileMine = writeTempFile("fileMine", "", $fileMineContent); |
|
216 |
|
217 my $fileOlderContent = <<'EOF'; |
|
218 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
219 |
|
220 Rubber-stamped by Maciej Stachowiak. |
|
221 |
|
222 Fix the ARM build. |
|
223 EOF |
|
224 my $fileOlder = writeTempFile("fileOlder", "", $fileOlderContent); |
|
225 |
|
226 my $fileNewerContent = <<'EOF'; |
|
227 2010-01-29 Mark Rowe <mrowe@apple.com> |
|
228 |
|
229 Fix the Mac build. |
|
230 |
|
231 Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional". |
|
232 |
|
233 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
234 |
|
235 Rubber-stamped by Maciej Stachowiak. |
|
236 |
|
237 Fix the ARM build. |
|
238 EOF |
|
239 my $fileNewer = writeTempFile("fileNewer", "", $fileNewerContent); |
|
240 |
|
241 my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer); |
|
242 |
|
243 # mergeChangeLogs() should return 1 since the patch succeeded. |
|
244 ok($exitStatus == 1, "$title: should return 1 for success"); |
|
245 |
|
246 ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged"); |
|
247 ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged"); |
|
248 |
|
249 my $expectedContent = <<'EOF'; |
|
250 2010-01-29 Oliver Hunt <oliver@apple.com> |
|
251 |
|
252 Reviewed by Darin Adler. |
|
253 |
|
254 JSC is failing to propagate anonymous slot count on some transitions |
|
255 |
|
256 EOF |
|
257 $expectedContent .= $fileNewerContent; |
|
258 |
|
259 ok(readFile($fileNewer) eq $expectedContent, "$title: \$fileNewer should be patched"); |
|
260 |
|
261 unlink($fileMine, $fileOlder, $fileNewer); |
|
262 } |
|
263 |
|
264 # -------------------------------------------------------------------------------- |
|
265 |
|
266 { |
|
267 # New test |
|
268 my $title = "mergeChangeLogs: patch fails"; |
|
269 |
|
270 my $fileMineContent = <<'EOF'; |
|
271 2010-01-29 Mark Rowe <mrowe@apple.com> |
|
272 |
|
273 Fix the Mac build. |
|
274 |
|
275 Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional". |
|
276 |
|
277 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
278 |
|
279 Rubber-stamped by Maciej Stachowiak. |
|
280 |
|
281 Fix the ARM build. |
|
282 EOF |
|
283 my $fileMine = writeTempFile("fileMine", "", $fileMineContent); |
|
284 |
|
285 my $fileOlderContent = <<'EOF'; |
|
286 2010-01-29 Mark Rowe <mrowe@apple.com> |
|
287 |
|
288 Fix the Mac build. |
|
289 |
|
290 Disable ENABLE_INDEXED_DATABASE since it is "completely non-functional". |
|
291 |
|
292 2010-01-29 Oliver Hunt <oliver@apple.com> |
|
293 |
|
294 Reviewed by Darin Adler. |
|
295 |
|
296 JSC is failing to propagate anonymous slot count on some transitions |
|
297 |
|
298 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
299 |
|
300 Rubber-stamped by Maciej Stachowiak. |
|
301 |
|
302 Fix the ARM build. |
|
303 EOF |
|
304 my $fileOlder = writeTempFile("fileOlder", "", $fileOlderContent); |
|
305 |
|
306 my $fileNewerContent = <<'EOF'; |
|
307 2010-01-29 Oliver Hunt <oliver@apple.com> |
|
308 |
|
309 Reviewed by Darin Adler. |
|
310 |
|
311 JSC is failing to propagate anonymous slot count on some transitions |
|
312 |
|
313 2010-01-29 Simon Hausmann <simon.hausmann@nokia.com> |
|
314 |
|
315 Rubber-stamped by Maciej Stachowiak. |
|
316 |
|
317 Fix the ARM build. |
|
318 EOF |
|
319 my $fileNewer = writeTempFile("fileNewer", "", $fileNewerContent); |
|
320 |
|
321 my $exitStatus = mergeChangeLogs($fileMine, $fileOlder, $fileNewer); |
|
322 |
|
323 # mergeChangeLogs() should return a non-zero exit status since the patch failed. |
|
324 ok($exitStatus == 0, "$title: return non-zero exit status for failure"); |
|
325 |
|
326 ok(readFile($fileMine) eq $fileMineContent, "$title: \$fileMine should be unchanged"); |
|
327 ok(readFile($fileOlder) eq $fileOlderContent, "$title: \$fileOlder should be unchanged"); |
|
328 |
|
329 # $fileNewer should still exist unchanged because the patch failed |
|
330 ok(readFile($fileNewer) eq $fileNewerContent, "$title: \$fileNewer should be unchanged"); |
|
331 |
|
332 unlink($fileMine, $fileOlder, $fileNewer); |
|
333 } |
|
334 |
|
335 # -------------------------------------------------------------------------------- |
|
336 |