Skip to content

Commit

Permalink
Don't add empty classes
Browse files Browse the repository at this point in the history
XML nodes were being added for empty class lists when they didn't need to be. This was causing issues for some parsers when trying to parse them empty class list. This commit simply ommits a package if it has no applicable files
  • Loading branch information
growpathjadamson committed May 5, 2021
1 parent 9c07643 commit 7bf84d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/simplecov-cobertura.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def result_to_xml(result)
end

groups.map do |name, files|
next if files.empty?
packages.add_element(package = REXML::Element.new('package'))
set_package_attributes(package, name, files)

Expand Down
8 changes: 7 additions & 1 deletion test/simplecov-cobertura_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

class CoberturaFormatterTest < Test::Unit::TestCase
def setup
@result = SimpleCov::Result.new({ "#{__FILE__}" => [1,2] })
coverage_data =
if Gem.loaded_specs['simplecov'].version >= Gem::Version.new('0.18')
{ lines: [1, 2] }
else
[1, 2]
end
@result = SimpleCov::Result.new({ __FILE__ => coverage_data })
@formatter = SimpleCov::Formatter::CoberturaFormatter.new
end

Expand Down

0 comments on commit 7bf84d0

Please sign in to comment.