simplecov-cobertura 1.3.1 → 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 +5 -19
- data/lib/simplecov-cobertura/version.rb +1 -1
- data/lib/simplecov-cobertura.rb +126 -70
- data/simplecov-cobertura.gemspec +4 -3
- data/test/coverage/coverage.xml +21 -0
- data/test/simplecov-cobertura_test.rb +75 -33
- metadata +32 -17
- data/shippable.yml +0 -16
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
|
-
[![
|
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,25 +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
|
37
|
+
* 2.7
|
35
38
|
* 2.6
|
36
39
|
* 2.5
|
37
|
-
* 2.4
|
38
|
-
* 2.3
|
39
|
-
* 2.2
|
40
|
-
* 2.1
|
41
|
-
* 2.0
|
42
|
-
* 1.9
|
43
|
-
|
44
|
-
## Known Limitations
|
45
|
-
* No support for branch coverage
|
46
|
-
|
47
|
-
## Contributors
|
48
|
-
* Jesse Bowes
|
49
|
-
* Sean Clemmer
|
50
|
-
* Ivailo Petrov
|
51
|
-
* Rob Lester
|
52
|
-
* Denis <Zaratan> Pasin
|
53
|
-
* Jesper Rønn-Jensen
|
54
40
|
|
55
41
|
## Contributing
|
56
42
|
|
@@ -61,7 +47,7 @@ Tested in a CI environment against the following Ruby versions:
|
|
61
47
|
5. Create a new Pull Request
|
62
48
|
|
63
49
|
## License
|
64
|
-
Copyright
|
50
|
+
Copyright 2021 Dashing Rocket, Ltd.
|
65
51
|
|
66
52
|
Licensed under the Apache License, Version 2.0 (the "License");
|
67
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
|
@@ -22,98 +27,149 @@ module SimpleCov
|
|
22
27
|
|
23
28
|
xml_str = string_io.string
|
24
29
|
File.write(result_path, xml_str)
|
25
|
-
puts "Coverage report generated for #{result.command_name} to #{result_path}"
|
30
|
+
puts "Coverage report generated for #{result.command_name} to #{result_path}. #{coverage_output(result)}"
|
26
31
|
xml_str
|
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
|
-
|
116
|
-
|
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
|
133
|
+
|
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
|
117
173
|
end
|
118
174
|
end
|
119
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) }
|
@@ -21,8 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_development_dependency 'test-unit', '~> 3.2'
|
24
|
-
spec.add_development_dependency 'rake', '~> 12.0'
|
25
24
|
spec.add_development_dependency 'nokogiri', '~> 1.0'
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
26
26
|
|
27
|
-
spec.add_dependency 'simplecov', '~> 0.
|
27
|
+
spec.add_dependency 'simplecov', '~> 0.19'
|
28
|
+
spec.add_dependency 'rexml'
|
28
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,20 @@ 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
|
+
|
45
|
+
def test_terminal_output
|
46
|
+
output, _ = capture_output { @formatter.format(@result) }
|
47
|
+
result_path = File.join(SimpleCov.coverage_path, SimpleCov::Formatter::CoberturaFormatter::RESULT_FILE_NAME)
|
48
|
+
output_regex = /Coverage report generated for #{@result.command_name} to #{result_path}. (.*) covered./
|
49
|
+
assert_match(output_regex, output)
|
50
|
+
end
|
51
|
+
|
27
52
|
def test_format_dtd_validates
|
28
53
|
xml = @formatter.format(@result)
|
29
54
|
options = Nokogiri::XML::ParseOptions::DTDLOAD
|
@@ -36,12 +61,12 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
36
61
|
doc = Nokogiri::XML::Document.parse(xml)
|
37
62
|
|
38
63
|
coverage = doc.xpath '/coverage'
|
39
|
-
assert_equal '
|
40
|
-
assert_equal '0', coverage.attribute('branch-rate').value
|
41
|
-
assert_equal '
|
42
|
-
assert_equal '
|
43
|
-
assert_equal '
|
44
|
-
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
|
45
70
|
assert_equal '0', coverage.attribute('complexity').value
|
46
71
|
assert_equal '0', coverage.attribute('version').value
|
47
72
|
assert_not_empty coverage.attribute('timestamp').value
|
@@ -54,8 +79,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
54
79
|
assert_equal 1, packages.length
|
55
80
|
package = packages.first
|
56
81
|
assert_equal 'simplecov-cobertura', package.attribute('name').value
|
57
|
-
assert_equal '
|
58
|
-
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
|
59
84
|
assert_equal '0', package.attribute('complexity').value
|
60
85
|
|
61
86
|
classes = doc.xpath '/coverage/packages/package/classes/class'
|
@@ -63,20 +88,20 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
63
88
|
clazz = classes.first
|
64
89
|
assert_equal 'simplecov-cobertura_test', clazz.attribute('name').value
|
65
90
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('filename').value
|
66
|
-
assert_equal '
|
67
|
-
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
|
68
93
|
assert_equal '0', clazz.attribute('complexity').value
|
69
94
|
|
70
95
|
lines = doc.xpath '/coverage/packages/package/classes/class/lines/line'
|
71
|
-
assert_equal
|
96
|
+
assert_equal 7, lines.length
|
72
97
|
first_line = lines.first
|
73
98
|
assert_equal '1', first_line.attribute('number').value
|
74
99
|
assert_equal 'false', first_line.attribute('branch').value
|
75
100
|
assert_equal '1', first_line.attribute('hits').value
|
76
101
|
last_line = lines.last
|
77
|
-
assert_equal '
|
78
|
-
assert_equal '
|
79
|
-
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
|
80
105
|
end
|
81
106
|
|
82
107
|
def test_groups
|
@@ -86,12 +111,12 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
86
111
|
doc = Nokogiri::XML::Document.parse(xml)
|
87
112
|
|
88
113
|
coverage = doc.xpath '/coverage'
|
89
|
-
assert_equal '
|
90
|
-
assert_equal '0', coverage.attribute('branch-rate').value
|
91
|
-
assert_equal '
|
92
|
-
assert_equal '
|
93
|
-
assert_equal '
|
94
|
-
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
|
95
120
|
assert_equal '0', coverage.attribute('complexity').value
|
96
121
|
assert_equal '0', coverage.attribute('version').value
|
97
122
|
assert_not_empty coverage.attribute('timestamp').value
|
@@ -104,8 +129,8 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
104
129
|
assert_equal 1, packages.length
|
105
130
|
package = packages.first
|
106
131
|
assert_equal 'test_group', package.attribute('name').value
|
107
|
-
assert_equal '
|
108
|
-
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
|
109
134
|
assert_equal '0', package.attribute('complexity').value
|
110
135
|
|
111
136
|
classes = doc.xpath '/coverage/packages/package/classes/class'
|
@@ -113,19 +138,36 @@ class CoberturaFormatterTest < Test::Unit::TestCase
|
|
113
138
|
clazz = classes.first
|
114
139
|
assert_equal 'simplecov-cobertura_test', clazz.attribute('name').value
|
115
140
|
assert_equal 'test/simplecov-cobertura_test.rb', clazz.attribute('filename').value
|
116
|
-
assert_equal '
|
117
|
-
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
|
118
143
|
assert_equal '0', clazz.attribute('complexity').value
|
119
144
|
|
120
145
|
lines = doc.xpath '/coverage/packages/package/classes/class/lines/line'
|
121
|
-
assert_equal
|
146
|
+
assert_equal 7, lines.length
|
122
147
|
first_line = lines.first
|
123
148
|
assert_equal '1', first_line.attribute('number').value
|
124
149
|
assert_equal 'false', first_line.attribute('branch').value
|
125
150
|
assert_equal '1', first_line.attribute('hits').value
|
126
151
|
last_line = lines.last
|
127
|
-
assert_equal '
|
128
|
-
assert_equal '
|
129
|
-
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)
|
130
172
|
end
|
131
|
-
end
|
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
|
-
autorequire:
|
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
|
@@ -25,47 +25,61 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
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: '
|
47
|
+
version: '13.0'
|
48
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: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.19'
|
62
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: '0.
|
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,6 +87,7 @@ executables: []
|
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
90
|
+
- ".github/workflows/build.yml"
|
76
91
|
- ".gitignore"
|
77
92
|
- Gemfile
|
78
93
|
- LICENSE
|
@@ -80,14 +95,14 @@ files:
|
|
80
95
|
- Rakefile
|
81
96
|
- lib/simplecov-cobertura.rb
|
82
97
|
- lib/simplecov-cobertura/version.rb
|
83
|
-
- shippable.yml
|
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:
|
88
103
|
- Apache-2.0
|
89
104
|
metadata: {}
|
90
|
-
post_install_message:
|
105
|
+
post_install_message:
|
91
106
|
rdoc_options: []
|
92
107
|
require_paths:
|
93
108
|
- lib
|
@@ -95,17 +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
|
-
|
106
|
-
|
107
|
-
signing_key:
|
120
|
+
rubygems_version: 3.2.22
|
121
|
+
signing_key:
|
108
122
|
specification_version: 4
|
109
123
|
summary: SimpleCov Cobertura Formatter
|
110
124
|
test_files:
|
125
|
+
- test/coverage/coverage.xml
|
111
126
|
- test/simplecov-cobertura_test.rb
|