simplecov-cobertura 3.0.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +2 -2
- data/lib/simplecov-cobertura/version.rb +1 -1
- data/lib/simplecov-cobertura.rb +24 -16
- data/test/simplecov-cobertura_test.rb +35 -17
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d9b68c5aa76db30753de21b0db6f942c58e0ccc41c7f77d73881215faf7bbf31
|
|
4
|
+
data.tar.gz: 19b8626568d444dc368bd9a4fad5747c78c0cb4583c0d44d074994e671d4ceab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9cd6c9bf87b3da4df600bd3c3754ed66581802eb5d46b691119f605af7707f23a14af37fba5a67f524bf36380540f259ca2f3479ee0d651d5fd8cd0c6e0f3ffd
|
|
7
|
+
data.tar.gz: 4308ed2698f5bd7c3afc7c319a6a231aa1ea501f312282fd73f9650062d34d7492e26e8cb86d127a779f11c2fbb89a80c06dc6638e063e3c7bdf219a2356f6f8
|
data/.github/workflows/build.yml
CHANGED
|
@@ -15,10 +15,10 @@ jobs:
|
|
|
15
15
|
runs-on: ubuntu-latest
|
|
16
16
|
strategy:
|
|
17
17
|
matrix:
|
|
18
|
-
ruby-version: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4]
|
|
18
|
+
ruby-version: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4, 4.0]
|
|
19
19
|
|
|
20
20
|
steps:
|
|
21
|
-
- uses: actions/checkout@
|
|
21
|
+
- uses: actions/checkout@v6
|
|
22
22
|
- name: Set up Ruby
|
|
23
23
|
uses: ruby/setup-ruby@v1
|
|
24
24
|
with:
|
data/lib/simplecov-cobertura.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
require 'stringio'
|
|
1
2
|
require 'rexml/document'
|
|
2
3
|
require 'rexml/element'
|
|
3
4
|
require 'pathname'
|
|
5
|
+
require 'simplecov'
|
|
4
6
|
|
|
5
7
|
require_relative 'simplecov-cobertura/version'
|
|
6
8
|
|
|
@@ -33,8 +35,11 @@ module SimpleCov
|
|
|
33
35
|
private
|
|
34
36
|
|
|
35
37
|
def result_to_xml(result)
|
|
36
|
-
doc = REXML::Document.new
|
|
38
|
+
doc = REXML::Document.new
|
|
37
39
|
doc.context[:attribute_quote] = :quote
|
|
40
|
+
doc << REXML::XMLDecl.new('1.0')
|
|
41
|
+
doc << REXML::DocType.new('coverage', "SYSTEM \"#{DTD_URL}\"")
|
|
42
|
+
doc << REXML::Comment.new("Generated by simplecov-cobertura version #{VERSION} (https://github.com/jessebs/simplecov-cobertura)")
|
|
38
43
|
doc.add_element REXML::Element.new('coverage')
|
|
39
44
|
coverage = doc.root
|
|
40
45
|
|
|
@@ -66,14 +71,21 @@ module SimpleCov
|
|
|
66
71
|
class_.add_element(REXML::Element.new('methods'))
|
|
67
72
|
class_.add_element(lines = REXML::Element.new('lines'))
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
branches_by_line = {}
|
|
75
|
+
if SimpleCov.branch_coverage?
|
|
76
|
+
file.branches.each do |branch|
|
|
77
|
+
line_no = branch.start_line
|
|
78
|
+
branches_by_line[line_no] ||= { total: 0, covered: 0 }
|
|
79
|
+
branches_by_line[line_no][:total] += 1
|
|
80
|
+
branches_by_line[line_no][:covered] += 1 if branch.covered?
|
|
81
|
+
end
|
|
82
|
+
end
|
|
71
83
|
|
|
72
84
|
file.lines.each do |file_line|
|
|
73
85
|
if file_line.covered? || file_line.missed?
|
|
74
86
|
lines.add_element(line = REXML::Element.new('line'))
|
|
75
87
|
set_line_attributes(line, file_line)
|
|
76
|
-
set_branch_attributes(line, file_line,
|
|
88
|
+
set_branch_attributes(line, file_line, branches_by_line) if SimpleCov.branch_coverage?
|
|
77
89
|
end
|
|
78
90
|
end
|
|
79
91
|
end
|
|
@@ -130,23 +142,19 @@ module SimpleCov
|
|
|
130
142
|
line.attributes['hits'] = file_line.coverage.to_s
|
|
131
143
|
end
|
|
132
144
|
|
|
133
|
-
def set_branch_attributes(line, file_line,
|
|
134
|
-
|
|
135
|
-
|
|
145
|
+
def set_branch_attributes(line, file_line, branches_by_line)
|
|
146
|
+
branch_info = branches_by_line[file_line.number]
|
|
147
|
+
if branch_info
|
|
148
|
+
total = branch_info[:total]
|
|
149
|
+
covered = branch_info[:covered]
|
|
150
|
+
pct_coverage = total > 0 ? (covered * 100 / total) : 0
|
|
136
151
|
line.attributes['branch'] = 'true'
|
|
137
|
-
line.attributes['condition-coverage'] = "#{pct_coverage}% (#{
|
|
152
|
+
line.attributes['condition-coverage'] = "#{pct_coverage}% (#{covered}/#{total})"
|
|
138
153
|
else
|
|
139
154
|
line.attributes['branch'] = 'false'
|
|
140
155
|
end
|
|
141
156
|
end
|
|
142
157
|
|
|
143
|
-
def set_xml_head(lines=[])
|
|
144
|
-
lines << "<?xml version=\"1.0\"?>"
|
|
145
|
-
lines << "<!DOCTYPE coverage SYSTEM \"#{DTD_URL}\">"
|
|
146
|
-
lines << "<!-- Generated by simplecov-cobertura version #{VERSION} (https://github.com/jessebs/simplecov-cobertura) -->"
|
|
147
|
-
lines.join("\n")
|
|
148
|
-
end
|
|
149
|
-
|
|
150
158
|
# Roughly mirrors private method SimpleCov::Formatter::HTMLFormatter#output_coverage
|
|
151
159
|
def output_message(result, output_path)
|
|
152
160
|
output = "Coverage report generated for #{result.command_name} to #{output_path}."
|
|
@@ -160,7 +168,7 @@ module SimpleCov
|
|
|
160
168
|
end
|
|
161
169
|
|
|
162
170
|
def extract_rate(percent)
|
|
163
|
-
(percent / 100).round(
|
|
171
|
+
(percent / 100).round(4).to_s
|
|
164
172
|
end
|
|
165
173
|
|
|
166
174
|
def project_root
|
|
@@ -17,7 +17,13 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
17
17
|
[:if, 3, 5, 4, 5, 26] =>
|
|
18
18
|
{[:then, 4, 5, 16, 5, 20] => 1, [:else, 5, 5, 23, 5, 26] => 0},
|
|
19
19
|
[:if, 6, 7, 4, 11, 7] =>
|
|
20
|
-
{[:then, 7, 8, 6, 8, 10] => 0, [:else, 8, 10, 6, 10, 9] => 1}
|
|
20
|
+
{[:then, 7, 8, 6, 8, 10] => 0, [:else, 8, 10, 6, 10, 9] => 1},
|
|
21
|
+
[:if, 9, 12, 4, 12, 15] =>
|
|
22
|
+
{[:then, 10, 12, 6, 12, 10] => 1, [:else, 11, 12, 13, 12, 15] => 0},
|
|
23
|
+
[:if, 12, 13, 4, 13, 20] =>
|
|
24
|
+
{[:then, 13, 13, 6, 13, 15] => 1, [:else, 14, 13, 18, 13, 20] => 0},
|
|
25
|
+
[:if, 15, 15, 4, 15, 25] =>
|
|
26
|
+
{[:then, 16, 15, 6, 15, 20] => 0, [:else, 17, 15, 23, 15, 25] => 0}
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
})
|
|
@@ -65,12 +71,12 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
65
71
|
doc = Nokogiri::XML::Document.parse(xml)
|
|
66
72
|
|
|
67
73
|
coverage = doc.xpath '/coverage'
|
|
68
|
-
assert_equal '0.
|
|
69
|
-
assert_equal '0.
|
|
74
|
+
assert_equal '0.8571', coverage.attribute('line-rate').value
|
|
75
|
+
assert_equal '0.4167', coverage.attribute('branch-rate').value
|
|
70
76
|
assert_equal '6', coverage.attribute('lines-covered').value
|
|
71
77
|
assert_equal '7', coverage.attribute('lines-valid').value
|
|
72
|
-
assert_equal '
|
|
73
|
-
assert_equal '
|
|
78
|
+
assert_equal '5', coverage.attribute('branches-covered').value
|
|
79
|
+
assert_equal '12', coverage.attribute('branches-valid').value
|
|
74
80
|
assert_equal '0', coverage.attribute('complexity').value
|
|
75
81
|
assert_equal '0', coverage.attribute('version').value
|
|
76
82
|
assert_not_empty coverage.attribute('timestamp').value
|
|
@@ -83,8 +89,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
83
89
|
assert_equal 1, packages.length
|
|
84
90
|
package = packages.first
|
|
85
91
|
assert_equal 'simplecov-cobertura', package.attribute('name').value
|
|
86
|
-
assert_equal '0.
|
|
87
|
-
assert_equal '0.
|
|
92
|
+
assert_equal '0.8571', package.attribute('line-rate').value
|
|
93
|
+
assert_equal '0.4167', package.attribute('branch-rate').value
|
|
88
94
|
assert_equal '0', package.attribute('complexity').value
|
|
89
95
|
|
|
90
96
|
classes = doc.xpath '/coverage/packages/package/classes/class'
|
|
@@ -92,8 +98,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
92
98
|
clazz = classes.first
|
|
93
99
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('name').value
|
|
94
100
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('filename').value
|
|
95
|
-
assert_equal '0.
|
|
96
|
-
assert_equal '0.
|
|
101
|
+
assert_equal '0.8571', clazz.attribute('line-rate').value
|
|
102
|
+
assert_equal '0.4167', clazz.attribute('branch-rate').value
|
|
97
103
|
assert_equal '0', clazz.attribute('complexity').value
|
|
98
104
|
|
|
99
105
|
lines = doc.xpath '/coverage/packages/package/classes/class/lines/line'
|
|
@@ -106,6 +112,18 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
106
112
|
assert_equal '10', last_line.attribute('number').value
|
|
107
113
|
assert_equal 'true', last_line.attribute('branch').value
|
|
108
114
|
assert_equal '1', last_line.attribute('hits').value
|
|
115
|
+
|
|
116
|
+
# Verify condition-coverage accurately reflects branch counts per line
|
|
117
|
+
branched_lines = lines.select { |l| l.attribute('branch').value == 'true' }
|
|
118
|
+
condition_coverages = branched_lines.map { |l| [l.attribute('number').value, l.attribute('condition-coverage').value] }
|
|
119
|
+
# Line 3: 2 branches (then=>0, else=>1) => 50% (1/2)
|
|
120
|
+
assert_include condition_coverages, ['3', '50% (1/2)']
|
|
121
|
+
# Line 5: 2 branches (then=>1, else=>0) => 50% (1/2)
|
|
122
|
+
assert_include condition_coverages, ['5', '50% (1/2)']
|
|
123
|
+
# Line 8: 1 branch (then=>0) => 0% (0/1)
|
|
124
|
+
assert_include condition_coverages, ['8', '0% (0/1)']
|
|
125
|
+
# Line 10: 1 branch (else=>1) => 100% (1/1)
|
|
126
|
+
assert_include condition_coverages, ['10', '100% (1/1)']
|
|
109
127
|
end
|
|
110
128
|
|
|
111
129
|
def test_groups
|
|
@@ -115,12 +133,12 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
115
133
|
doc = Nokogiri::XML::Document.parse(xml)
|
|
116
134
|
|
|
117
135
|
coverage = doc.xpath '/coverage'
|
|
118
|
-
assert_equal '0.
|
|
119
|
-
assert_equal '0.
|
|
136
|
+
assert_equal '0.8571', coverage.attribute('line-rate').value
|
|
137
|
+
assert_equal '0.4167', coverage.attribute('branch-rate').value
|
|
120
138
|
assert_equal '6', coverage.attribute('lines-covered').value
|
|
121
139
|
assert_equal '7', coverage.attribute('lines-valid').value
|
|
122
|
-
assert_equal '
|
|
123
|
-
assert_equal '
|
|
140
|
+
assert_equal '5', coverage.attribute('branches-covered').value
|
|
141
|
+
assert_equal '12', coverage.attribute('branches-valid').value
|
|
124
142
|
assert_equal '0', coverage.attribute('complexity').value
|
|
125
143
|
assert_equal '0', coverage.attribute('version').value
|
|
126
144
|
assert_not_empty coverage.attribute('timestamp').value
|
|
@@ -133,8 +151,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
133
151
|
assert_equal 1, packages.length
|
|
134
152
|
package = packages.first
|
|
135
153
|
assert_equal 'test_group', package.attribute('name').value
|
|
136
|
-
assert_equal '0.
|
|
137
|
-
assert_equal '0.
|
|
154
|
+
assert_equal '0.8571', package.attribute('line-rate').value
|
|
155
|
+
assert_equal '0.4167', package.attribute('branch-rate').value
|
|
138
156
|
assert_equal '0', package.attribute('complexity').value
|
|
139
157
|
|
|
140
158
|
classes = doc.xpath '/coverage/packages/package/classes/class'
|
|
@@ -142,8 +160,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
|
142
160
|
clazz = classes.first
|
|
143
161
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('name').value
|
|
144
162
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('filename').value
|
|
145
|
-
assert_equal '0.
|
|
146
|
-
assert_equal '0.
|
|
163
|
+
assert_equal '0.8571', clazz.attribute('line-rate').value
|
|
164
|
+
assert_equal '0.4167', clazz.attribute('branch-rate').value
|
|
147
165
|
assert_equal '0', clazz.attribute('complexity').value
|
|
148
166
|
|
|
149
167
|
lines = doc.xpath '/coverage/packages/package/classes/class/lines/line'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simplecov-cobertura
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jesse Bowes
|
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
114
114
|
- !ruby/object:Gem::Version
|
|
115
115
|
version: '0'
|
|
116
116
|
requirements: []
|
|
117
|
-
rubygems_version: 3.6.
|
|
117
|
+
rubygems_version: 3.6.9
|
|
118
118
|
specification_version: 4
|
|
119
119
|
summary: SimpleCov Cobertura Formatter
|
|
120
120
|
test_files:
|