simplecov_covview 0.1.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/.gitignore +9 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +13 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/simplecov_covview.rb +18 -0
- data/lib/simplecov_covview/formatter.rb +42 -0
- data/lib/simplecov_covview/line.rb +49 -0
- data/lib/simplecov_covview/resultfile.rb +40 -0
- data/lib/simplecov_covview/srcfile.rb +35 -0
- data/lib/simplecov_covview/version.rb +5 -0
- data/simplecov_covview.gemspec +27 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9cfefe5ecc6d9189158b4e206bd3d085f78a644b7b52a4af732bd20ef83823d6
|
4
|
+
data.tar.gz: de86a0a0d01bec7314875c43ff787006d3d8ac729bcd6e2ae30e61ce51060d2d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0748769c3ac19d2e7845d6b5517df5419483b162058f035f553ba877732430b6e76f86654acc8dd13c8bdb40c863a726ded84079f4e8083ad81eeac9cb1a3d5
|
7
|
+
data.tar.gz: 16585701e76e9b0a27d62c5608dbcb83a1daf16a8ed41acb1e998f137fa88549ec94ba6fbca920d688a1fb7a162855070f0238b9f813a94efd56f031c4207293
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 icm7216
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Simplecov_covview
|
2
|
+
|
3
|
+
simplecov_covview is a coverage viewer for SimpleCov.
|
4
|
+
|
5
|
+
This formatter Generates a console report of your SimpleCov ruby code coverage results on Ruby.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'simplecov_covview'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install simplecov_covview
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
SimpleCov.formatter = SimpleCov::Formatter::CovView
|
28
|
+
# or
|
29
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
30
|
+
SimpleCov::Formatter::HTMLFormatter,
|
31
|
+
SimpleCov::Formatter::CovView
|
32
|
+
])
|
33
|
+
```
|
34
|
+
|
35
|
+
Example output:
|
36
|
+
|
37
|
+
```text
|
38
|
+
|
39
|
+
----- file => foo.rb -----
|
40
|
+
4 lines covered and 1 lines missed.
|
41
|
+
line# status count code
|
42
|
+
1: [ never] [ - ] # foo.rb
|
43
|
+
2: [covered] [ 1 ] def foo(n)
|
44
|
+
3: [covered] [ 10 ] if n <= 10
|
45
|
+
4: [covered] [ 10 ] p "n < 10"
|
46
|
+
5: [ never] [ - ] else
|
47
|
+
6: [ missed] [ 0 ] p "n >= 10"
|
48
|
+
7: [ never] [ - ] end
|
49
|
+
8: [ never] [ - ] end
|
50
|
+
9: [ never] [ - ]
|
51
|
+
10: [covered] [ 11 ] (1..10).each {|x| foo(x)}
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/icm7216/simplecov_covview.
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
t.options = "-v"
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: :test
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "simplecov_covview"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "simplecov_covview/version"
|
4
|
+
require_relative "simplecov_covview/formatter"
|
5
|
+
require_relative "simplecov_covview/resultfile.rb"
|
6
|
+
require_relative "simplecov_covview/srcfile.rb"
|
7
|
+
require_relative "simplecov_covview/line.rb"
|
8
|
+
|
9
|
+
module SimpleCov
|
10
|
+
module Formatter
|
11
|
+
class CovView
|
12
|
+
def format(result)
|
13
|
+
covview = SimplecovCovview::CovView.new(result)
|
14
|
+
covview.formatter.render
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module SimplecovCovview
|
2
|
+
class CovView
|
3
|
+
attr_accessor :src_files_list
|
4
|
+
|
5
|
+
def initialize(result)
|
6
|
+
@result = result
|
7
|
+
@src_files_list = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def formatter
|
11
|
+
@src_files_list = @result.source_files.map do |file|
|
12
|
+
contents = file.lines.map do |line|
|
13
|
+
coverage = line.coverage.nil? ? "-" : "#{line.coverage}"
|
14
|
+
{
|
15
|
+
num: line.number,
|
16
|
+
status: line.status,
|
17
|
+
cov: coverage,
|
18
|
+
src: line.src,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
result_file = SimplecovCovview::CovView::Resultfile.new(file)
|
23
|
+
file_contents = { contents: contents }
|
24
|
+
file_contents.merge(result_file.status)
|
25
|
+
end
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def render
|
31
|
+
@src_files_list.each do |src_file|
|
32
|
+
source_file = SimplecovCovview::CovView::Srcfile.new(src_file)
|
33
|
+
puts source_file.header
|
34
|
+
|
35
|
+
src_file[:contents].each do |line|
|
36
|
+
row = SimplecovCovview::CovView::Srcfile::Line.new(line, src_file)
|
37
|
+
puts row.contents
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Create text for each line from @src_files_list.
|
2
|
+
#
|
3
|
+
# @param [Hash] line @src_files_list
|
4
|
+
# @param [Hash] src_file @src_files_list
|
5
|
+
module SimplecovCovview
|
6
|
+
class CovView
|
7
|
+
class Srcfile
|
8
|
+
class Line
|
9
|
+
def initialize(line, src_file)
|
10
|
+
@line = line
|
11
|
+
@src_file = src_file
|
12
|
+
end
|
13
|
+
|
14
|
+
def line_number
|
15
|
+
@line[:num]
|
16
|
+
end
|
17
|
+
|
18
|
+
def line_width
|
19
|
+
@src_file[:line_digit] < 4 ? 4 : @src_file[:line_digit]
|
20
|
+
end
|
21
|
+
|
22
|
+
def status
|
23
|
+
@line[:status]
|
24
|
+
end
|
25
|
+
|
26
|
+
def cov_count
|
27
|
+
@line[:cov]
|
28
|
+
end
|
29
|
+
|
30
|
+
def cov_width
|
31
|
+
@src_file[:cov_digit] < 4 ? 4 : @src_file[:cov_digit] + 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def source_code
|
35
|
+
@line[:src]
|
36
|
+
end
|
37
|
+
|
38
|
+
def contents
|
39
|
+
[
|
40
|
+
sprintf("%#{line_width}s: ", line_number),
|
41
|
+
sprintf("[%7s] ", status),
|
42
|
+
sprintf("[%#{cov_width}s ] ", cov_count),
|
43
|
+
source_code,
|
44
|
+
].join
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# The Resultfile class stores source file's information.
|
2
|
+
#
|
3
|
+
# @param [Hash] file SimpleCov::SourceFile
|
4
|
+
module SimplecovCovview
|
5
|
+
class CovView
|
6
|
+
class Resultfile
|
7
|
+
|
8
|
+
def initialize(file)
|
9
|
+
@file = file
|
10
|
+
end
|
11
|
+
|
12
|
+
def covered_count
|
13
|
+
@file.covered_lines.count
|
14
|
+
end
|
15
|
+
|
16
|
+
def missed_count
|
17
|
+
@file.missed_lines.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def line_digit
|
21
|
+
@file.lines.count.to_s.size
|
22
|
+
end
|
23
|
+
|
24
|
+
def cov_digit
|
25
|
+
@file.coverage_data["lines"].map(&:to_i).max.to_s.size
|
26
|
+
end
|
27
|
+
|
28
|
+
def status
|
29
|
+
{
|
30
|
+
filename: File.basename(@file.filename),
|
31
|
+
line_digit: line_digit,
|
32
|
+
cov_digit: cov_digit,
|
33
|
+
covered: covered_count,
|
34
|
+
missed: missed_count,
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Create coverage header from @src_files_list.
|
2
|
+
#
|
3
|
+
# @param [Hash] src_file @src_files_list
|
4
|
+
module SimplecovCovview
|
5
|
+
class CovView
|
6
|
+
class Srcfile
|
7
|
+
def initialize(src_file)
|
8
|
+
@src_file = src_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def filename
|
12
|
+
@src_file[:filename]
|
13
|
+
end
|
14
|
+
|
15
|
+
def status
|
16
|
+
{
|
17
|
+
covered: @src_file[:covered],
|
18
|
+
missed: @src_file[:missed],
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def title
|
23
|
+
"line# status count code"
|
24
|
+
end
|
25
|
+
|
26
|
+
def header
|
27
|
+
[
|
28
|
+
"\n----- file => #{filename} -----",
|
29
|
+
"#{status[:covered]} lines covered and #{status[:missed]} lines missed.",
|
30
|
+
title,
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/simplecov_covview/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "simplecov_covview"
|
7
|
+
spec.version = SimplecovCovview::VERSION
|
8
|
+
spec.authors = ["icm7216"]
|
9
|
+
spec.email = ["icm7216d@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Coverage viewer for simplecov."
|
12
|
+
spec.description = "Coverage console output formatter for SimpleCov."
|
13
|
+
spec.homepage = "https://github.com/icm7216/simplecov_covview"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "test-unit"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplecov_covview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- icm7216
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: test-unit
|
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
|
+
description: Coverage console output formatter for SimpleCov.
|
28
|
+
email:
|
29
|
+
- icm7216d@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/console
|
40
|
+
- bin/setup
|
41
|
+
- lib/simplecov_covview.rb
|
42
|
+
- lib/simplecov_covview/formatter.rb
|
43
|
+
- lib/simplecov_covview/line.rb
|
44
|
+
- lib/simplecov_covview/resultfile.rb
|
45
|
+
- lib/simplecov_covview/srcfile.rb
|
46
|
+
- lib/simplecov_covview/version.rb
|
47
|
+
- simplecov_covview.gemspec
|
48
|
+
homepage: https://github.com/icm7216/simplecov_covview
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.4.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.2.17
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Coverage viewer for simplecov.
|
71
|
+
test_files: []
|