simplecov-console 0.7.0 → 0.9.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/CHANGELOG.md +26 -0
- data/Gemfile +1 -1
- data/README.md +89 -18
- data/VERSION +1 -1
- data/lib/simplecov-console.rb +71 -49
- data/lib/simplecov-console/output/block.rb +28 -0
- data/lib/simplecov-console/output/table.rb +48 -0
- data/simplecov-console.gemspec +18 -22
- data/test/test_simplecov-console.rb +74 -4
- metadata +12 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5bb7e11c42fb65f0946870622b11a55ab39bb0eba3aa8cfc16da3d18be8fa48e
|
|
4
|
+
data.tar.gz: 433b3c37567470bb280384d28c48a6e9fc04916fb9f74ce451c3f77316d4b130
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 837d50087a4744ecfcbfb1086ad425573a2ba151da649c529ed379340cb0720ad27824b3c26d4a9fdfadb91bfa464e9c8036029ca62991919019a9dc658b4702
|
|
7
|
+
data.tar.gz: 7f104c87f947046cf75996ceec687684aee3466c0eb8c86074b7a18185142a14bcff96d7565bec1987f5ad75e3425923507c0fbf4ff0ff1e7d7766ec47f179cc
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.8 (2020.11.11)
|
|
4
|
+
|
|
5
|
+
- Added support for branch coverage - thanks [@robotdana!](https://github.com/robotdana) ([#19](https://github.com/chetan/simplecov-console/pull/19))
|
|
6
|
+
|
|
7
|
+
## 0.7.2 (2020.03.05)
|
|
8
|
+
|
|
9
|
+
- Fix: table output include ([#17](https://github.com/chetan/simplecov-console/issues/17))
|
|
10
|
+
|
|
11
|
+
## 0.7.1 (2020.03.05)
|
|
12
|
+
|
|
13
|
+
- Fix: block output doesn't work with frozen string literal ([#16](https://github.com/chetan/simplecov-console/issues/16))
|
|
14
|
+
|
|
15
|
+
## 0.7 (2020.03.04)
|
|
16
|
+
|
|
17
|
+
- Added new 'block' style output option - thanks [@hpainter](https://github.com/hpainter)! ([#15](https://github.com/chetan/simplecov-console/issues/15))
|
|
18
|
+
|
|
19
|
+
## 0.6 (2019.11.08)
|
|
20
|
+
|
|
21
|
+
- Added new config options: `sort`, `show_covered`, and `max_rows`
|
|
22
|
+
|
|
23
|
+
## 0.5 (2019.05.24)
|
|
24
|
+
|
|
25
|
+
- Replaced `hirb` gem with `terminal-table` due to multiple warnings thrown ([#11](https://github.com/chetan/simplecov-console/issues/11))
|
|
26
|
+
- Support [disabling colorized](https://no-color.org/) output via `NO_COLOR` env var
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -47,58 +47,96 @@ showing bottom (worst) 15 of 69 files
|
|
|
47
47
|
|
|
48
48
|
## Configuration
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
simplecov-console is configurable through environment variables and/or via Ruby
|
|
51
|
+
code, generally in your test helper or setup file.
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
### Options
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
SimpleCov::Formatter::Console.sort = 'path' # sort by file path
|
|
57
|
+
SimpleCov::Formatter::Console.show_covered = true # show all files in coverage report
|
|
58
|
+
SimpleCov::Formatter::Console.max_rows = 15 # integer
|
|
59
|
+
SimpleCov::Formatter::Console.max_lines = 5 # integer
|
|
60
|
+
SimpleCov::Formatter::Console.missing_len = 20 # integer
|
|
61
|
+
SimpleCov::Formatter::Console.output_style = 'block' # 'table' (default) or 'block'
|
|
62
|
+
SimpleCov::Formatter::Console.table_options = {:style => {:width => 200}}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Note that all options except `table_options` can also be set via env var using
|
|
66
|
+
the uppercase name, e.g., `MAX_ROWS`.
|
|
67
|
+
|
|
68
|
+
#### Disabling colorized output
|
|
69
|
+
|
|
70
|
+
Color support is active by default. To disable, export `NO_COLOR=1`:
|
|
53
71
|
|
|
54
72
|
```sh
|
|
55
73
|
NO_COLOR=1 rake test
|
|
56
74
|
```
|
|
57
75
|
|
|
58
|
-
|
|
76
|
+
#### Sorting the output
|
|
59
77
|
|
|
60
|
-
By default the coverage report
|
|
78
|
+
By default the coverage report sorts by coverage % in descending order. To
|
|
79
|
+
sort alphabetically by path:
|
|
61
80
|
|
|
62
81
|
```ruby
|
|
63
82
|
SimpleCov::Formatter::Console.sort = 'path' # sort by file path
|
|
64
83
|
```
|
|
65
84
|
|
|
66
|
-
|
|
85
|
+
#### Showing covered files
|
|
67
86
|
|
|
68
|
-
By default, fully covered files are excluded from the report.
|
|
87
|
+
By default, fully covered files are excluded from the report. To include them:
|
|
69
88
|
|
|
70
89
|
```ruby
|
|
71
90
|
SimpleCov::Formatter::Console.show_covered = true # show all files in coverage report
|
|
72
91
|
```
|
|
73
92
|
|
|
74
|
-
|
|
93
|
+
#### Maximum rows displayed
|
|
75
94
|
|
|
76
|
-
By default, a maximum of 15 files with the worst coverage are displayed in the
|
|
95
|
+
By default, a maximum of 15 files with the worst coverage are displayed in the
|
|
96
|
+
report. To override this limit:
|
|
77
97
|
|
|
78
98
|
```ruby
|
|
79
|
-
SimpleCov::Formatter::Console.max_rows = #
|
|
99
|
+
SimpleCov::Formatter::Console.max_rows = 20 # integer
|
|
80
100
|
```
|
|
81
101
|
|
|
82
|
-
Setting a value of `-1` or `nil` will show all
|
|
102
|
+
Setting a value of `-1` or `nil` (in Ruby) will show all files.
|
|
103
|
+
|
|
104
|
+
#### Maximum lines displayed
|
|
105
|
+
|
|
106
|
+
By default, all missing lines will be included for each displayed file. For
|
|
107
|
+
large source files with poor coverage, this may become unwieldy. To show fewer
|
|
108
|
+
groups of lines:
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
SimpleCov::Formatter::Console.max_lines = 5 # integer
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Maximum length of missing lines
|
|
115
|
+
|
|
116
|
+
As an alternative to the above `max_lines` option, you may limit the missing
|
|
117
|
+
lines output by number of characters:
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
SimpleCov::Formatter::Console.missing_len = 20 # integer
|
|
121
|
+
```
|
|
83
122
|
|
|
84
|
-
|
|
123
|
+
#### Table options
|
|
85
124
|
|
|
86
|
-
In some cases, you may need to pass some options to `TerminalTable.new`. For
|
|
87
|
-
|
|
125
|
+
In some cases, you may need to pass some options to `TerminalTable.new`. For
|
|
126
|
+
example, if the filenames truncate so much that you can't read them, try
|
|
127
|
+
increasing the table width:
|
|
88
128
|
|
|
89
129
|
```ruby
|
|
90
130
|
SimpleCov::Formatter::Console.table_options = {:style => {:width => 200}}
|
|
91
|
-
SimpleCov.formatter = SimpleCov::Formatter::Console
|
|
92
131
|
```
|
|
93
132
|
|
|
94
|
-
|
|
133
|
+
#### Block output style
|
|
95
134
|
|
|
96
|
-
As an alternative to the default table output format,
|
|
97
|
-
|
|
135
|
+
As an alternative to the default table output format, a simpler block format is
|
|
136
|
+
also available:
|
|
98
137
|
|
|
99
138
|
```ruby
|
|
100
139
|
SimpleCov::Formatter::Console.output_style = 'block'
|
|
101
|
-
SimpleCov.formatter = SimpleCov::Formatter::Console
|
|
102
140
|
```
|
|
103
141
|
|
|
104
142
|
Example output:
|
|
@@ -131,8 +169,41 @@ coverage: 44.00% (28/50 lines)
|
|
|
131
169
|
42 file(s) with 100% coverage not shown
|
|
132
170
|
```
|
|
133
171
|
|
|
172
|
+
### Branch Coverage Support
|
|
173
|
+
|
|
174
|
+
When branch coverage is [enabled in
|
|
175
|
+
simplecov](https://github.com/simplecov-ruby/simplecov/tree/818bc2547842a90c607b4fec834320766a8686de#branch-coverage-ruby--25),
|
|
176
|
+
branch info will automatically be displayed in the output:
|
|
177
|
+
|
|
178
|
+
```text
|
|
179
|
+
COVERAGE: 78.26% -- 18/23 lines in 2 files
|
|
180
|
+
BRANCH COVERAGE: 83.33% -- 5/6 branches in 2 branches
|
|
181
|
+
|
|
182
|
+
+----------+-------------------------------+-------+--------+---------------+-----------------+----------+-----------------+------------------+
|
|
183
|
+
| coverage | file | lines | missed | missing | branch coverage | branches | branches missed | branches missing |
|
|
184
|
+
+----------+-------------------------------+-------+--------+---------------+-----------------+----------+-----------------+------------------+
|
|
185
|
+
| 72.22% | lib/simplecov-console-test.rb | 18 | 5 | 10-12, 16, 25 | 83.33% | 6 | 1 | 25[then] |
|
|
186
|
+
+----------+-------------------------------+-------+--------+---------------+-----------------+----------+-----------------+------------------+
|
|
187
|
+
```
|
|
188
|
+
|
|
134
189
|
## History
|
|
135
190
|
|
|
191
|
+
### 0.9 (2021.01.21)
|
|
192
|
+
|
|
193
|
+
- Added support for limiting number of lines shown
|
|
194
|
+
|
|
195
|
+
### 0.8 (2020.11.11)
|
|
196
|
+
|
|
197
|
+
- Added support for branch coverage - thanks [@robotdana!](https://github.com/robotdana) ([#19](https://github.com/chetan/simplecov-console/pull/19))
|
|
198
|
+
|
|
199
|
+
### 0.7.2 (2020.03.05)
|
|
200
|
+
|
|
201
|
+
- Fix: table output include ([#17](https://github.com/chetan/simplecov-console/issues/17))
|
|
202
|
+
|
|
203
|
+
### 0.7.1 (2020.03.05)
|
|
204
|
+
|
|
205
|
+
- Fix: block output doesn't work with frozen string literal ([#16](https://github.com/chetan/simplecov-console/issues/16))
|
|
206
|
+
|
|
136
207
|
### 0.7 (2020.03.04)
|
|
137
208
|
|
|
138
209
|
- Added new 'block' style output option - thanks [@hpainter](https://github.com/hpainter)! ([#15](https://github.com/chetan/simplecov-console/issues/15))
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.9.1
|
data/lib/simplecov-console.rb
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
require 'terminal-table'
|
|
2
1
|
require 'ansi/code'
|
|
3
2
|
|
|
4
3
|
class SimpleCov::Formatter::Console
|
|
5
4
|
|
|
6
5
|
VERSION = IO.read(File.expand_path("../../VERSION", __FILE__)).strip
|
|
7
6
|
|
|
8
|
-
ATTRIBUTES = [:table_options, :use_colors, :max_rows, :
|
|
7
|
+
ATTRIBUTES = [:table_options, :use_colors, :max_rows, :max_lines,
|
|
8
|
+
:missing_len, :show_covered, :sort, :output_style]
|
|
9
|
+
|
|
9
10
|
class << self
|
|
10
11
|
attr_accessor(*ATTRIBUTES)
|
|
11
12
|
end
|
|
@@ -17,6 +18,10 @@ class SimpleCov::Formatter::Console
|
|
|
17
18
|
# configure max rows from MAX_ROWS env var
|
|
18
19
|
SimpleCov::Formatter::Console.max_rows = ENV.fetch('MAX_ROWS', 15).to_i
|
|
19
20
|
|
|
21
|
+
# configure max lines per row and missing len
|
|
22
|
+
SimpleCov::Formatter::Console.max_lines = ENV.fetch('MAX_LINES', 0).to_i
|
|
23
|
+
SimpleCov::Formatter::Console.missing_len = ENV.fetch('MISSING_LEN', 0).to_i
|
|
24
|
+
|
|
20
25
|
# configure show_covered from SHOW_COVERED env var
|
|
21
26
|
SimpleCov::Formatter::Console.show_covered = ENV.fetch('SHOW_COVERED', 'false') == 'true'
|
|
22
27
|
|
|
@@ -26,7 +31,24 @@ class SimpleCov::Formatter::Console
|
|
|
26
31
|
# configure output format ('table', 'block')
|
|
27
32
|
SimpleCov::Formatter::Console.output_style = ENV.fetch('OUTPUT_STYLE', 'table')
|
|
28
33
|
|
|
34
|
+
def include_output_style
|
|
35
|
+
if SimpleCov::Formatter::Console.output_style == 'block' then
|
|
36
|
+
require 'simplecov-console/output/block'
|
|
37
|
+
extend BlockOutput
|
|
38
|
+
else
|
|
39
|
+
# default to table
|
|
40
|
+
require 'simplecov-console/output/table'
|
|
41
|
+
extend TableOutput
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def show_branch_coverage?(result)
|
|
46
|
+
Gem::Version.new(SimpleCov::VERSION) >= Gem::Version.new('0.18.5') &&
|
|
47
|
+
result.coverage_statistics[:branch]
|
|
48
|
+
end
|
|
49
|
+
|
|
29
50
|
def format(result)
|
|
51
|
+
include_output_style
|
|
30
52
|
|
|
31
53
|
root = nil
|
|
32
54
|
if Module.const_defined? :ROOT then
|
|
@@ -40,7 +62,11 @@ class SimpleCov::Formatter::Console
|
|
|
40
62
|
end
|
|
41
63
|
|
|
42
64
|
puts
|
|
43
|
-
puts "COVERAGE: #{colorize(pct(result))} -- #{result.covered_lines}/#{result.total_lines} lines in #{result.files.size} files"
|
|
65
|
+
puts "COVERAGE: #{colorize(pct(result.covered_percent))} -- #{result.covered_lines}/#{result.total_lines} lines in #{result.files.size} files"
|
|
66
|
+
show_branch_coverage = show_branch_coverage?(result)
|
|
67
|
+
if show_branch_coverage
|
|
68
|
+
puts "BRANCH COVERAGE: #{colorize(pct(result.coverage_statistics[:branch].percent))} -- #{result.covered_branches}/#{result.total_branches} branches in #{result.files.size} branches"
|
|
69
|
+
end
|
|
44
70
|
puts
|
|
45
71
|
|
|
46
72
|
if root.nil? then
|
|
@@ -48,16 +74,23 @@ class SimpleCov::Formatter::Console
|
|
|
48
74
|
end
|
|
49
75
|
|
|
50
76
|
if SimpleCov::Formatter::Console.sort == 'coverage'
|
|
51
|
-
|
|
77
|
+
if show_branch_coverage
|
|
78
|
+
files = result.files.sort do |a,b|
|
|
79
|
+
(a.covered_percent <=> b.covered_percent).nonzero? ||
|
|
80
|
+
(a.coverage_statistics[:branch].percent <=> b.coverage_statistics[:branch].percent)
|
|
81
|
+
end
|
|
82
|
+
else
|
|
83
|
+
files = result.files.sort_by(&:covered_percent)
|
|
84
|
+
end
|
|
52
85
|
else
|
|
53
|
-
files = result.files
|
|
86
|
+
files = result.files.to_a
|
|
54
87
|
end
|
|
55
88
|
|
|
56
89
|
covered_files = 0
|
|
57
90
|
|
|
58
91
|
unless SimpleCov::Formatter::Console.show_covered
|
|
59
92
|
files.select!{ |file|
|
|
60
|
-
if file.covered_percent == 100 then
|
|
93
|
+
if file.covered_percent == 100 && (!show_branch_coverage || file.coverage_statistics[:branch].percent == 100) then
|
|
61
94
|
covered_files += 1
|
|
62
95
|
false
|
|
63
96
|
else
|
|
@@ -76,14 +109,25 @@ class SimpleCov::Formatter::Console
|
|
|
76
109
|
files = files.slice(0, max_rows)
|
|
77
110
|
end
|
|
78
111
|
|
|
79
|
-
puts
|
|
80
|
-
|
|
112
|
+
puts output(files, root, show_branch_coverage)
|
|
113
|
+
|
|
81
114
|
if covered_files > 0 then
|
|
82
115
|
puts "#{covered_files} file(s) with 100% coverage not shown"
|
|
83
116
|
end
|
|
84
117
|
|
|
85
118
|
end
|
|
86
119
|
|
|
120
|
+
def branches_missed(missed_branches)
|
|
121
|
+
missed_branches.group_by(&:start_line).map do |line_number, branches|
|
|
122
|
+
"#{line_number}[#{branches.map(&:type).join(',')}]"
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Group missed lines for better display
|
|
127
|
+
#
|
|
128
|
+
# @param [Array<SimpleCov::SourceFile::Line>] missed array of missed lines reported by SimpleCov
|
|
129
|
+
#
|
|
130
|
+
# @return [Array<String>] Missing groups of lines
|
|
87
131
|
def missed(missed_lines)
|
|
88
132
|
groups = {}
|
|
89
133
|
base = nil
|
|
@@ -109,11 +153,28 @@ class SimpleCov::Formatter::Console
|
|
|
109
153
|
end
|
|
110
154
|
end
|
|
111
155
|
|
|
156
|
+
max_lines = SimpleCov::Formatter::Console.max_lines
|
|
157
|
+
if max_lines > 0 && group_str.size > max_lines then
|
|
158
|
+
# Show at most N missing groups of lines
|
|
159
|
+
group_str = group_str[0, SimpleCov::Formatter::Console.max_lines] << "..."
|
|
160
|
+
end
|
|
161
|
+
|
|
112
162
|
group_str
|
|
113
163
|
end
|
|
114
164
|
|
|
115
|
-
|
|
116
|
-
|
|
165
|
+
# Truncate string to at most N chars (as defined by missing_len)
|
|
166
|
+
def trunc(str)
|
|
167
|
+
return str if str.include?("...") # already truncated, skip
|
|
168
|
+
|
|
169
|
+
len = SimpleCov::Formatter::Console.missing_len
|
|
170
|
+
if len > 0 && str.size > len then
|
|
171
|
+
str = str[0, len].gsub(/,(\s+)?$/, '') + ' ...'
|
|
172
|
+
end
|
|
173
|
+
str
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def pct(number)
|
|
177
|
+
sprintf("%6.2f%%", number)
|
|
117
178
|
end
|
|
118
179
|
|
|
119
180
|
def use_colors?
|
|
@@ -133,43 +194,4 @@ class SimpleCov::Formatter::Console
|
|
|
133
194
|
ANSI.red { s }
|
|
134
195
|
end
|
|
135
196
|
end
|
|
136
|
-
|
|
137
|
-
# format per-file results output using Terminal::Table
|
|
138
|
-
def table_output(files, root)
|
|
139
|
-
table = files.map do |f|
|
|
140
|
-
[
|
|
141
|
-
colorize(pct(f)),
|
|
142
|
-
f.filename.gsub(root + "/", ''),
|
|
143
|
-
f.lines_of_code,
|
|
144
|
-
f.missed_lines.count,
|
|
145
|
-
missed(f.missed_lines).join(", ")
|
|
146
|
-
]
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
table_options = SimpleCov::Formatter::Console.table_options || {}
|
|
150
|
-
if !table_options.kind_of?(Hash) then
|
|
151
|
-
raise ArgumentError.new("SimpleCov::Formatter::Console.table_options must be a Hash")
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
headings = %w{ coverage file lines missed missing }
|
|
155
|
-
|
|
156
|
-
opts = table_options.merge({:headings => headings, :rows => table})
|
|
157
|
-
Terminal::Table.new(opts)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# format per-file results output as plain text blocks
|
|
161
|
-
def block_output(files, root)
|
|
162
|
-
blocks = []
|
|
163
|
-
files.each do |f|
|
|
164
|
-
block = []
|
|
165
|
-
block << sprintf("%8.8s: %s", 'file', f.filename.gsub(root + "/", ''))
|
|
166
|
-
block << sprintf("%8.8s: %s (%d/%d lines)", 'coverage',
|
|
167
|
-
colorize(sprintf("%.2f%%", f.covered_percent)),
|
|
168
|
-
f.covered_lines.count, f.lines_of_code)
|
|
169
|
-
block << sprintf("%8.8s: %s", 'missed', missed(f.missed_lines).join(", "))
|
|
170
|
-
blocks << block.join("\n")
|
|
171
|
-
end
|
|
172
|
-
"\n" << blocks.join("\n\n") << "\n\n"
|
|
173
|
-
end
|
|
174
|
-
|
|
175
197
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
class SimpleCov::Formatter::Console
|
|
3
|
+
module BlockOutput
|
|
4
|
+
|
|
5
|
+
# format per-file results output as plain text blocks
|
|
6
|
+
def output(files, root, show_branch)
|
|
7
|
+
blocks = []
|
|
8
|
+
files.each do |f|
|
|
9
|
+
block = []
|
|
10
|
+
block << sprintf("%8.8s: %s", 'file', f.filename.gsub(root + "/", ''))
|
|
11
|
+
block << sprintf("%8.8s: %s (%d/%d lines)", 'coverage',
|
|
12
|
+
colorize(sprintf("%.2f%%", f.covered_percent)),
|
|
13
|
+
f.covered_lines.count, f.lines_of_code)
|
|
14
|
+
block << sprintf("%8.8s: %s", 'missed', trunc(missed(f.missed_lines).join(", ")))
|
|
15
|
+
if show_branch
|
|
16
|
+
block << sprintf("%8.8s: %s (%d/%d branches)", 'branches',
|
|
17
|
+
colorize(sprintf("%.2f%%", f.coverage_statistics[:branch].percent)),
|
|
18
|
+
(f.total_branches.count - f.missed_branches.count), f.total_branches.count)
|
|
19
|
+
block << sprintf("%8.8s: %s", 'missed', branches_missed(f.missed_branches).join(", "))
|
|
20
|
+
end
|
|
21
|
+
blocks << block.join("\n")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
"\n" + blocks.join("\n\n") + "\n\n"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'terminal-table'
|
|
2
|
+
|
|
3
|
+
class SimpleCov::Formatter::Console
|
|
4
|
+
module TableOutput
|
|
5
|
+
|
|
6
|
+
# format per-file results output using Terminal::Table
|
|
7
|
+
def output(files, root,show_branch)
|
|
8
|
+
table = files.map do |f|
|
|
9
|
+
row = [
|
|
10
|
+
colorize(pct(f.covered_percent)),
|
|
11
|
+
f.filename.gsub(root + "/", ''),
|
|
12
|
+
f.lines_of_code,
|
|
13
|
+
f.missed_lines.count,
|
|
14
|
+
trunc(missed(f.missed_lines).join(", ")),
|
|
15
|
+
]
|
|
16
|
+
if show_branch
|
|
17
|
+
row += [
|
|
18
|
+
colorize(pct(f.coverage_statistics[:branch].percent)),
|
|
19
|
+
f.total_branches.count,
|
|
20
|
+
f.missed_branches.count,
|
|
21
|
+
branches_missed(f.missed_branches).join(", ")
|
|
22
|
+
]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
row
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
table_options = SimpleCov::Formatter::Console.table_options || {}
|
|
29
|
+
if !table_options.kind_of?(Hash) then
|
|
30
|
+
raise ArgumentError.new("SimpleCov::Formatter::Console.table_options must be a Hash")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
headings = %w{ coverage file lines missed missing }
|
|
34
|
+
if show_branch
|
|
35
|
+
headings += [
|
|
36
|
+
'branch coverage',
|
|
37
|
+
'branches',
|
|
38
|
+
'branches missed',
|
|
39
|
+
'branches missing'
|
|
40
|
+
]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
opts = table_options.merge({:headings => headings, :rows => table})
|
|
44
|
+
Terminal::Table.new(opts)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
data/simplecov-console.gemspec
CHANGED
|
@@ -2,66 +2,62 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: simplecov-console 0.
|
|
5
|
+
# stub: simplecov-console 0.9.1 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "simplecov-console".freeze
|
|
9
|
-
s.version = "0.
|
|
9
|
+
s.version = "0.9.1"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.require_paths = ["lib".freeze]
|
|
13
13
|
s.authors = ["Chetan Sarva".freeze]
|
|
14
|
-
s.date = "
|
|
14
|
+
s.date = "2021-02-01"
|
|
15
15
|
s.description = "Simple console output formatter for SimpleCov".freeze
|
|
16
16
|
s.email = "chetan@pixelcop.net".freeze
|
|
17
17
|
s.extra_rdoc_files = [
|
|
18
|
+
"CHANGELOG.md",
|
|
18
19
|
"LICENSE.txt",
|
|
19
20
|
"README.md"
|
|
20
21
|
]
|
|
21
22
|
s.files = [
|
|
22
23
|
".document",
|
|
24
|
+
"CHANGELOG.md",
|
|
23
25
|
"Gemfile",
|
|
24
26
|
"LICENSE.txt",
|
|
25
27
|
"README.md",
|
|
26
28
|
"Rakefile",
|
|
27
29
|
"VERSION",
|
|
28
30
|
"lib/simplecov-console.rb",
|
|
31
|
+
"lib/simplecov-console/output/block.rb",
|
|
32
|
+
"lib/simplecov-console/output/table.rb",
|
|
29
33
|
"simplecov-console.gemspec",
|
|
30
34
|
"test/helper.rb",
|
|
31
35
|
"test/test_simplecov-console.rb"
|
|
32
36
|
]
|
|
33
37
|
s.homepage = "http://github.com/chetan/simplecov-console".freeze
|
|
34
38
|
s.licenses = ["MIT".freeze]
|
|
35
|
-
s.rubygems_version = "3.
|
|
39
|
+
s.rubygems_version = "3.1.4".freeze
|
|
36
40
|
s.summary = "Simple console output formatter".freeze
|
|
37
41
|
|
|
38
42
|
if s.respond_to? :specification_version then
|
|
39
43
|
s.specification_version = 4
|
|
44
|
+
end
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
else
|
|
50
|
-
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
|
51
|
-
s.add_dependency(%q<terminal-table>.freeze, [">= 0"])
|
|
52
|
-
s.add_dependency(%q<ansi>.freeze, [">= 0"])
|
|
53
|
-
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
|
54
|
-
s.add_dependency(%q<yard>.freeze, [">= 0"])
|
|
55
|
-
s.add_dependency(%q<bundler>.freeze, ["~> 1.2"])
|
|
56
|
-
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
|
57
|
-
end
|
|
46
|
+
if s.respond_to? :add_runtime_dependency then
|
|
47
|
+
s.add_runtime_dependency(%q<simplecov>.freeze, [">= 0"])
|
|
48
|
+
s.add_runtime_dependency(%q<terminal-table>.freeze, [">= 0"])
|
|
49
|
+
s.add_runtime_dependency(%q<ansi>.freeze, [">= 0"])
|
|
50
|
+
s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
|
|
51
|
+
s.add_development_dependency(%q<yard>.freeze, [">= 0"])
|
|
52
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 2.1"])
|
|
53
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
|
58
54
|
else
|
|
59
55
|
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
|
60
56
|
s.add_dependency(%q<terminal-table>.freeze, [">= 0"])
|
|
61
57
|
s.add_dependency(%q<ansi>.freeze, [">= 0"])
|
|
62
58
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
|
63
59
|
s.add_dependency(%q<yard>.freeze, [">= 0"])
|
|
64
|
-
s.add_dependency(%q<bundler>.freeze, ["~> 1
|
|
60
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 2.1"])
|
|
65
61
|
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
|
66
62
|
end
|
|
67
63
|
end
|
|
@@ -14,10 +14,35 @@ class TestSimplecovConsole < MiniTest::Test
|
|
|
14
14
|
:covered_percent
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
+
CoverageStatistics = Struct.new(
|
|
18
|
+
:percent
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
Branch = Struct.new(
|
|
22
|
+
:start_line,
|
|
23
|
+
:type
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
SourceFileWithBranches = Struct.new(
|
|
27
|
+
:filename,
|
|
28
|
+
:lines_of_code,
|
|
29
|
+
:covered_lines,
|
|
30
|
+
:missed_lines,
|
|
31
|
+
:covered_percent,
|
|
32
|
+
:coverage_statistics,
|
|
33
|
+
:total_branches,
|
|
34
|
+
:missed_branches
|
|
35
|
+
)
|
|
36
|
+
|
|
17
37
|
def setup
|
|
18
38
|
@console = SimpleCov::Formatter::Console.new
|
|
19
39
|
end
|
|
20
40
|
|
|
41
|
+
def teardown
|
|
42
|
+
SimpleCov::Formatter::Console.output_style = 'table'
|
|
43
|
+
SimpleCov::Formatter::Console.max_lines = 0
|
|
44
|
+
end
|
|
45
|
+
|
|
21
46
|
def test_defined
|
|
22
47
|
assert defined?(SimpleCov::Formatter::Console)
|
|
23
48
|
assert defined?(SimpleCov::Formatter::Console::VERSION)
|
|
@@ -27,26 +52,71 @@ class TestSimplecovConsole < MiniTest::Test
|
|
|
27
52
|
missed_lines = [Line.new(1), Line.new(2),
|
|
28
53
|
Line.new(3), Line.new(5)]
|
|
29
54
|
expected_result = ["1-3", "5"]
|
|
30
|
-
assert_equal @console.missed(missed_lines)
|
|
55
|
+
assert_equal expected_result, @console.missed(missed_lines)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_max_missed
|
|
59
|
+
SimpleCov::Formatter::Console.max_lines = 1
|
|
60
|
+
missed_lines = [Line.new(1), Line.new(2),
|
|
61
|
+
Line.new(3), Line.new(5)]
|
|
62
|
+
expected_result = ["1-3", "..."]
|
|
63
|
+
assert_equal expected_result, @console.missed(missed_lines)
|
|
64
|
+
|
|
65
|
+
SimpleCov::Formatter::Console.max_lines = 3
|
|
66
|
+
expected_result = ["1-3", "5"]
|
|
67
|
+
assert_equal expected_result, @console.missed(missed_lines)
|
|
31
68
|
end
|
|
32
69
|
|
|
33
70
|
def test_table_output
|
|
34
71
|
SimpleCov::Formatter::Console.output_style = 'table'
|
|
72
|
+
@console.include_output_style
|
|
35
73
|
files = [
|
|
36
74
|
SourceFile.new('foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0)
|
|
37
75
|
]
|
|
38
|
-
actual = @console.
|
|
76
|
+
actual = @console.output(files,'/',false)
|
|
77
|
+
assert actual.is_a? Terminal::Table
|
|
78
|
+
assert_equal 1, actual.rows.count
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_table_output_with_branches
|
|
82
|
+
SimpleCov::Formatter::Console.output_style = 'table'
|
|
83
|
+
@console.include_output_style
|
|
84
|
+
files = [
|
|
85
|
+
SourceFileWithBranches.new(
|
|
86
|
+
'foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0,
|
|
87
|
+
{branch: CoverageStatistics.new(50.0)}, [1,2],
|
|
88
|
+
[Branch.new(2, :then)]
|
|
89
|
+
)
|
|
90
|
+
]
|
|
91
|
+
actual = @console.output(files,'/',true)
|
|
39
92
|
assert actual.is_a? Terminal::Table
|
|
40
|
-
assert_equal 1, actual.rows.count
|
|
93
|
+
assert_equal 1, actual.rows.count
|
|
41
94
|
end
|
|
42
95
|
|
|
43
96
|
def test_block_output
|
|
44
97
|
SimpleCov::Formatter::Console.use_colors = false
|
|
45
98
|
SimpleCov::Formatter::Console.output_style = 'block'
|
|
99
|
+
@console.include_output_style
|
|
100
|
+
|
|
46
101
|
files = [
|
|
47
102
|
SourceFile.new('foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0)
|
|
48
103
|
]
|
|
49
104
|
expected = "\n file: foo.rb\ncoverage: 40.00% (2/5 lines)\n missed: 1, 4-5\n\n"
|
|
50
|
-
assert_equal expected, @console.
|
|
105
|
+
assert_equal expected, @console.output(files,'/',false)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_block_output_with_branches
|
|
109
|
+
SimpleCov::Formatter::Console.use_colors = false
|
|
110
|
+
SimpleCov::Formatter::Console.output_style = 'block'
|
|
111
|
+
@console.include_output_style
|
|
112
|
+
files = [
|
|
113
|
+
SourceFileWithBranches.new(
|
|
114
|
+
'foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0,
|
|
115
|
+
{branch: CoverageStatistics.new(50.0)}, [1,2],
|
|
116
|
+
[Branch.new(2, :then)]
|
|
117
|
+
)
|
|
118
|
+
]
|
|
119
|
+
expected = "\n file: foo.rb\ncoverage: 40.00% (2/5 lines)\n missed: 1, 4-5\nbranches: 50.00% (1/2 branches)\n missed: 2[then]\n\n"
|
|
120
|
+
assert_equal expected, @console.output(files,'/',true)
|
|
51
121
|
end
|
|
52
122
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simplecov-console
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chetan Sarva
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: simplecov
|
|
@@ -86,14 +86,14 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '1
|
|
89
|
+
version: '2.1'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '1
|
|
96
|
+
version: '2.1'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: juwelier
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -113,16 +113,20 @@ email: chetan@pixelcop.net
|
|
|
113
113
|
executables: []
|
|
114
114
|
extensions: []
|
|
115
115
|
extra_rdoc_files:
|
|
116
|
+
- CHANGELOG.md
|
|
116
117
|
- LICENSE.txt
|
|
117
118
|
- README.md
|
|
118
119
|
files:
|
|
119
120
|
- ".document"
|
|
121
|
+
- CHANGELOG.md
|
|
120
122
|
- Gemfile
|
|
121
123
|
- LICENSE.txt
|
|
122
124
|
- README.md
|
|
123
125
|
- Rakefile
|
|
124
126
|
- VERSION
|
|
125
127
|
- lib/simplecov-console.rb
|
|
128
|
+
- lib/simplecov-console/output/block.rb
|
|
129
|
+
- lib/simplecov-console/output/table.rb
|
|
126
130
|
- simplecov-console.gemspec
|
|
127
131
|
- test/helper.rb
|
|
128
132
|
- test/test_simplecov-console.rb
|
|
@@ -130,7 +134,7 @@ homepage: http://github.com/chetan/simplecov-console
|
|
|
130
134
|
licenses:
|
|
131
135
|
- MIT
|
|
132
136
|
metadata: {}
|
|
133
|
-
post_install_message:
|
|
137
|
+
post_install_message:
|
|
134
138
|
rdoc_options: []
|
|
135
139
|
require_paths:
|
|
136
140
|
- lib
|
|
@@ -145,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
145
149
|
- !ruby/object:Gem::Version
|
|
146
150
|
version: '0'
|
|
147
151
|
requirements: []
|
|
148
|
-
rubygems_version: 3.
|
|
149
|
-
signing_key:
|
|
152
|
+
rubygems_version: 3.1.4
|
|
153
|
+
signing_key:
|
|
150
154
|
specification_version: 4
|
|
151
155
|
summary: Simple console output formatter
|
|
152
156
|
test_files: []
|