• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
33use Test::Simple tests => 7;
34use 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
56my $title;
57my $in;
58my $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.
78END
79
80ok(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
96END
97
98ok(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:
121END
122
123ok(fixChangeLogPatch($in) eq $in, $title);
124
125# New test
126$title = "fixChangeLogPatch: Leading context includes first line.";
127
128$in = <<'END';
129--- ChangeLog
130+++ ChangeLog
131@@ -1,5 +1,13 @@
132 2009-12-22  Alice  <alice@email.address>
133
134+        Reviewed by Sue.
135+
136+        Changed some more code on 2009-12-22.
137+
138+        * File:
139+
140+2009-12-22  Alice  <alice@email.address>
141+
142         Reviewed by Ray.
143
144         Changed some code on 2009-12-22.
145END
146
147$out = <<'END';
148--- ChangeLog
149+++ ChangeLog
150@@ -1,3 +1,11 @@
151+2009-12-22  Alice  <alice@email.address>
152+
153+        Reviewed by Sue.
154+
155+        Changed some more code on 2009-12-22.
156+
157+        * File:
158+
159 2009-12-22  Alice  <alice@email.address>
160
161         Reviewed by Ray.
162END
163
164ok(fixChangeLogPatch($in) eq $out, $title);
165
166# New test
167$title = "fixChangeLogPatch: Leading context does not include first line.";
168
169$in = <<'END';
170@@ -2,6 +2,14 @@
171
172         Reviewed by Ray.
173
174+        Changed some more code on 2009-12-22.
175+
176+        * File:
177+
178+2009-12-22  Alice  <alice@email.address>
179+
180+        Reviewed by Ray.
181+
182         Changed some code on 2009-12-22.
183
184         * File:
185END
186
187$out = <<'END';
188@@ -1,3 +1,11 @@
189+2009-12-22  Alice  <alice@email.address>
190+
191+        Reviewed by Ray.
192+
193+        Changed some more code on 2009-12-22.
194+
195+        * File:
196+
197 2009-12-22  Alice  <alice@email.address>
198
199         Reviewed by Ray.
200END
201
202ok(fixChangeLogPatch($in) eq $out, $title);
203
204# New test
205$title = "fixChangeLogPatch: Non-consecutive line additions.";
206
207# This can occur, for example, if the new ChangeLog entry includes
208# trailing white space in the first blank line but not the second.
209# A diff command can then match the second blank line of the new
210# ChangeLog entry with the first blank line of the old.
211# The svn diff command with the default --diff-cmd has done this.
212$in = <<'END';
213@@ -1,5 +1,11 @@
214 2009-12-22  Alice  <alice@email.address>
215+ <pretend-whitespace>
216+        Reviewed by Ray.
217
218+        Changed some more code on 2009-12-22.
219+
220+2009-12-22  Alice  <alice@email.address>
221+
222         Reviewed by Ray.
223
224         Changed some code on 2009-12-22.
225END
226
227$out = <<'END';
228@@ -1,3 +1,9 @@
229+2009-12-22  Alice  <alice@email.address>
230+ <pretend-whitespace>
231+        Reviewed by Ray.
232+
233+        Changed some more code on 2009-12-22.
234+
235 2009-12-22  Alice  <alice@email.address>
236
237         Reviewed by Ray.
238END
239
240ok(fixChangeLogPatch($in) eq $out, $title);
241
242# New test
243$title = "fixChangeLogPatch: Additional edits after new entry.";
244
245$in = <<'END';
246@@ -2,10 +2,17 @@
247
248         Reviewed by Ray.
249
250+        Changed some more code on 2009-12-22.
251+
252+        * File:
253+
254+2009-12-22  Alice  <alice@email.address>
255+
256+        Reviewed by Ray.
257+
258         Changed some code on 2009-12-22.
259
260         * File:
261-        * File2:
262
263 2009-12-21  Alice  <alice@email.address>
264
265END
266
267$out = <<'END';
268@@ -1,11 +1,18 @@
269+2009-12-22  Alice  <alice@email.address>
270+
271+        Reviewed by Ray.
272+
273+        Changed some more code on 2009-12-22.
274+
275+        * File:
276+
277 2009-12-22  Alice  <alice@email.address>
278
279         Reviewed by Ray.
280
281         Changed some code on 2009-12-22.
282
283         * File:
284-        * File2:
285
286 2009-12-21  Alice  <alice@email.address>
287
288END
289
290ok(fixChangeLogPatch($in) eq $out, $title);
291