simplecov-cobertura 1.4.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +28 -0
- data/.gitignore +1 -1
- data/README.md +4 -20
- data/lib/simplecov-cobertura/version.rb +1 -1
- data/lib/simplecov-cobertura.rb +124 -72
- data/simplecov-cobertura.gemspec +4 -11
- data/test/coverage/coverage.xml +21 -0
- data/test/simplecov-cobertura_test.rb +67 -32
- metadata +29 -13
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c2d0c9eebf10fae25ce491aa5b33fd744cb72c8bd3b9645706e8b6f35495e88
|
4
|
+
data.tar.gz: 8890ee7ca2a87b49a4f37ee049bbb6d9375f5ead377bc2e3e32ee793883f56a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce64fbbd3eb2986a45d90800573739d5f558162a8a66223007926a799e0ba082c4393a7eae1974fe8f40c7b1a22b1f3bebe3adb696805a29a2206c7c5a0b6a21
|
7
|
+
data.tar.gz: ed1e556b151833e2db0eeb4a2e8a0539946f80af3a3a85429e708a119065def438032eb660437367f1bd34c91eb1d75d7636ca3958844ca83249ef433080eb6d
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Build
|
9
|
+
|
10
|
+
on: [push, pull_request]
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby-version: [2.5, 2.6, 2.7, 3.0]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby-version }}
|
26
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
27
|
+
- name: Run tests
|
28
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# simplecov-cobertura
|
2
|
-
[![Build
|
2
|
+
[![Build](https://github.com/dashingrocket/simplecov-cobertura/actions/workflows/build.yml/badge.svg)](https://github.com/dashingrocket/simplecov-cobertura/actions/workflows/build.yml) [![Gem Version](https://badge.fury.io/rb/simplecov-cobertura.svg)](http://badge.fury.io/rb/simplecov-cobertura) [![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/simplecov-cobertura?type=total)](https://rubygems.org/gems/simplecov-cobertura)
|
3
|
+
|
3
4
|
|
4
5
|
Produces [Cobertura](http://cobertura.sourceforge.net/) formatted XML from [SimpleCov](https://github.com/colszowka/simplecov).
|
5
6
|
|
@@ -32,27 +33,10 @@ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
|
32
33
|
|
33
34
|
## Continuous Integration
|
34
35
|
Tested in a CI environment against the following Ruby versions:
|
36
|
+
* 3.0
|
35
37
|
* 2.7
|
36
38
|
* 2.6
|
37
39
|
* 2.5
|
38
|
-
* 2.4
|
39
|
-
* 2.3
|
40
|
-
* 2.2
|
41
|
-
* 2.1
|
42
|
-
* 2.0
|
43
|
-
* 1.9
|
44
|
-
|
45
|
-
## Known Limitations
|
46
|
-
* No support for branch coverage
|
47
|
-
|
48
|
-
## Contributors
|
49
|
-
* Jesse Bowes
|
50
|
-
* Sean Clemmer
|
51
|
-
* Ivailo Petrov
|
52
|
-
* Rob Lester
|
53
|
-
* Denis <Zaratan> Pasin
|
54
|
-
* Jesper Rønn-Jensen
|
55
|
-
* Pramod Shinde
|
56
40
|
|
57
41
|
## Contributing
|
58
42
|
|
@@ -63,7 +47,7 @@ Tested in a CI environment against the following Ruby versions:
|
|
63
47
|
5. Create a new Pull Request
|
64
48
|
|
65
49
|
## License
|
66
|
-
Copyright
|
50
|
+
Copyright 2021 Dashing Rocket, Ltd.
|
67
51
|
|
68
52
|
Licensed under the Apache License, Version 2.0 (the "License");
|
69
53
|
you may not use this file except in compliance with the License.
|
data/lib/simplecov-cobertura.rb
CHANGED
@@ -2,6 +2,7 @@ require 'simplecov'
|
|
2
2
|
|
3
3
|
require 'rexml/document'
|
4
4
|
require 'rexml/element'
|
5
|
+
require 'pathname'
|
5
6
|
|
6
7
|
require_relative 'simplecov-cobertura/version'
|
7
8
|
|
@@ -11,9 +12,13 @@ module SimpleCov
|
|
11
12
|
RESULT_FILE_NAME = 'coverage.xml'
|
12
13
|
DTD_URL = 'http://cobertura.sourceforge.net/xml/coverage-04.dtd'
|
13
14
|
|
15
|
+
def initialize(result_file_name: RESULT_FILE_NAME)
|
16
|
+
@result_file_name = result_file_name
|
17
|
+
end
|
18
|
+
|
14
19
|
def format(result)
|
15
20
|
xml_doc = result_to_xml result
|
16
|
-
result_path = File.join(SimpleCov.coverage_path,
|
21
|
+
result_path = File.join(SimpleCov.coverage_path, @result_file_name)
|
17
22
|
|
18
23
|
formatter = REXML::Formatters::Pretty.new
|
19
24
|
formatter.compact = true
|
@@ -27,97 +32,144 @@ module SimpleCov
|
|
27
32
|
end
|
28
33
|
|
29
34
|
private
|
30
|
-
def result_to_xml(result)
|
31
|
-
doc = REXML::Document.new set_xml_head
|
32
|
-
doc.context[:attribute_quote] = :quote
|
33
|
-
doc.add_element REXML::Element.new('coverage')
|
34
|
-
coverage = doc.root
|
35
35
|
|
36
|
-
|
36
|
+
def result_to_xml(result)
|
37
|
+
doc = REXML::Document.new set_xml_head
|
38
|
+
doc.context[:attribute_quote] = :quote
|
39
|
+
doc.add_element REXML::Element.new('coverage')
|
40
|
+
coverage = doc.root
|
37
41
|
|
38
|
-
|
39
|
-
sources.add_element(source = REXML::Element.new('source'))
|
40
|
-
source.text = SimpleCov.root
|
42
|
+
set_coverage_attributes(coverage, result)
|
41
43
|
|
42
|
-
|
44
|
+
coverage.add_element(sources = REXML::Element.new('sources'))
|
45
|
+
sources.add_element(source = REXML::Element.new('source'))
|
46
|
+
source.text = SimpleCov.root
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
coverage.add_element(packages = REXML::Element.new('packages'))
|
49
|
+
|
50
|
+
if result.groups.empty?
|
51
|
+
groups = {File.basename(SimpleCov.root) => result.files}
|
52
|
+
else
|
53
|
+
groups = result.groups
|
54
|
+
end
|
49
55
|
|
50
|
-
|
51
|
-
|
52
|
-
|
56
|
+
groups.each do |name, files|
|
57
|
+
next if files.empty?
|
58
|
+
packages.add_element(package = REXML::Element.new('package'))
|
59
|
+
set_package_attributes(package, name, files)
|
53
60
|
|
54
|
-
|
61
|
+
package.add_element(classes = REXML::Element.new('classes'))
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
63
|
+
files.each do |file|
|
64
|
+
classes.add_element(class_ = REXML::Element.new('class'))
|
65
|
+
set_class_attributes(class_, file)
|
59
66
|
|
60
|
-
|
61
|
-
|
67
|
+
class_.add_element(REXML::Element.new('methods'))
|
68
|
+
class_.add_element(lines = REXML::Element.new('lines'))
|
62
69
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
branched_lines = file.branches.map(&:start_line)
|
71
|
+
branched_lines_covered = file.covered_branches.map(&:start_line)
|
72
|
+
|
73
|
+
file.lines.each do |file_line|
|
74
|
+
if file_line.covered? || file_line.missed?
|
75
|
+
lines.add_element(line = REXML::Element.new('line'))
|
76
|
+
set_line_attributes(line, file_line)
|
77
|
+
set_branch_attributes(line, file_line, branched_lines, branched_lines_covered) if SimpleCov.branch_coverage?
|
78
|
+
end
|
67
79
|
end
|
68
80
|
end
|
69
81
|
end
|
82
|
+
|
83
|
+
doc
|
70
84
|
end
|
71
85
|
|
72
|
-
|
73
|
-
|
86
|
+
def set_coverage_attributes(coverage, result)
|
87
|
+
ls = result.coverage_statistics[:line]
|
88
|
+
bs = result.coverage_statistics[:branch]
|
89
|
+
|
90
|
+
coverage.attributes['line-rate'] = extract_rate(ls.percent)
|
91
|
+
coverage.attributes['lines-covered'] = ls.covered.to_s.to_s
|
92
|
+
coverage.attributes['lines-valid'] = ls.total.to_s.to_s
|
93
|
+
if SimpleCov.branch_coverage?
|
94
|
+
coverage.attributes['branches-covered'] = bs.covered.to_s
|
95
|
+
coverage.attributes['branches-valid'] = bs.total.to_s
|
96
|
+
coverage.attributes['branch-rate'] = extract_rate(bs.percent)
|
97
|
+
end
|
98
|
+
coverage.attributes['complexity'] = '0'
|
99
|
+
coverage.attributes['version'] = '0'
|
100
|
+
coverage.attributes['timestamp'] = Time.now.to_i.to_s
|
101
|
+
end
|
74
102
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
coverage.attributes['lines-covered'] = result.covered_lines.to_s
|
79
|
-
coverage.attributes['lines-valid'] = (result.covered_lines + result.missed_lines).to_s
|
80
|
-
coverage.attributes['branches-covered'] = '0'
|
81
|
-
coverage.attributes['branches-valid'] = '0'
|
82
|
-
coverage.attributes['branch-rate'] = '0'
|
83
|
-
coverage.attributes['complexity'] = '0'
|
84
|
-
coverage.attributes['version'] = '0'
|
85
|
-
coverage.attributes['timestamp'] = Time.now.to_i.to_s
|
86
|
-
end
|
103
|
+
def set_package_attributes(package, name, result)
|
104
|
+
ls = result.coverage_statistics[:line]
|
105
|
+
bs = result.coverage_statistics[:branch]
|
87
106
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
107
|
+
package.attributes['name'] = name
|
108
|
+
package.attributes['line-rate'] = extract_rate(ls.percent)
|
109
|
+
if SimpleCov.branch_coverage?
|
110
|
+
package.attributes['branch-rate'] = extract_rate(bs.percent)
|
111
|
+
end
|
112
|
+
package.attributes['complexity'] = '0'
|
113
|
+
end
|
94
114
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
class_.attributes['name'] = File.basename(filename, '.*')
|
99
|
-
class_.attributes['filename'] = path
|
100
|
-
class_.attributes['line-rate'] = (file.covered_percent/100).round(2).to_s
|
101
|
-
class_.attributes['branch-rate'] = '0'
|
102
|
-
class_.attributes['complexity'] = '0'
|
103
|
-
end
|
115
|
+
def set_class_attributes(class_, file)
|
116
|
+
ls = file.coverage_statistics[:line]
|
117
|
+
bs = file.coverage_statistics[:branch]
|
104
118
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
119
|
+
filename = file.filename
|
120
|
+
class_.attributes['name'] = File.basename(filename, '.*')
|
121
|
+
class_.attributes['filename'] = resolve_filename(filename)
|
122
|
+
class_.attributes['line-rate'] = extract_rate(ls.percent)
|
123
|
+
if SimpleCov.branch_coverage?
|
124
|
+
class_.attributes['branch-rate'] = extract_rate(bs.percent)
|
125
|
+
end
|
126
|
+
class_.attributes['complexity'] = '0'
|
127
|
+
end
|
110
128
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
lines.join("\n")
|
116
|
-
end
|
129
|
+
def set_line_attributes(line, file_line)
|
130
|
+
line.attributes['number'] = file_line.line_number.to_s
|
131
|
+
line.attributes['hits'] = file_line.coverage.to_s
|
132
|
+
end
|
117
133
|
|
118
|
-
|
119
|
-
|
120
|
-
|
134
|
+
def set_branch_attributes(line, file_line, branched_lines, branched_lines_covered)
|
135
|
+
if branched_lines.include? file_line.number
|
136
|
+
pct_coverage, branches_covered = branched_lines_covered.include?(file_line.number) ? [100, '1/1'] : [0, '0/1']
|
137
|
+
line.attributes['branch'] = 'true'
|
138
|
+
line.attributes['condition-coverage'] = "#{pct_coverage}% (#{branches_covered})"
|
139
|
+
else
|
140
|
+
line.attributes['branch'] = 'false'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def set_xml_head(lines=[])
|
145
|
+
lines << "<?xml version=\"1.0\"?>"
|
146
|
+
lines << "<!DOCTYPE coverage SYSTEM \"#{DTD_URL}\">"
|
147
|
+
lines << "<!-- Generated by simplecov-cobertura version #{VERSION} (https://github.com/dashingrocket/simplecov-cobertura) -->"
|
148
|
+
lines.join("\n")
|
149
|
+
end
|
150
|
+
|
151
|
+
def coverage_output(result)
|
152
|
+
ls = result.coverage_statistics[:line]
|
153
|
+
bs = result.coverage_statistics[:branch]
|
154
|
+
|
155
|
+
if SimpleCov.branch_coverage?
|
156
|
+
"%d / %d LOC (%.2f%%) covered; %d / %d BC (%.2f%%) covered" % [ls.covered, ls.total, ls.percent, bs.covered, bs.total, bs.percent]
|
157
|
+
else
|
158
|
+
"%d / %d LOC (%.2f%%) covered" % [ls.covered, ls.total, ls.percent]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def resolve_filename(filename)
|
163
|
+
Pathname.new(filename).relative_path_from(project_root).to_s
|
164
|
+
end
|
165
|
+
|
166
|
+
def extract_rate(percent)
|
167
|
+
(percent / 100).round(2).to_s
|
168
|
+
end
|
169
|
+
|
170
|
+
def project_root
|
171
|
+
@project_root ||= Pathname.new(SimpleCov.root)
|
172
|
+
end
|
121
173
|
end
|
122
174
|
end
|
123
175
|
end
|
data/simplecov-cobertura.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = 'Produces Cobertura XML formatted output from SimpleCov'
|
14
14
|
spec.homepage = 'https://github.com/dashingrocket/simplecov-cobertura'
|
15
15
|
spec.license = 'Apache-2.0'
|
16
|
-
spec.required_ruby_version = '>=
|
16
|
+
spec.required_ruby_version = '>= 2.5.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0")
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -22,15 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency 'test-unit', '~> 3.2'
|
24
24
|
spec.add_development_dependency 'nokogiri', '~> 1.0'
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
25
26
|
|
26
|
-
spec.add_dependency 'simplecov', '~> 0.
|
27
|
-
|
28
|
-
if RUBY_VERSION < '2.0'
|
29
|
-
spec.add_dependency 'json', '< 2.3.0'
|
30
|
-
spec.add_development_dependency 'rake', '~> 12.0', '< 12.3'
|
31
|
-
elsif RUBY_VERSION < '2.2'
|
32
|
-
spec.add_development_dependency 'rake', '~> 12.0'
|
33
|
-
else
|
34
|
-
spec.add_development_dependency 'rake', '~> 13.0'
|
35
|
-
end
|
27
|
+
spec.add_dependency 'simplecov', '~> 0.19'
|
28
|
+
spec.add_dependency 'rexml'
|
36
29
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
|
3
|
+
<!-- Generated by simplecov-cobertura version 1.4.3-dev (https://github.com/dashingrocket/simplecov-cobertura) -->
|
4
|
+
<coverage line-rate="1.0" branch-rate="0" lines-covered="2" lines-valid="2" branches-covered="0" branches-valid="0" complexity="0" version="0" timestamp="1636204971">
|
5
|
+
<sources>
|
6
|
+
<source>/Users/st0012/projects/simplecov-cobertura/test</source>
|
7
|
+
</sources>
|
8
|
+
<packages>
|
9
|
+
<package name="test" line-rate="1.0" branch-rate="0" complexity="0">
|
10
|
+
<classes>
|
11
|
+
<class name="simplecov-cobertura_test" filename="simplecov-cobertura_test.rb" line-rate="1.0" branch-rate="0" complexity="0">
|
12
|
+
<methods/>
|
13
|
+
<lines>
|
14
|
+
<line number="1" branch="false" hits="1"/>
|
15
|
+
<line number="2" branch="false" hits="2"/>
|
16
|
+
</lines>
|
17
|
+
</class>
|
18
|
+
</classes>
|
19
|
+
</package>
|
20
|
+
</packages>
|
21
|
+
</coverage>
|
@@ -1,15 +1,26 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
|
3
2
|
require 'nokogiri'
|
4
|
-
|
5
3
|
require 'open-uri'
|
6
4
|
require 'simplecov'
|
7
5
|
require 'simplecov-cobertura'
|
8
6
|
|
9
7
|
class CoberturaFormatterTest < Test::Unit::TestCase
|
10
|
-
|
11
8
|
def setup
|
12
|
-
|
9
|
+
SimpleCov.enable_coverage :branch
|
10
|
+
SimpleCov.coverage_dir "tmp"
|
11
|
+
@result = SimpleCov::Result.new({
|
12
|
+
"#{__FILE__}" => {
|
13
|
+
"lines" => [1, 1, 1, nil, 1, nil, 1, 0, nil, 1, nil, nil, nil],
|
14
|
+
"branches" => {
|
15
|
+
[:if, 0, 3, 4, 3, 21] =>
|
16
|
+
{[:then, 1, 3, 4, 3, 10] => 0, [:else, 2, 3, 4, 3, 21] => 1},
|
17
|
+
[:if, 3, 5, 4, 5, 26] =>
|
18
|
+
{[:then, 4, 5, 16, 5, 20] => 1, [:else, 5, 5, 23, 5, 26] => 0},
|
19
|
+
[:if, 6, 7, 4, 11, 7] =>
|
20
|
+
{[:then, 7, 8, 6, 8, 10] => 0, [:else, 8, 10, 6, 10, 9] => 1}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
})
|
13
24
|
@formatter = SimpleCov::Formatter::CoberturaFormatter.new
|
14
25
|
end
|
15
26
|
|
@@ -24,6 +35,13 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
24
35
|
assert_equal(xml, IO.read(result_path))
|
25
36
|
end
|
26
37
|
|
38
|
+
def test_format_save_custom_filename
|
39
|
+
xml = SimpleCov::Formatter::CoberturaFormatter.new(result_file_name: 'cobertura.xml').format(@result)
|
40
|
+
result_path = File.join(SimpleCov.coverage_path, 'cobertura.xml')
|
41
|
+
assert_not_empty(xml)
|
42
|
+
assert_equal(xml, IO.read(result_path))
|
43
|
+
end
|
44
|
+
|
27
45
|
def test_terminal_output
|
28
46
|
output, _ = capture_output { @formatter.format(@result) }
|
29
47
|
result_path = File.join(SimpleCov.coverage_path, SimpleCov::Formatter::CoberturaFormatter::RESULT_FILE_NAME)
|
@@ -43,12 +61,12 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
43
61
|
doc = Nokogiri::XML::Document.parse(xml)
|
44
62
|
|
45
63
|
coverage = doc.xpath '/coverage'
|
46
|
-
assert_equal '
|
47
|
-
assert_equal '0', coverage.attribute('branch-rate').value
|
48
|
-
assert_equal '
|
49
|
-
assert_equal '
|
50
|
-
assert_equal '
|
51
|
-
assert_equal '
|
64
|
+
assert_equal '0.86', coverage.attribute('line-rate').value
|
65
|
+
assert_equal '0.5', coverage.attribute('branch-rate').value
|
66
|
+
assert_equal '6', coverage.attribute('lines-covered').value
|
67
|
+
assert_equal '7', coverage.attribute('lines-valid').value
|
68
|
+
assert_equal '3', coverage.attribute('branches-covered').value
|
69
|
+
assert_equal '6', coverage.attribute('branches-valid').value
|
52
70
|
assert_equal '0', coverage.attribute('complexity').value
|
53
71
|
assert_equal '0', coverage.attribute('version').value
|
54
72
|
assert_not_empty coverage.attribute('timestamp').value
|
@@ -61,8 +79,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
61
79
|
assert_equal 1, packages.length
|
62
80
|
package = packages.first
|
63
81
|
assert_equal 'simplecov-cobertura', package.attribute('name').value
|
64
|
-
assert_equal '
|
65
|
-
assert_equal '0', package.attribute('branch-rate').value
|
82
|
+
assert_equal '0.86', package.attribute('line-rate').value
|
83
|
+
assert_equal '0.5', package.attribute('branch-rate').value
|
66
84
|
assert_equal '0', package.attribute('complexity').value
|
67
85
|
|
68
86
|
classes = doc.xpath '/coverage/packages/package/classes/class'
|
@@ -70,20 +88,20 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
70
88
|
clazz = classes.first
|
71
89
|
assert_equal 'simplecov-cobertura_test', clazz.attribute('name').value
|
72
90
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('filename').value
|
73
|
-
assert_equal '
|
74
|
-
assert_equal '0', clazz.attribute('branch-rate').value
|
91
|
+
assert_equal '0.86', clazz.attribute('line-rate').value
|
92
|
+
assert_equal '0.5', clazz.attribute('branch-rate').value
|
75
93
|
assert_equal '0', clazz.attribute('complexity').value
|
76
94
|
|
77
95
|
lines = doc.xpath '/coverage/packages/package/classes/class/lines/line'
|
78
|
-
assert_equal
|
96
|
+
assert_equal 7, lines.length
|
79
97
|
first_line = lines.first
|
80
98
|
assert_equal '1', first_line.attribute('number').value
|
81
99
|
assert_equal 'false', first_line.attribute('branch').value
|
82
100
|
assert_equal '1', first_line.attribute('hits').value
|
83
101
|
last_line = lines.last
|
84
|
-
assert_equal '
|
85
|
-
assert_equal '
|
86
|
-
assert_equal '
|
102
|
+
assert_equal '10', last_line.attribute('number').value
|
103
|
+
assert_equal 'true', last_line.attribute('branch').value
|
104
|
+
assert_equal '1', last_line.attribute('hits').value
|
87
105
|
end
|
88
106
|
|
89
107
|
def test_groups
|
@@ -93,12 +111,12 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
93
111
|
doc = Nokogiri::XML::Document.parse(xml)
|
94
112
|
|
95
113
|
coverage = doc.xpath '/coverage'
|
96
|
-
assert_equal '
|
97
|
-
assert_equal '0', coverage.attribute('branch-rate').value
|
98
|
-
assert_equal '
|
99
|
-
assert_equal '
|
100
|
-
assert_equal '
|
101
|
-
assert_equal '
|
114
|
+
assert_equal '0.86', coverage.attribute('line-rate').value
|
115
|
+
assert_equal '0.5', coverage.attribute('branch-rate').value
|
116
|
+
assert_equal '6', coverage.attribute('lines-covered').value
|
117
|
+
assert_equal '7', coverage.attribute('lines-valid').value
|
118
|
+
assert_equal '3', coverage.attribute('branches-covered').value
|
119
|
+
assert_equal '6', coverage.attribute('branches-valid').value
|
102
120
|
assert_equal '0', coverage.attribute('complexity').value
|
103
121
|
assert_equal '0', coverage.attribute('version').value
|
104
122
|
assert_not_empty coverage.attribute('timestamp').value
|
@@ -111,8 +129,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
111
129
|
assert_equal 1, packages.length
|
112
130
|
package = packages.first
|
113
131
|
assert_equal 'test_group', package.attribute('name').value
|
114
|
-
assert_equal '
|
115
|
-
assert_equal '0', package.attribute('branch-rate').value
|
132
|
+
assert_equal '0.86', package.attribute('line-rate').value
|
133
|
+
assert_equal '0.5', package.attribute('branch-rate').value
|
116
134
|
assert_equal '0', package.attribute('complexity').value
|
117
135
|
|
118
136
|
classes = doc.xpath '/coverage/packages/package/classes/class'
|
@@ -120,19 +138,36 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
120
138
|
clazz = classes.first
|
121
139
|
assert_equal 'simplecov-cobertura_test', clazz.attribute('name').value
|
122
140
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('filename').value
|
123
|
-
assert_equal '
|
124
|
-
assert_equal '0', clazz.attribute('branch-rate').value
|
141
|
+
assert_equal '0.86', clazz.attribute('line-rate').value
|
142
|
+
assert_equal '0.5', clazz.attribute('branch-rate').value
|
125
143
|
assert_equal '0', clazz.attribute('complexity').value
|
126
144
|
|
127
145
|
lines = doc.xpath '/coverage/packages/package/classes/class/lines/line'
|
128
|
-
assert_equal
|
146
|
+
assert_equal 7, lines.length
|
129
147
|
first_line = lines.first
|
130
148
|
assert_equal '1', first_line.attribute('number').value
|
131
149
|
assert_equal 'false', first_line.attribute('branch').value
|
132
150
|
assert_equal '1', first_line.attribute('hits').value
|
133
151
|
last_line = lines.last
|
134
|
-
assert_equal '
|
135
|
-
assert_equal '
|
136
|
-
assert_equal '
|
152
|
+
assert_equal '10', last_line.attribute('number').value
|
153
|
+
assert_equal 'true', last_line.attribute('branch').value
|
154
|
+
assert_equal '1', last_line.attribute('hits').value
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_supports_root_project_path
|
158
|
+
old_root = SimpleCov.root
|
159
|
+
SimpleCov.root("/tmp")
|
160
|
+
expected_base = old_root[1..-1] # Remove leading "/"
|
161
|
+
|
162
|
+
xml = @formatter.format(@result)
|
163
|
+
doc = Nokogiri::XML::Document.parse(xml)
|
164
|
+
|
165
|
+
classes = doc.xpath '/coverage/packages/package/classes/class'
|
166
|
+
assert_equal 1, classes.length
|
167
|
+
clazz = classes.first
|
168
|
+
assert_equal 'simplecov-cobertura_test', clazz.attribute('name').value
|
169
|
+
assert_equal "../#{expected_base}/test/simplecov-cobertura_test.rb", clazz.attribute('filename').value
|
170
|
+
ensure
|
171
|
+
SimpleCov.root(old_root)
|
137
172
|
end
|
138
173
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplecov-cobertura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Bowes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -39,33 +39,47 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
48
|
-
type: :
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
61
|
+
version: '0.19'
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.19'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rexml
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Produces Cobertura XML formatted output from SimpleCov
|
70
84
|
email:
|
71
85
|
- jbowes@dashingrocket.com
|
@@ -73,8 +87,8 @@ executables: []
|
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
90
|
+
- ".github/workflows/build.yml"
|
76
91
|
- ".gitignore"
|
77
|
-
- ".travis.yml"
|
78
92
|
- Gemfile
|
79
93
|
- LICENSE
|
80
94
|
- README.md
|
@@ -82,6 +96,7 @@ files:
|
|
82
96
|
- lib/simplecov-cobertura.rb
|
83
97
|
- lib/simplecov-cobertura/version.rb
|
84
98
|
- simplecov-cobertura.gemspec
|
99
|
+
- test/coverage/coverage.xml
|
85
100
|
- test/simplecov-cobertura_test.rb
|
86
101
|
homepage: https://github.com/dashingrocket/simplecov-cobertura
|
87
102
|
licenses:
|
@@ -95,16 +110,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
110
|
requirements:
|
96
111
|
- - ">="
|
97
112
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
113
|
+
version: 2.5.0
|
99
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
115
|
requirements:
|
101
116
|
- - ">="
|
102
117
|
- !ruby/object:Gem::Version
|
103
118
|
version: '0'
|
104
119
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.2.22
|
106
121
|
signing_key:
|
107
122
|
specification_version: 4
|
108
123
|
summary: SimpleCov Cobertura Formatter
|
109
124
|
test_files:
|
125
|
+
- test/coverage/coverage.xml
|
110
126
|
- test/simplecov-cobertura_test.rb
|