simplecov-cobertura 3.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04ae07cb7f6bb85ad36640169b7d630c985ca1d3d067ef3485ea531b7b775209
4
- data.tar.gz: 42f5899bf07710880548d48a27d8d59d2eef1b4d10a05374c44e4344f8f0ac54
3
+ metadata.gz: d9b68c5aa76db30753de21b0db6f942c58e0ccc41c7f77d73881215faf7bbf31
4
+ data.tar.gz: 19b8626568d444dc368bd9a4fad5747c78c0cb4583c0d44d074994e671d4ceab
5
5
  SHA512:
6
- metadata.gz: e35c59ec78263fe81826f47b83ff5e160e08bf8aa4e01a01b943d1671974c853737e4742e5073997e4ac40d77f54f4f29a1f3d29b17a8e93021432c3f7814fc1
7
- data.tar.gz: b320d8920cfb8a354031628b045077387474fb07511547cc14f277a00362fcd34ef9974dfb0464cda308f5f167e0c3c3c4bbf932b3608e463bc948dbeb0696da
6
+ metadata.gz: 9cd6c9bf87b3da4df600bd3c3754ed66581802eb5d46b691119f605af7707f23a14af37fba5a67f524bf36380540f259ca2f3479ee0d651d5fd8cd0c6e0f3ffd
7
+ data.tar.gz: 4308ed2698f5bd7c3afc7c319a6a231aa1ea501f312282fd73f9650062d34d7492e26e8cb86d127a779f11c2fbb89a80c06dc6638e063e3c7bdf219a2356f6f8
@@ -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@v2
21
+ - uses: actions/checkout@v6
22
22
  - name: Set up Ruby
23
23
  uses: ruby/setup-ruby@v1
24
24
  with:
@@ -1,7 +1,7 @@
1
1
  module SimpleCov
2
2
  module Formatter
3
3
  class CoberturaFormatter
4
- VERSION = '3.1.0'
4
+ VERSION = '3.1.2'
5
5
  end
6
6
  end
7
7
  end
@@ -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
 
@@ -69,14 +71,21 @@ module SimpleCov
69
71
  class_.add_element(REXML::Element.new('methods'))
70
72
  class_.add_element(lines = REXML::Element.new('lines'))
71
73
 
72
- branched_lines = file.branches.map(&:start_line)
73
- branched_lines_covered = file.covered_branches.map(&:start_line)
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
74
83
 
75
84
  file.lines.each do |file_line|
76
85
  if file_line.covered? || file_line.missed?
77
86
  lines.add_element(line = REXML::Element.new('line'))
78
87
  set_line_attributes(line, file_line)
79
- set_branch_attributes(line, file_line, branched_lines, branched_lines_covered) if SimpleCov.branch_coverage?
88
+ set_branch_attributes(line, file_line, branches_by_line) if SimpleCov.branch_coverage?
80
89
  end
81
90
  end
82
91
  end
@@ -133,11 +142,14 @@ module SimpleCov
133
142
  line.attributes['hits'] = file_line.coverage.to_s
134
143
  end
135
144
 
136
- def set_branch_attributes(line, file_line, branched_lines, branched_lines_covered)
137
- if branched_lines.include? file_line.number
138
- pct_coverage, branches_covered = branched_lines_covered.include?(file_line.number) ? [100, '1/1'] : [0, '0/1']
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
139
151
  line.attributes['branch'] = 'true'
140
- line.attributes['condition-coverage'] = "#{pct_coverage}% (#{branches_covered})"
152
+ line.attributes['condition-coverage'] = "#{pct_coverage}% (#{covered}/#{total})"
141
153
  else
142
154
  line.attributes['branch'] = 'false'
143
155
  end
@@ -112,6 +112,18 @@ class CoberturaFormatterTest < Test::Unit::TestCase
112
112
  assert_equal '10', last_line.attribute('number').value
113
113
  assert_equal 'true', last_line.attribute('branch').value
114
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)']
115
127
  end
116
128
 
117
129
  def test_groups
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.1.0
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.7
117
+ rubygems_version: 3.6.9
118
118
  specification_version: 4
119
119
  summary: SimpleCov Cobertura Formatter
120
120
  test_files: