require_relative '../test_helper' module OhlohScm::Parsers class BzrXmlParserTest < Scm::Test def test_empty_array assert_equal([], BzrXmlParser.parse('')) end def test_empty_xml assert_equal("\n\n\n", BzrXmlParser.parse('', :writer => XmlWriter.new)) end def test_basic_xml xml = <<-XML 10 test@example.com-20110725174345-brbpkwumeh07aoh8 amujumdar@blackducksoftware.com-20110722185038-e0i4d1mdxwpipxc4 test <test@example.com> myproject Mon 2011-07-25 13:43:45 -0400 XML commits = BzrXmlParser.parse(xml) assert_equal 1, commits.size c = commits.first assert_equal 0, c.diffs.size assert_equal "Renamed test1.txt to subdir/test_b.txt, removed test2.txt and added test_a.txt.", c.message assert_equal "test@example.com-20110725174345-brbpkwumeh07aoh8", c.token end def test_verbose_xml xml = <<-XML 10 test@example.com-20110725174345-brbpkwumeh07aoh8 amujumdar@blackducksoftware.com-20110722185038-e0i4d1mdxwpipxc4 test <test@example.com> myproject Mon 2011-07-25 13:43:45 -0400 test2.txt test_a.txt subdir/test_b.txt XML commits = BzrXmlParser.parse(xml) assert_equal 1, commits.size c = commits.first assert_equal 4, c.diffs.size # Rename is a D followed by A assert_equal "test2.txt", c.diffs[0].path assert_equal "D", c.diffs[0].action assert_equal "test_a.txt", c.diffs[1].path assert_equal "A", c.diffs[1].action assert_equal "test1.txt", c.diffs[2].path assert_equal "D", c.diffs[2].action assert_equal "subdir/test_b.txt", c.diffs[3].path assert_equal "A", c.diffs[3].action end # When an directory is deleted, bzr outputs one delete entry # per file and one for the directory. For empty dirs, there # is only one directory remove entry. # Ohloh keeps file delete entries but ignores directory # delete entry. def test_ignore_dir_delete_xml xml = <<-XML 720.9.33 jano.vesely@gmail.com-20110127220929-d3af6kj4d53lh70t jano.vesely@gmail.com-20110125225108-0vxoig7z3d3q0w0w vojtechhorky@users.sourceforge.net-20110126145255-4xdar4rxwcrh6s0a Jan Vesely <jano.vesely@gmail.com> helenos Thu 2011-01-27 23:09:29 +0100 uspace/lib/net/include/nil_interface.h uspace/srv/hw/bus/usb/ uspace/srv/hw/bus/usb/hcd/ XML commits = BzrXmlParser.parse(xml) assert_equal 1, commits.size c = commits.first assert_equal 1, c.diffs.size assert_equal "uspace/lib/net/include/nil_interface.h", c.diffs.first.path end # bzr also outputs a kind_changed entry when file kind changes, for example # a symlink is changed to file. # Ohloh ignores such changes. def test_ignore_kind_changed_xml xml = <<-XML 720.9.33 jano.vesely@gmail.com-20110127220929-d3af6kj4d53lh70t jano.vesely@gmail.com-20110125225108-0vxoig7z3d3q0w0w vojtechhorky@users.sourceforge.net-20110126145255-4xdar4rxwcrh6s0a Jan Vesely <jano.vesely@gmail.com> helenos Thu 2011-01-27 23:09:29 +0100 uspace/lib/net/include/nil_interface.h uspace/app/tester/mm/mapping1.c uspace/lib/usb/include/usb/hcd.h uspace/lib/usb/include/usb/addrkeep.h .bzrignore XML commits = BzrXmlParser.parse(xml) assert_equal 1, commits.size c = commits.first assert_equal 3, c.diffs.size assert_equal "D", c.diffs[0].action assert_equal "uspace/lib/net/include/nil_interface.h", c.diffs[0].path assert_equal "A", c.diffs[1].action assert_equal "uspace/app/tester/mm/mapping1.c", c.diffs[1].path assert_equal "M", c.diffs[2].action assert_equal ".bzrignore", c.diffs[2].path end def test_different_author_and_committer xml = <<-XML 1 amujumdar@blackducksoftware.com-20111011152356-90nluwydpw9g4ncu Abhay Mujumdar <amujumdar@blackducksoftware.com> bzr_with_authors Tue 2011-10-11 11:23:56 -0400 2 amujumdar@blackducksoftware.com-20111011152412-l9ehyruiezws32kj amujumdar@blackducksoftware.com-20111011152356-90nluwydpw9g4ncu Abhay Mujumdar <amujumdar@blackducksoftware.com> John Doe <johndoe@example.com> bzr_with_authors Tue 2011-10-11 11:24:12 -0400 3 test@example.com-20111011162601-ud1nidteswfdbhbu amujumdar@blackducksoftware.com-20111011152412-l9ehyruiezws32kj test <test@example.com> Jim Beam <jimbeam@example.com> Jane Smith <janesmith@example.com> bzr_with_authors Tue 2011-10-11 12:26:01 -0400 4 test@example.com-20111011162601-dummyrevision test@example.com-20111011162601-ud1nidteswfdbhbu test <test@example.com> bzr_with_authors Tue 2011-10-11 12:28:01 -0400 XML commits = BzrXmlParser.parse(xml) c = commits[0] assert_equal "Abhay Mujumdar", c.committer_name assert_equal "amujumdar@blackducksoftware.com", c.committer_email c = commits[1] assert_equal "Abhay Mujumdar", c.committer_name assert_equal "amujumdar@blackducksoftware.com", c.committer_email assert_equal "John Doe", c.author_name assert_equal "johndoe@example.com", c.author_email c = commits[2] assert_equal "test", c.committer_name assert_equal "test@example.com", c.committer_email assert_equal "Jim Beam", c.author_name assert_equal "jimbeam@example.com", c.author_email c = commits[3] assert_equal "test", c.committer_name assert_equal "test@example.com", c.committer_email assert_equal nil, c.author_name assert_equal nil, c.author_email end def test_rename xml = <<-XML 10 test@example.com-20110725174345-brbpkwumeh07aoh8 amujumdar@blackducksoftware.com-20110722185038-e0i4d1mdxwpipxc4 test <test@example.com> myproject Mon 2011-07-25 13:43:45 -0400 subdir/test_b.txt XML commits = BzrXmlParser.parse(xml) assert_equal 1, commits.size assert_equal 2, commits.first.diffs.size assert_equal 'D', commits.first.diffs.first.action assert_equal 'test1.txt', commits.first.diffs.first.path assert_equal 'A', commits.first.diffs.last.action assert_equal 'subdir/test_b.txt', commits.first.diffs.last.path end def test_remove_dupes_add_remove diffs = BzrXmlParser.remove_dupes([ Scm::Diff.new(:action => "A", :path => "foo"), Scm::Diff.new(:action => "D", :path => "foo") ]) assert_equal 1, diffs.size assert_equal 'M', diffs.first.action assert_equal 'foo', diffs.first.path end # A complex delete/rename/modify test. # Removed test_a.txt, Renamed test3.txt to test_a.txt, edited test_a.txt # # This is what Ohloh expects to see: # # D test3.txt # M test_a.txt # def test_complex_rename xml = <<-XML 11 test@example.com-20111012191732-h3bt3lp6l38vbm9v test@example.com-20110725174345-brbpkwumeh07aoh8 test <test@example.com> myproject Wed 2011-10-12 15:17:32 -0400 test_a.txt test_a.txt test_a.txt XML diffs = BzrXmlParser.parse(xml).first.diffs diffs.sort! { |a,b| a.action <=> b.action } assert_equal 2, diffs.size assert_equal 'D', diffs.first.action assert_equal 'test3.txt', diffs.first.path assert_equal 'M', diffs.last.action assert_equal 'test_a.txt', diffs.last.path end # This test-case also tests rename and modify in the same commit. # A rename and modify should result in a DELETE and an ADD. def test_strip_trailing_asterisk_from_executables xml = <<-XML 14 test@example.com-20111012195747-seei62z2wmefjhmo test@example.com-20111012195606-0shla0kf4e8hq4mq test <test@example.com> myproject Wed 2011-10-12 15:57:47 -0400 renamed_arch renamed_arch* XML diffs = BzrXmlParser.parse(xml).first.diffs diffs.sort! { |a,b| a.action <=> b.action } assert_equal 'A', diffs[0].action assert_equal 'renamed_arch', diffs[0].path assert_equal 'D', diffs[1].action assert_equal 'arch', diffs[1].path end def test_committer_name_capture name, email = BzrXmlParser.capture_name('John') assert_equal name, 'John' assert_equal email, nil assert_equal ['John Doe', nil], BzrXmlParser.capture_name('John Doe') assert_equal ['John Doe jdoe@example.com', nil], BzrXmlParser.capture_name('John Doe jdoe@example.com') assert_equal ['John Doe ', nil], BzrXmlParser.capture_name('John Doe jdoe@example.com>') assert_equal ['John Doe', 'jdoe@example.com'], BzrXmlParser.capture_name('John Doe ') assert_equal ['John Doe', 'jdoe@example.com'], BzrXmlParser.capture_name('John Doe ') assert_equal ['jdoe@example.com', nil], BzrXmlParser.capture_name('jdoe@example.com') xml = <<-XML 15 a@b.com-20111013152207-q8uec9pp1330gfbh test@example.com-20111012195747-seei62z2wmefjhmo a@b.com author@c.com myproject Thu 2011-10-13 11:22:07 -0400 test_a.txt XML c = BzrXmlParser.parse(xml).first assert_equal 'M', c.diffs.first.action assert_equal 'test_a.txt', c.diffs.first.path assert_equal 'a@b.com', c.committer_name assert_equal nil, c.committer_email assert_equal 'author@c.com', c.author_name assert_equal nil, c.author_email end end end