simplecov_lcov_formatter 0.9.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +38 -0
- data/lib/simplecov_lcov_formatter/configuration.rb +28 -0
- data/lib/simplecov_lcov_formatter/version.rb +3 -0
- data/lib/simplecov_lcov_formatter.rb +130 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27bad063daa9b20b4d40eb8da0135e518b310c64468c257d92bf85be74e2171e
|
4
|
+
data.tar.gz: 6a5d795e0f71554eecfbefbb120ca3a9c0db6aa25b09696efef8c16e4f4a9b77
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35333006ab5ed7030231ace40f366729ec931f8f25885949f43aba9c8c6d9c576a3e34ce9da1c2fc979c7f5a58462e18eb4cd121e1d3d619df93b69ba9ac60cd
|
7
|
+
data.tar.gz: 4882623cc22d650145f23fb82ed35420d135e55b81dbb027010f315724826f8a2496adf8052973548e13795194ed5fe9d1a580bf54fed87ac652e5c62ff7fd5a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 t-mario-y
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# simplecov_lcov_formatter
|
2
|
+
|
3
|
+
LCOV formatter for SimpleCov. Successor of [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Output report per file:
|
8
|
+
|
9
|
+
```Ruby
|
10
|
+
require 'simplecov'
|
11
|
+
require 'simplecov_lcov_formatter'
|
12
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
13
|
+
SimpleCov.start
|
14
|
+
```
|
15
|
+
|
16
|
+
Output report as single file:
|
17
|
+
|
18
|
+
```Ruby
|
19
|
+
require 'simplecov'
|
20
|
+
require 'simplecov_lcov_formatter'
|
21
|
+
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
|
22
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
23
|
+
SimpleCov.start
|
24
|
+
```
|
25
|
+
|
26
|
+
Other available configuration options for single file report:
|
27
|
+
|
28
|
+
```Ruby
|
29
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
30
|
+
c.output_directory = 'your/path' # default: "coverage/lcov"
|
31
|
+
c.lcov_file_name = 'lcov.info' # default: "YOUR_PROJECT_NAME.lcov"
|
32
|
+
c.single_report_path = 'your/path/lcov.info'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
TBD
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SimpleCovLcovFormatter
|
2
|
+
class Configuration
|
3
|
+
attr_writer :report_with_single_file
|
4
|
+
attr_writer :output_directory
|
5
|
+
attr_writer :lcov_file_name
|
6
|
+
|
7
|
+
def report_with_single_file?
|
8
|
+
!!@report_with_single_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def output_directory
|
12
|
+
@output_directory || File.join(SimpleCov.coverage_path, 'lcov')
|
13
|
+
end
|
14
|
+
|
15
|
+
def single_report_path=(new_path)
|
16
|
+
self.output_directory = File.dirname(new_path)
|
17
|
+
@single_report_path = new_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def single_report_path
|
21
|
+
@single_report_path || File.join(output_directory, lcov_file_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def lcov_file_name
|
25
|
+
@lcov_file_name || "#{Pathname.new(SimpleCov.root).basename}.lcov"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
require 'simplecov'
|
4
|
+
|
5
|
+
require_relative 'simplecov_lcov_formatter/configuration'
|
6
|
+
|
7
|
+
module SimpleCov
|
8
|
+
module Formatter
|
9
|
+
# Custom Formatter to generate lcov style coverage for simplecov
|
10
|
+
class LcovFormatter
|
11
|
+
# generate lcov style coverage.
|
12
|
+
# ==== Args
|
13
|
+
# _result_ :: [SimpleCov::Result] abcoverage result instance.
|
14
|
+
def format(result)
|
15
|
+
create_output_directory!
|
16
|
+
|
17
|
+
if report_with_single_file?
|
18
|
+
write_lcov_to_single_file!(result.files)
|
19
|
+
else
|
20
|
+
result.files.each { |file| write_lcov!(file) }
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "Lcov style coverage report generated for #{result.command_name} to #{lcov_results_path}"
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def config
|
28
|
+
@config ||= SimpleCovLcovFormatter::Configuration.new
|
29
|
+
yield @config if block_given?
|
30
|
+
@config
|
31
|
+
end
|
32
|
+
|
33
|
+
def report_with_single_file=(value)
|
34
|
+
deprecation_message =
|
35
|
+
"#{caller(1..1).first} " \
|
36
|
+
"`#{LcovFormatter}.report_with_single_file=` is deprecated. " \
|
37
|
+
"Use `#{LcovFormatter}.config.report_with_single_file=` instead"
|
38
|
+
|
39
|
+
warn deprecation_message
|
40
|
+
config.report_with_single_file = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def output_directory
|
47
|
+
self.class.config.output_directory
|
48
|
+
end
|
49
|
+
|
50
|
+
def lcov_results_path
|
51
|
+
report_with_single_file? ? single_report_path : output_directory
|
52
|
+
end
|
53
|
+
|
54
|
+
def report_with_single_file?
|
55
|
+
self.class.config.report_with_single_file?
|
56
|
+
end
|
57
|
+
|
58
|
+
def single_report_path
|
59
|
+
self.class.config.single_report_path
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_output_directory!
|
63
|
+
return if Dir.exist?(output_directory)
|
64
|
+
FileUtils.mkdir_p(output_directory)
|
65
|
+
end
|
66
|
+
|
67
|
+
def write_lcov!(file)
|
68
|
+
File.open(File.join(output_directory, output_filename(file.filename)), 'w') { |f| f.write format_file(file) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def write_lcov_to_single_file!(files)
|
72
|
+
File.open(single_report_path, 'w') { |f| files.each { |file| f.write format_file(file) } }
|
73
|
+
end
|
74
|
+
|
75
|
+
def output_filename(filename)
|
76
|
+
filename.gsub("#{SimpleCov.root}/", '').gsub('/', '-').tap { |name| name << '.lcov' }
|
77
|
+
end
|
78
|
+
|
79
|
+
def format_file(file)
|
80
|
+
filename = file.filename.gsub("#{SimpleCov.root}/", './')
|
81
|
+
pieces = []
|
82
|
+
pieces << "SF:#{filename}"
|
83
|
+
pieces << format_lines(file)
|
84
|
+
pieces << "LF:#{file.lines.filter { |el| el.coverage }.count}"
|
85
|
+
pieces << "LH:#{file.lines.filter { |el| el.coverage && el.coverage > 0 }.count}"
|
86
|
+
|
87
|
+
if SimpleCov.branch_coverage?
|
88
|
+
branch_data = format_branches(file)
|
89
|
+
pieces << branch_data if branch_data.length > 0
|
90
|
+
pieces << "BRF:#{file.total_branches.length}"
|
91
|
+
pieces << "BRH:#{file.covered_branches.length}"
|
92
|
+
end
|
93
|
+
pieces << 'end_of_record'
|
94
|
+
pieces << ''
|
95
|
+
pieces.join("\n")
|
96
|
+
end
|
97
|
+
|
98
|
+
def format_branches(file)
|
99
|
+
branch_idx = 0
|
100
|
+
filtered_branches(file)
|
101
|
+
.map do |branch|
|
102
|
+
branch_idx += 1
|
103
|
+
format_branch(branch, branch_idx)
|
104
|
+
end
|
105
|
+
.join("\n")
|
106
|
+
end
|
107
|
+
|
108
|
+
def format_lines(file)
|
109
|
+
filtered_lines(file).map { |line| format_line(line) }.join("\n")
|
110
|
+
end
|
111
|
+
|
112
|
+
def filtered_lines(file)
|
113
|
+
file.lines.reject(&:never?).reject(&:skipped?)
|
114
|
+
end
|
115
|
+
|
116
|
+
def filtered_branches(file)
|
117
|
+
file.branches.reject(&:skipped?)
|
118
|
+
end
|
119
|
+
|
120
|
+
def format_branch(branch, branch_idx)
|
121
|
+
taken = branch.coverage == 0 ? '-' : branch.coverage
|
122
|
+
"BRDA:#{branch.report_line},0,#{branch_idx},#{taken}"
|
123
|
+
end
|
124
|
+
|
125
|
+
def format_line(line)
|
126
|
+
"DA:#{line.number},#{line.coverage}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplecov_lcov_formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- t-mario-y
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: syntax_tree
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.18'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.18'
|
69
|
+
description: LCOV formatter for SimpleCov. Successor of simplecov-lcov.
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- LICENSE
|
76
|
+
- README.md
|
77
|
+
- lib/simplecov_lcov_formatter.rb
|
78
|
+
- lib/simplecov_lcov_formatter/configuration.rb
|
79
|
+
- lib/simplecov_lcov_formatter/version.rb
|
80
|
+
homepage: https://github.com/t-mario-y/simplecov_lcov_formatter
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.4.19
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: LCOV formatter for SimpleCov. Successor of simplecov-lcov.
|
103
|
+
test_files: []
|