Skip to content

Commit 5796ef1

Browse files
committed
Adds relevant tests from BzrParser tests.
1 parent 8383f6d commit 5796ef1

File tree

2 files changed

+138
-6
lines changed

2 files changed

+138
-6
lines changed

lib/scm/parsers/bzr_xml_parser.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,18 @@ def strip_trailing_asterisk(path)
110110
end
111111

112112
def remove_dupes(diffs)
113+
BzrXmlParser.remove_dupes(diffs)
113114
# Bazaar may report that a file was added and modified in a single commit.
114115
# Reduce these cases to a single 'A' action.
115-
diffs.delete_if do |d|
116-
d.action == 'M' && diffs.select { |x| x.path == d.path && x.action == 'A' }.any?
117-
end
116+
#diffs.delete_if do |d|
117+
# d.action == 'M' && diffs.select { |x| x.path == d.path && x.action == 'A' }.any?
118+
#end
118119

119120
# Bazaar may report that a file was both deleted and added in a single commit.
120121
# Reduce these cases to a single 'M' action.
121-
diffs.each do |d|
122-
d.action = 'M' if diffs.select { |x| x.path == d.path }.size > 1
123-
end.uniq
122+
#diffs.each do |d|
123+
# d.action = 'M' if diffs.select { |x| x.path == d.path }.size > 1
124+
#end.uniq
124125
end
125126

126127
end
@@ -137,5 +138,19 @@ def self.internal_parse(buffer, opts)
137138
def self.scm
138139
'bzr'
139140
end
141+
142+
def self.remove_dupes(diffs)
143+
# Bazaar may report that a file was added and modified in a single commit.
144+
# Reduce these cases to a single 'A' action.
145+
diffs.delete_if do |d|
146+
d.action == 'M' && diffs.select { |x| x.path == d.path && x.action == 'A' }.any?
147+
end
148+
149+
# Bazaar may report that a file was both deleted and added in a single commit.
150+
# Reduce these cases to a single 'M' action.
151+
diffs.each do |d|
152+
d.action = 'M' if diffs.select { |x| x.path == d.path }.size > 1
153+
end.uniq
154+
end
140155
end
141156
end

test/unit/bzr_xml_parser_test.rb

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,122 @@ def test_different_author_and_committer
245245
assert_equal nil, c.author_name
246246
assert_equal nil, c.author_email
247247
end
248+
249+
def test_rename
250+
xml = <<-XML
251+
<logs>
252+
<log>
253+
<revno>10</revno>
254+
<revisionid>test@example.com-20110725174345-brbpkwumeh07aoh8</revisionid>
255+
<parents>
256+
<parent>amujumdar@blackducksoftware.com-20110722185038-e0i4d1mdxwpipxc4</parent>
257+
</parents>
258+
<committer>test &lt;test@example.com&gt;</committer>
259+
<branch-nick>myproject</branch-nick>
260+
<timestamp>Mon 2011-07-25 13:43:45 -0400</timestamp>
261+
<message><![CDATA[Renamed test1.txt to subdir/test_b.txt, removed test2.txt and added test_a.txt.]]></message>
262+
<affected-files>
263+
<renamed>
264+
<file oldpath="test1.txt" fid="test1.txt-20110722163813-257mjqqrvw3mav0f-2">subdir/test_b.txt</file>
265+
</renamed>
266+
</affected-files>
267+
</log>
268+
</logs>
269+
XML
270+
commits = BzrXmlParser.parse(xml)
271+
assert_equal 1, commits.size
272+
assert_equal 2, commits.first.diffs.size
273+
assert_equal 'D', commits.first.diffs.first.action
274+
assert_equal 'test1.txt', commits.first.diffs.first.path
275+
276+
assert_equal 'A', commits.first.diffs.last.action
277+
assert_equal 'subdir/test_b.txt', commits.first.diffs.last.path
278+
end
279+
280+
def test_remove_dupes_add_remove
281+
diffs = BzrXmlParser.remove_dupes([ Scm::Diff.new(:action => "A", :path => "foo"),
282+
Scm::Diff.new(:action => "D", :path => "foo") ])
283+
assert_equal 1, diffs.size
284+
assert_equal 'M', diffs.first.action
285+
assert_equal 'foo', diffs.first.path
286+
end
287+
288+
# A complex delete/rename/modify test.
289+
# Removed test_a.txt, Renamed test3.txt to test_a.txt, edited test_a.txt
290+
#
291+
# This is what Ohloh expects to see:
292+
#
293+
# D test3.txt
294+
# M test_a.txt
295+
#
296+
def test_complex_rename
297+
xml = <<-XML
298+
<logs>
299+
<log>
300+
<revno>11</revno>
301+
<revisionid>test@example.com-20111012191732-h3bt3lp6l38vbm9v</revisionid>
302+
<parents>
303+
<parent>test@example.com-20110725174345-brbpkwumeh07aoh8</parent>
304+
</parents>
305+
<committer>test &lt;test@example.com&gt;</committer>
306+
<branch-nick>myproject</branch-nick>
307+
<timestamp>Wed 2011-10-12 15:17:32 -0400</timestamp>
308+
<message><![CDATA[Removed test_a.txt, Renamed test3.txt to test_a.txt, edited test_a.txt.]]></message>
309+
<affected-files>
310+
<removed>
311+
<file fid="test_a.txt-20110725174250-y989xbb6y8ae027k-1">test_a.txt</file>
312+
</removed>
313+
<renamed>
314+
<file oldpath="test3.txt" fid="test3.txt-20110722163813-257mjqqrvw3mav0f-4">test_a.txt</file>
315+
</renamed>
316+
<modified>
317+
<file fid="test3.txt-20110722163813-257mjqqrvw3mav0f-4">test_a.txt</file>
318+
</modified>
319+
</affected-files>
320+
</log>
321+
</logs>
322+
XML
323+
diffs = BzrXmlParser.parse(xml).first.diffs
324+
diffs.sort! { |a,b| a.action <=> b.action }
325+
assert_equal 2, diffs.size
326+
assert_equal 'D', diffs.first.action
327+
assert_equal 'test3.txt', diffs.first.path
328+
assert_equal 'M', diffs.last.action
329+
assert_equal 'test_a.txt', diffs.last.path
330+
end
331+
332+
# This test-case also tests rename and modify in the same commit.
333+
# A rename and modify should result in a DELETE and an ADD.
334+
def test_strip_trailing_asterisk_from_executables
335+
xml = <<-XML
336+
<logs>
337+
<log>
338+
<revno>14</revno>
339+
<revisionid>test@example.com-20111012195747-seei62z2wmefjhmo</revisionid>
340+
<parents>
341+
<parent>test@example.com-20111012195606-0shla0kf4e8hq4mq</parent>
342+
</parents>
343+
<committer>test &lt;test@example.com&gt;</committer>
344+
<branch-nick>myproject</branch-nick>
345+
<timestamp>Wed 2011-10-12 15:57:47 -0400</timestamp>
346+
<message><![CDATA[Changed +x on arch and then renamed arch to renamed_arch.]]></message>
347+
<affected-files>
348+
<renamed>
349+
<file oldpath="arch" meta_modified="true" fid="arch-20111012194919-geu209qc2loshh3i-1">renamed_arch</file>
350+
</renamed>
351+
<modified>
352+
<file fid="arch-20111012194919-geu209qc2loshh3i-1">renamed_arch*</file>
353+
</modified>
354+
</affected-files>
355+
</log>
356+
</logs>
357+
XML
358+
diffs = BzrXmlParser.parse(xml).first.diffs
359+
diffs.sort! { |a,b| a.action <=> b.action }
360+
assert_equal 'A', diffs[0].action
361+
assert_equal 'renamed_arch', diffs[0].path
362+
assert_equal 'D', diffs[1].action
363+
assert_equal 'arch', diffs[1].path
364+
end
248365
end
249366
end

0 commit comments

Comments
 (0)