Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## master

## v1.6.0
## v1.5.4

* Fix calculation of branch coverage when a class has no branches
[Julian Krumow](https://github.com/tarbrain)
[#40](https://github.com/venmo/slather/pull/40)

## v1.5.2

* Add an option to define the output directory for cobertura xml reports
[Julian Krumow](https://github.com/tarbrain)
Expand Down
32 changes: 21 additions & 11 deletions lib/slather/coverage_service/cobertura_xml_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def grouped_coverage_files
def create_xml_report(coverage_files)
total_project_lines = 0
total_project_lines_tested = 0
total_project_line_rate = 0.0
total_project_line_rate = '%.16f' % 1.0
total_project_branches = 0
total_project_branches_tested = 0
total_project_branch_rate = '%.16f' % 1.0

create_empty_xml_report
coverage_node = @doc.root
Expand All @@ -58,9 +59,10 @@ def create_xml_report(coverage_files)

total_package_lines = 0
total_package_lines_tested = 0
total_package_lines_rate = 0.0
total_package_lines_rate = '%.16f' % 1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I remember was this does now!

total_package_branches = 0
total_package_branches_tested = 0
total_package_branch_rate = '%.16f' % 1.0

package_coverage_files.each do |package_coverage_file|
class_node = create_class_node(package_coverage_file)
Expand All @@ -71,8 +73,13 @@ def create_xml_report(coverage_files)
total_package_branches_tested += package_coverage_file.num_branches_tested
end

total_package_line_rate = '%.16f' % (total_package_lines_tested / total_package_lines.to_f)
total_package_branch_rate = '%.16f' % (total_package_branches_tested / total_package_branches.to_f)
if (total_package_lines > 0)
total_package_line_rate = '%.16f' % (total_package_lines_tested / total_package_lines.to_f)
end

if (total_package_branches > 0)
total_package_branch_rate = '%.16f' % (total_package_branches_tested / total_package_branches.to_f)
end

package_node['line-rate'] = total_package_line_rate
package_node['branch-rate'] = total_package_branch_rate
Expand All @@ -84,8 +91,13 @@ def create_xml_report(coverage_files)
total_project_branches_tested += total_package_branches_tested
end

total_project_line_rate = '%.16f' % (total_project_lines_tested / total_project_lines.to_f)
total_project_branch_rate = '%.16f' % (total_project_branches_tested / total_project_branches.to_f)
if (total_project_lines > 0)
total_project_line_rate = '%.16f' % (total_project_lines_tested / total_project_lines.to_f)
end

if (total_project_branches > 0)
total_project_branch_rate = '%.16f' % (total_project_branches_tested / total_project_branches.to_f)
end

coverage_node['line-rate'] = total_project_line_rate
coverage_node['branch-rate'] = total_project_branch_rate
Expand All @@ -106,8 +118,9 @@ def create_class_node(coverage_file)
class_node = Nokogiri::XML::Node.new "class", @doc
class_node['name'] = filename
class_node['filename'] = filepath
class_node['line-rate'] = '%.16f' % coverage_file.rate_lines_tested
class_node['branch-rate'] = '1.0'
class_node['line-rate'] = '%.16f' % [(coverage_file.num_lines_testable > 0) ? coverage_file.rate_lines_tested : 1.0]
class_node['branch-rate'] = '%.16f' % [(coverage_file.num_branches_testable > 0) ? coverage_file.rate_branches_tested : 1.0]
class_node['complexity'] = '0.0'

methods_node = Nokogiri::XML::Node.new "methods", @doc
methods_node.parent = class_node
Expand All @@ -117,13 +130,10 @@ def create_class_node(coverage_file)
coverage_file.cleaned_gcov_data.split("\n").each do |line|
line_segments = line.split(':')
if coverage_file.coverage_for_line(line)
line_number = line_segments[1].strip.to_i
line_node = create_line_node(line, coverage_file)
line_node.parent = lines_node
end
end
class_node['branch-rate'] = '%.16f' % [coverage_file.rate_branches_tested]
class_node['complexity'] = '0.0'
class_node
end

Expand Down
10 changes: 5 additions & 5 deletions spec/fixtures/cobertura.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<line number="43" branch="false" hits="2"/>
</lines>
</class>
<class name="Empty" filename="spec/fixtures/fixtures/more_files/Empty.m" line-rate="0.0000000000000000" branch-rate="0.0000000000000000" complexity="0.0">
<class name="Empty" filename="spec/fixtures/fixtures/more_files/Empty.m" line-rate="1.0000000000000000" branch-rate="1.0000000000000000" complexity="0.0">
<methods/>
<lines/>
</class>
Expand All @@ -69,9 +69,9 @@
</class>
</classes>
</package>
<package name="spec.fixtures.fixtures" line-rate="0.5000000000000000" branch-rate="NaN" complexity="0.0">
<package name="spec.fixtures.fixtures" line-rate="0.5000000000000000" branch-rate="1.0000000000000000" complexity="0.0">
<classes>
<class name="fixtures" filename="spec/fixtures/fixtures/fixtures.m" line-rate="0.5000000000000000" branch-rate="0.0000000000000000" complexity="0.0">
<class name="fixtures" filename="spec/fixtures/fixtures/fixtures.m" line-rate="0.5000000000000000" branch-rate="1.0000000000000000" complexity="0.0">
<methods/>
<lines>
<line number="15" branch="false" hits="1"/>
Expand All @@ -84,7 +84,7 @@
</package>
<package name="spec.fixtures.fixturesTests" line-rate="1.0000000000000000" branch-rate="0.0333333333333333" complexity="0.0">
<classes>
<class name="BranchesTests" filename="spec/fixtures/fixturesTests/BranchesTests.m" line-rate="1.0000000000000000" branch-rate="0.0000000000000000" complexity="0.0">
<class name="BranchesTests" filename="spec/fixtures/fixturesTests/BranchesTests.m" line-rate="1.0000000000000000" branch-rate="1.0000000000000000" complexity="0.0">
<methods/>
<lines>
<line number="19" branch="false" hits="2"/>
Expand All @@ -99,7 +99,7 @@
<line number="36" branch="false" hits="1"/>
</lines>
</class>
<class name="fixturesTests" filename="spec/fixtures/fixturesTests/fixturesTests.m" line-rate="1.0000000000000000" branch-rate="0.0000000000000000" complexity="0.0">
<class name="fixturesTests" filename="spec/fixtures/fixturesTests/fixturesTests.m" line-rate="1.0000000000000000" branch-rate="1.0000000000000000" complexity="0.0">
<methods/>
<lines>
<line number="20" branch="false" hits="1"/>
Expand Down