simplecov-console 0.6.0 → 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 +4 -4
- data/CHANGELOG.md +26 -0
- data/Gemfile +1 -1
- data/README.md +130 -15
- data/VERSION +1 -1
- data/lib/simplecov-console.rb +75 -31
- 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 +100 -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: 816c658af1a3631341c32bc6de8c315c9630dabc514f2afaafce3e5d2a08c4c5
|
4
|
+
data.tar.gz: 91eb4d147fdda1bd77860ed0ee7cf407baec1882fd56075a5092850663eaec14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76945af6f21860703b3c0e5f0e78bb24d9411698fd6bc98576e03eadd2bc5d86e60600539ee081f26003431e06d35d5fde4f47b604b4880974a401954da914b1
|
7
|
+
data.tar.gz: 60a05bd402183c8797523df22d8f3c947f650f059ec18ad2a02420639c821224d007b6f2eaf57696ca0776aec359d2e6265be1591f77c38f43338ddcbadb8714
|
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,52 +47,167 @@ 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
|
+
```
|
83
113
|
|
84
|
-
|
114
|
+
#### Maximum length of missing lines
|
85
115
|
|
86
|
-
|
87
|
-
|
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
|
+
```
|
122
|
+
|
123
|
+
#### Table options
|
124
|
+
|
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
|
-
|
131
|
+
```
|
132
|
+
|
133
|
+
#### Block output style
|
134
|
+
|
135
|
+
As an alternative to the default table output format, a simpler block format is
|
136
|
+
also available:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
SimpleCov::Formatter::Console.output_style = 'block'
|
140
|
+
```
|
141
|
+
|
142
|
+
Example output:
|
143
|
+
|
144
|
+
```text
|
145
|
+
COVERAGE: 82.34% -- 2345/2848 lines in 111 files
|
146
|
+
|
147
|
+
showing bottom (worst) 5 of 69 files
|
148
|
+
|
149
|
+
file: lib/bixby/api/websocket_server.rb
|
150
|
+
coverage: 22.73% (17/22 lines)
|
151
|
+
missed: 11, 14, 17-18, 20-22, 24, 28-30, 32, 36-...
|
152
|
+
|
153
|
+
file: app/models/role.rb
|
154
|
+
coverage: 30.77% (9/13 lines)
|
155
|
+
missed: 28-34, 36-37
|
156
|
+
|
157
|
+
file: lib/bixby/modules/metrics/rescan.rb
|
158
|
+
coverage: 32.14% (19/28 lines)
|
159
|
+
missed: 19-23, 27-31, 33-37, 39-41, 43
|
160
|
+
|
161
|
+
file: lib/archie/mail.rb
|
162
|
+
coverage: 42.86% (8/14 lines)
|
163
|
+
missed: 6-8, 12-15, 22
|
164
|
+
|
165
|
+
file: lib/archie/controller.rb
|
166
|
+
coverage: 44.00% (28/50 lines)
|
167
|
+
missed: 18-21, 23, 27-30, 32, 38-40, 44-45, 48-4...
|
168
|
+
|
169
|
+
42 file(s) with 100% coverage not shown
|
170
|
+
```
|
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
|
+
+----------+-------------------------------+-------+--------+---------------+-----------------+----------+-----------------+------------------+
|
92
187
|
```
|
93
188
|
|
94
189
|
## History
|
95
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
|
+
|
207
|
+
### 0.7 (2020.03.04)
|
208
|
+
|
209
|
+
- Added new 'block' style output option - thanks [@hpainter](https://github.com/hpainter)! ([#15](https://github.com/chetan/simplecov-console/issues/15))
|
210
|
+
|
96
211
|
### 0.6 (2019.11.08)
|
97
212
|
|
98
213
|
- Added new config options: `sort`, `show_covered`, and `max_rows`
|
@@ -114,5 +229,5 @@ SimpleCov.formatter = SimpleCov::Formatter::Console
|
|
114
229
|
|
115
230
|
### Copyright
|
116
231
|
|
117
|
-
Copyright (c)
|
232
|
+
Copyright (c) 2020 Chetan Sarva. See LICENSE.txt for
|
118
233
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
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,13 +18,37 @@ 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
|
|
23
28
|
# configure sort from SORT env var
|
24
29
|
SimpleCov::Formatter::Console.sort = ENV.fetch('SORT', 'coverage')
|
25
30
|
|
31
|
+
# configure output format ('table', 'block')
|
32
|
+
SimpleCov::Formatter::Console.output_style = ENV.fetch('OUTPUT_STYLE', 'table')
|
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
|
+
|
26
50
|
def format(result)
|
51
|
+
include_output_style
|
27
52
|
|
28
53
|
root = nil
|
29
54
|
if Module.const_defined? :ROOT then
|
@@ -37,7 +62,11 @@ class SimpleCov::Formatter::Console
|
|
37
62
|
end
|
38
63
|
|
39
64
|
puts
|
40
|
-
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
|
41
70
|
puts
|
42
71
|
|
43
72
|
if root.nil? then
|
@@ -45,16 +74,23 @@ class SimpleCov::Formatter::Console
|
|
45
74
|
end
|
46
75
|
|
47
76
|
if SimpleCov::Formatter::Console.sort == 'coverage'
|
48
|
-
|
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
|
49
85
|
else
|
50
|
-
files = result.files
|
86
|
+
files = result.files.to_a
|
51
87
|
end
|
52
88
|
|
53
89
|
covered_files = 0
|
54
90
|
|
55
91
|
unless SimpleCov::Formatter::Console.show_covered
|
56
92
|
files.select!{ |file|
|
57
|
-
if file.covered_percent == 100 then
|
93
|
+
if file.covered_percent == 100 && (!show_branch_coverage || file.coverage_statistics[:branch].percent == 100) then
|
58
94
|
covered_files += 1
|
59
95
|
false
|
60
96
|
else
|
@@ -66,32 +102,14 @@ class SimpleCov::Formatter::Console
|
|
66
102
|
end
|
67
103
|
end
|
68
104
|
|
69
|
-
table = files.map do |f|
|
70
|
-
[
|
71
|
-
colorize(pct(f)),
|
72
|
-
f.filename.gsub(root + "/", ''),
|
73
|
-
f.lines_of_code,
|
74
|
-
f.missed_lines.count,
|
75
|
-
missed(f.missed_lines).join(", ")
|
76
|
-
]
|
77
|
-
end
|
78
|
-
|
79
105
|
max_rows = SimpleCov::Formatter::Console.max_rows
|
80
106
|
|
81
|
-
if ![-1, nil].include?(max_rows) &&
|
82
|
-
puts "showing bottom (worst) #{max_rows} of #{
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
table_options = SimpleCov::Formatter::Console.table_options || {}
|
87
|
-
if !table_options.kind_of?(Hash) then
|
88
|
-
raise ArgumentError.new("SimpleCov::Formatter::Console.table_options must be a Hash")
|
107
|
+
if ![-1, nil].include?(max_rows) && files.size > max_rows then
|
108
|
+
puts "showing bottom (worst) #{max_rows} of #{files.size} files"
|
109
|
+
files = files.slice(0, max_rows)
|
89
110
|
end
|
90
|
-
headings = %w{ coverage file lines missed missing }
|
91
111
|
|
92
|
-
|
93
|
-
t = Terminal::Table.new(opts)
|
94
|
-
puts t
|
112
|
+
puts output(files, root, show_branch_coverage)
|
95
113
|
|
96
114
|
if covered_files > 0 then
|
97
115
|
puts "#{covered_files} file(s) with 100% coverage not shown"
|
@@ -99,6 +117,17 @@ class SimpleCov::Formatter::Console
|
|
99
117
|
|
100
118
|
end
|
101
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
|
102
131
|
def missed(missed_lines)
|
103
132
|
groups = {}
|
104
133
|
base = nil
|
@@ -124,11 +153,27 @@ class SimpleCov::Formatter::Console
|
|
124
153
|
end
|
125
154
|
end
|
126
155
|
|
156
|
+
if SimpleCov::Formatter::Console.max_lines > 0 then
|
157
|
+
# show at most N missing groups of lines
|
158
|
+
group_str = group_str[0, SimpleCov::Formatter::Console.max_lines] << "..."
|
159
|
+
end
|
160
|
+
|
127
161
|
group_str
|
128
162
|
end
|
129
163
|
|
130
|
-
|
131
|
-
|
164
|
+
# Truncate string to at most N chars (as defined by missing_len)
|
165
|
+
def trunc(str)
|
166
|
+
return str if str.include?("...") # already truncated, skip
|
167
|
+
|
168
|
+
len = SimpleCov::Formatter::Console.missing_len
|
169
|
+
if len > 0 && str.size > len then
|
170
|
+
str = str[0, len].gsub(/,(\s+)?$/, '') + ' ...'
|
171
|
+
end
|
172
|
+
str
|
173
|
+
end
|
174
|
+
|
175
|
+
def pct(number)
|
176
|
+
sprintf("%6.2f%%", number)
|
132
177
|
end
|
133
178
|
|
134
179
|
def use_colors?
|
@@ -148,5 +193,4 @@ class SimpleCov::Formatter::Console
|
|
148
193
|
ANSI.red { s }
|
149
194
|
end
|
150
195
|
end
|
151
|
-
|
152
196
|
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.0 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.0"
|
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-01-21"
|
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
|
@@ -2,21 +2,117 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestSimplecovConsole < MiniTest::Test
|
4
4
|
|
5
|
-
|
5
|
+
# mock for SimpleCov::SourceFile::Line
|
6
|
+
Line = Struct.new(:line_number)
|
7
|
+
|
8
|
+
# mock for SimpleCov::SourceFile
|
9
|
+
SourceFile = Struct.new(
|
10
|
+
:filename,
|
11
|
+
:lines_of_code,
|
12
|
+
:covered_lines,
|
13
|
+
:missed_lines,
|
14
|
+
:covered_percent
|
15
|
+
)
|
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
|
+
)
|
6
36
|
|
7
37
|
def setup
|
8
38
|
@console = SimpleCov::Formatter::Console.new
|
9
39
|
end
|
10
40
|
|
41
|
+
def teardown
|
42
|
+
SimpleCov::Formatter::Console.output_style = 'table'
|
43
|
+
SimpleCov::Formatter::Console.max_lines = 0
|
44
|
+
end
|
45
|
+
|
11
46
|
def test_defined
|
12
47
|
assert defined?(SimpleCov::Formatter::Console)
|
13
48
|
assert defined?(SimpleCov::Formatter::Console::VERSION)
|
14
49
|
end
|
15
50
|
|
16
51
|
def test_missed
|
17
|
-
missed_lines = [
|
18
|
-
|
52
|
+
missed_lines = [Line.new(1), Line.new(2),
|
53
|
+
Line.new(3), Line.new(5)]
|
19
54
|
expected_result = ["1-3", "5"]
|
20
|
-
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
|
+
end
|
65
|
+
|
66
|
+
def test_table_output
|
67
|
+
SimpleCov::Formatter::Console.output_style = 'table'
|
68
|
+
@console.include_output_style
|
69
|
+
files = [
|
70
|
+
SourceFile.new('foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0)
|
71
|
+
]
|
72
|
+
actual = @console.output(files,'/',false)
|
73
|
+
assert actual.is_a? Terminal::Table
|
74
|
+
assert_equal 1, actual.rows.count
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_table_output_with_branches
|
78
|
+
SimpleCov::Formatter::Console.output_style = 'table'
|
79
|
+
@console.include_output_style
|
80
|
+
files = [
|
81
|
+
SourceFileWithBranches.new(
|
82
|
+
'foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0,
|
83
|
+
{branch: CoverageStatistics.new(50.0)}, [1,2],
|
84
|
+
[Branch.new(2, :then)]
|
85
|
+
)
|
86
|
+
]
|
87
|
+
actual = @console.output(files,'/',true)
|
88
|
+
assert actual.is_a? Terminal::Table
|
89
|
+
assert_equal 1, actual.rows.count
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_block_output
|
93
|
+
SimpleCov::Formatter::Console.use_colors = false
|
94
|
+
SimpleCov::Formatter::Console.output_style = 'block'
|
95
|
+
@console.include_output_style
|
96
|
+
|
97
|
+
files = [
|
98
|
+
SourceFile.new('foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0)
|
99
|
+
]
|
100
|
+
expected = "\n file: foo.rb\ncoverage: 40.00% (2/5 lines)\n missed: 1, 4-5\n\n"
|
101
|
+
assert_equal expected, @console.output(files,'/',false)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_block_output_with_branches
|
105
|
+
SimpleCov::Formatter::Console.use_colors = false
|
106
|
+
SimpleCov::Formatter::Console.output_style = 'block'
|
107
|
+
@console.include_output_style
|
108
|
+
files = [
|
109
|
+
SourceFileWithBranches.new(
|
110
|
+
'foo.rb',5,[2,3],[Line.new(1), Line.new(4), Line.new(5)],40.0,
|
111
|
+
{branch: CoverageStatistics.new(50.0)}, [1,2],
|
112
|
+
[Branch.new(2, :then)]
|
113
|
+
)
|
114
|
+
]
|
115
|
+
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"
|
116
|
+
assert_equal expected, @console.output(files,'/',true)
|
21
117
|
end
|
22
118
|
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.0
|
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-01-21 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: []
|