@@ -245,5 +245,122 @@ def test_different_author_and_committer
245
245
assert_equal nil , c . author_name
246
246
assert_equal nil , c . author_email
247
247
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 <test@example.com></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 <test@example.com></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 <test@example.com></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
248
365
end
249
366
end
0 commit comments