simplecov-table 1.0.0 → 1.0.1
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 +4 -4
- data/Gemfile +6 -0
- data/lib/simplecov-table.rb +109 -0
- data/simplecov-table.gemspec +3 -7
- metadata +5 -10
- data/README.md +0 -65
- data/spec/fixtures/bar.rb +0 -17
- data/spec/fixtures/foo.rb +0 -22
- data/spec/helpers.rb +0 -26
- data/spec/simplecov-table_spec.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc28d11cf99048676421d6e706105883378877a788b850714b747743465021fb
|
4
|
+
data.tar.gz: 9eac3ca3b0f4cab12ea1bf6f5f202199f0d3d18525bae4ad4838d0bc9f666ed3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4a677abb3a9ef7e9201afe4d5c6e775d923389bc52bd36e0ff13a2e5313598965f4ad4337b370f49a2164c05b6406055ac98c3bdba997ccb10952bf7c96b99c
|
7
|
+
data.tar.gz: c7014aedb4862b108cc267fa7ea5deffa43bd78894bded199d76331358e714ac25a624c6d0502000856d03cc8c61b50197369368064615b0519b67b813018feb
|
data/Gemfile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
fail 'simplecov-table requires simplecov' unless defined?(SimpleCov)
|
2
|
+
require 'io/console'
|
3
|
+
|
4
|
+
module SimpleCov
|
5
|
+
module Formatter
|
6
|
+
class TableFormatter
|
7
|
+
|
8
|
+
def format(coverage)
|
9
|
+
if coverage == nil then
|
10
|
+
$stderr.puts 'No coverage data'
|
11
|
+
return
|
12
|
+
end
|
13
|
+
|
14
|
+
table = {
|
15
|
+
'Files' => ['Files'],
|
16
|
+
'Coverage' => ['Coverage'],
|
17
|
+
'Uncovered lines' => ['Uncovered lines'],
|
18
|
+
}
|
19
|
+
|
20
|
+
coverage.files.each do |file|
|
21
|
+
if file.no_lines? then
|
22
|
+
continue
|
23
|
+
end
|
24
|
+
table['Files'].push(File.basename(file.filename))
|
25
|
+
table['Coverage'].push(file.covered_percent.round(1).to_s + '%')
|
26
|
+
table['Uncovered lines'].push(group_lines(file.missed_lines))
|
27
|
+
end
|
28
|
+
|
29
|
+
print_table(table)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def group_lines(lines)
|
35
|
+
if lines.length == 0 then
|
36
|
+
return ''
|
37
|
+
end
|
38
|
+
|
39
|
+
groups = []
|
40
|
+
group_start = group_end = lines.first.number
|
41
|
+
|
42
|
+
lines[1..].each do |line|
|
43
|
+
if line.number == group_end + 1 then
|
44
|
+
group_end = line.number
|
45
|
+
else
|
46
|
+
add_group(groups, group_start, group_end)
|
47
|
+
group_start = group_end = line.number
|
48
|
+
end
|
49
|
+
end
|
50
|
+
# Ensure the last group is closed
|
51
|
+
add_group(groups, group_start, group_end)
|
52
|
+
|
53
|
+
groups.join(',')
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_group(groups, group_start, group_end)
|
57
|
+
if group_end == nil || group_end == group_start then
|
58
|
+
groups.push(group_start.to_s)
|
59
|
+
elsif group_end == group_start + 1
|
60
|
+
groups.push(group_start.to_s, group_end.to_s)
|
61
|
+
else
|
62
|
+
groups.push(group_start.to_s + '-' + group_end.to_s)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def print_table(table)
|
67
|
+
headers = table.keys
|
68
|
+
columns = table.values
|
69
|
+
|
70
|
+
terminal_width = IO.console.winsize[1]
|
71
|
+
columns_widths = columns[0..-2].map { |column| column.map(&:length).max }
|
72
|
+
# The last column takes all the remaining horizontal space
|
73
|
+
columns_widths.push(terminal_width - (columns_widths.sum + 3*columns_widths.length) - 2)
|
74
|
+
|
75
|
+
rows = columns.first
|
76
|
+
.each_index
|
77
|
+
.map { |row_index| get_row(columns.map { |column| column[row_index] }, columns_widths) }
|
78
|
+
|
79
|
+
print [
|
80
|
+
'',
|
81
|
+
get_row_separator(columns_widths, '┬'),
|
82
|
+
get_row(headers, columns_widths),
|
83
|
+
get_row_separator(columns_widths, '┼'),
|
84
|
+
rows[1..].join("\n"),
|
85
|
+
get_row_separator(columns_widths, '┴'),
|
86
|
+
"\n",
|
87
|
+
].join("\n")
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_row(cells, columns_widths)
|
91
|
+
row = cells
|
92
|
+
.map.with_index { |cell, index| pad_string(cell, columns_widths[index]) }
|
93
|
+
.join(' │ ')
|
94
|
+
' ' + row
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_row_separator(columns_widths, cell_separator)
|
98
|
+
columns_widths
|
99
|
+
.map { |width| '─' * (width + 2) }
|
100
|
+
.join(cell_separator)
|
101
|
+
end
|
102
|
+
|
103
|
+
def pad_string(string, length)
|
104
|
+
string + ' ' * (length - string.length)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/simplecov-table.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'simplecov-table'
|
3
|
-
s.version = '1.0.
|
3
|
+
s.version = '1.0.1'
|
4
4
|
s.summary = 'A custom SimpleCov formatter to display summaries of coverage reports in table format.'
|
5
5
|
s.description = 'A custom SimpleCov formatter that displays table-formatted summaries of your coverage reports in the terminal. It prints the total coverage ratio of each source file, along with a compressed list of the uncovered lines.'
|
6
6
|
s.authors = ['cheap glitch']
|
@@ -9,13 +9,9 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.license = 'ISC'
|
10
10
|
s.require_path = 'lib'
|
11
11
|
s.files = Dir[
|
12
|
-
'
|
13
|
-
'lib/***/*.rb',
|
14
|
-
'spec/**/*.rb',
|
12
|
+
'lib/**/*.rb',
|
15
13
|
'simplecov-table.gemspec',
|
16
|
-
|
17
|
-
s.extra_rdoc_files = [
|
14
|
+
'Gemfile',
|
18
15
|
'LICENSE',
|
19
|
-
'README.md',
|
20
16
|
]
|
21
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplecov-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cheap glitch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A custom SimpleCov formatter that displays table-formatted summaries
|
14
14
|
of your coverage reports in the terminal. It prints the total coverage ratio of
|
@@ -16,17 +16,12 @@ description: A custom SimpleCov formatter that displays table-formatted summarie
|
|
16
16
|
email: cheap.glitch@gmail.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
19
|
-
extra_rdoc_files:
|
20
|
-
- LICENSE
|
21
|
-
- README.md
|
19
|
+
extra_rdoc_files: []
|
22
20
|
files:
|
21
|
+
- Gemfile
|
23
22
|
- LICENSE
|
24
|
-
-
|
23
|
+
- lib/simplecov-table.rb
|
25
24
|
- simplecov-table.gemspec
|
26
|
-
- spec/fixtures/bar.rb
|
27
|
-
- spec/fixtures/foo.rb
|
28
|
-
- spec/helpers.rb
|
29
|
-
- spec/simplecov-table_spec.rb
|
30
25
|
homepage: https://github.com/cheap-glitch/simplecov-table
|
31
26
|
licenses:
|
32
27
|
- ISC
|
data/README.md
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# 📊 simplecov-table
|
2
|
-
|
3
|
-

|
4
|
-

|
5
|
-
|
6
|
-
This is a custom [SimpleCov](https://github.com/simplecov-ruby/simplecov)
|
7
|
-
formatter that displays table-formatted summaries of your coverage reports in
|
8
|
-
the terminal. It prints the total coverage ratio of each source file, along with
|
9
|
-
a compressed list of the uncovered lines.
|
10
|
-
|
11
|
-
```text
|
12
|
-
────────────────────┬──────────┬──────────────────────────────────────
|
13
|
-
Files │ Coverage │ Uncovered lines
|
14
|
-
────────────────────┼──────────┼──────────────────────────────────────
|
15
|
-
lib/foo.rb │ 78.0% │ 11,12,20-27
|
16
|
-
lib/foo/bar.rb │ 100.0% │
|
17
|
-
lib/foo/baz.rb │ 33.5% │ 3,5,63-75,122,128
|
18
|
-
────────────────────┴──────────┴──────────────────────────────────────
|
19
|
-
```
|
20
|
-
|
21
|
-
## Installation
|
22
|
-
|
23
|
-
```shell
|
24
|
-
gem install simplecov-table
|
25
|
-
```
|
26
|
-
|
27
|
-
## Usage
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
require 'simplecov'
|
31
|
-
require 'simplecov-table'
|
32
|
-
|
33
|
-
SimpleCov.formatter = SimpleCov::Formatter::TableFormatter
|
34
|
-
SimpleCov.start
|
35
|
-
```
|
36
|
-
|
37
|
-
Or, if you want to use several formatters:
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
require 'simplecov'
|
41
|
-
require 'simplecov-table'
|
42
|
-
|
43
|
-
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
|
44
|
-
SimpleCov::Formatter::HTMLFormatter,
|
45
|
-
SimpleCov::Formatter::TableFormatter,
|
46
|
-
])
|
47
|
-
SimpleCov.start
|
48
|
-
```
|
49
|
-
|
50
|
-
## Changelog
|
51
|
-
|
52
|
-
See the full changelog [here](https://github.com/cheap-glitch/simplecov-table/releases).
|
53
|
-
|
54
|
-
## Contributing
|
55
|
-
|
56
|
-
Contributions are welcomed! Please open an issue before submitting substantial changes.
|
57
|
-
|
58
|
-
## Related
|
59
|
-
|
60
|
-
* [simplecov-erb](https://github.com/kpaulisse/simplecov-erb) - Flexible plain-text formatter that uses ERB templates
|
61
|
-
* [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov) - Simple LCOV formatter
|
62
|
-
|
63
|
-
## License
|
64
|
-
|
65
|
-
ISC
|
data/spec/fixtures/bar.rb
DELETED
data/spec/fixtures/foo.rb
DELETED
data/spec/helpers.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# Taken from https://github.com/cldwalker/hirb/blob/master/test/test_helper.rb
|
2
|
-
# Copyright (c) 2010 Gabriel Horner
|
3
|
-
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
def capture_stdout(&block)
|
7
|
-
original_stdout = $stdout
|
8
|
-
$stdout = fake = StringIO.new
|
9
|
-
begin
|
10
|
-
yield
|
11
|
-
ensure
|
12
|
-
$stdout = original_stdout
|
13
|
-
end
|
14
|
-
fake.string
|
15
|
-
end
|
16
|
-
|
17
|
-
def capture_stderr(&block)
|
18
|
-
original_stderr = $stderr
|
19
|
-
$stderr = fake = StringIO.new
|
20
|
-
begin
|
21
|
-
yield
|
22
|
-
ensure
|
23
|
-
$stderr = original_stderr
|
24
|
-
end
|
25
|
-
fake.string
|
26
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
|
3
|
-
require_relative 'helpers'
|
4
|
-
require_relative '../lib/simplecov-table'
|
5
|
-
|
6
|
-
FIXTURES_COVERAGE_DIR = 'spec/coverage'
|
7
|
-
|
8
|
-
module SimpleCov::Formatter
|
9
|
-
describe TableFormatter do
|
10
|
-
|
11
|
-
before(:example) do
|
12
|
-
FileUtils.remove_dir(FIXTURES_COVERAGE_DIR, true) if Dir.exist?(FIXTURES_COVERAGE_DIR)
|
13
|
-
SimpleCov.coverage_dir FIXTURES_COVERAGE_DIR
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'prints an error when there is no data' do
|
17
|
-
output = capture_stderr { TableFormatter.new.format(SimpleCov.result) }
|
18
|
-
expect(output).to eq("No coverage data\n")
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'prints a pretty table' do
|
22
|
-
SimpleCov.start
|
23
|
-
load 'fixtures/foo.rb'
|
24
|
-
output = capture_stdout { TableFormatter.new.format(SimpleCov.result) }
|
25
|
-
expect(output).to match(/^ Files │ Coverage │ Uncovered lines\s+$/m)
|
26
|
-
expect(output).to match(/^ foo\.rb │ 92\.3% │ 15\s+$/m)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'groups adjacent uncovered lines together' do
|
30
|
-
SimpleCov.start
|
31
|
-
load 'fixtures/bar.rb'
|
32
|
-
output = capture_stdout { TableFormatter.new.format(SimpleCov.result) }
|
33
|
-
expect(output).to match(/^ bar\.rb │ 60\.0% │ 3,11-13\s+$/m)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|