simple_cov-formatter-terminal 0.2.4 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 955970eab8c1321b2666ee16641ee768fa9c403c05f388091fc093fb0755d7c0
4
- data.tar.gz: 5484b17a524a65b0bdf996aa72169add91c2a1a59f193ab7ca09f6be4a272fd5
3
+ metadata.gz: afe58af417f8a70624c3a6deefa824a6e38f9135ac4fb25d39c02d88d08f5171
4
+ data.tar.gz: 6b518978a552895d25af3bc9a5c571147a609bb7709efcace7043fccb9a317af
5
5
  SHA512:
6
- metadata.gz: aed8c163266de2a1decc875607aa7ba00aea4d81b309ec49b655b157d7fcb60f744264cdd6ffdf4801e1439f790c277f960e4aa8d0808701c1c76512512c4f6f
7
- data.tar.gz: 900a825a976d73ba68ce91d16ec72cbdbcf3343acd4de5cfe8cf018f23534118bc05df31a9492fedb9580382ef9a22e8275c32ffc5618cf9a1b7a6fefab51eeb
6
+ metadata.gz: 8fe5ff1652801cdd2d012a53374aa5e30c4b10a475edbcd9d606eacfe62a1aab75a77f45a83e7c04bcf06301e2a933737864aee8c11b63ce1622b3faa1f2bca2
7
+ data.tar.gz: e75de61327497b94697d31472da4d2c01bb248785a8082cac0ea61987b660ce4c98dd3592b0fb8449c0f69f85ef8c428503496e560abf9698ab4e80d0305c536
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.3.0 (2023-11-19)
2
+
3
+ - Print only uncovered lines by default
4
+
1
5
  ## v0.2.4 (2023-05-30)
2
6
  ### Fixed
3
7
  - Removed dangling memoist requires
data/Gemfile.lock CHANGED
@@ -1,50 +1,63 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_cov-formatter-terminal (0.2.4)
4
+ simple_cov-formatter-terminal (0.3.0)
5
5
  activesupport (>= 7.0.4, < 8)
6
6
  memo_wise (>= 1.7.0, < 2)
7
7
  rouge (>= 4.0.0, < 5)
8
8
  rspec-core (>= 3.11.0, < 4)
9
+ runger_config (>= 3.0.0)
9
10
  simplecov (>= 0.21.2, < 1)
10
11
 
11
12
  GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
14
- activesupport (7.0.5)
15
+ activesupport (7.1.2)
16
+ base64
17
+ bigdecimal
15
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ connection_pool (>= 2.2.5)
20
+ drb
16
21
  i18n (>= 1.6, < 2)
17
22
  minitest (>= 5.1)
23
+ mutex_m
18
24
  tzinfo (~> 2.0)
19
25
  ast (2.4.2)
26
+ base64 (0.2.0)
27
+ bigdecimal (3.1.4)
20
28
  byebug (11.1.3)
21
29
  climate_control (1.2.0)
22
30
  coderay (1.1.3)
23
- colorize (0.8.1)
24
31
  concurrent-ruby (1.2.2)
32
+ connection_pool (2.4.1)
25
33
  diff-lcs (1.5.0)
26
34
  docile (1.4.0)
27
- i18n (1.13.0)
35
+ drb (2.2.0)
36
+ ruby2_keywords
37
+ i18n (1.14.1)
28
38
  concurrent-ruby (~> 1.0)
29
39
  json (2.6.3)
30
- memo_wise (1.7.0)
31
- memoist (0.16.2)
40
+ language_server-protocol (3.17.0.3)
41
+ memo_wise (1.8.0)
32
42
  method_source (1.0.0)
33
- minitest (5.18.0)
43
+ minitest (5.20.0)
44
+ mutex_m (0.2.0)
34
45
  parallel (1.23.0)
35
- parser (3.2.2.1)
46
+ parser (3.2.2.4)
36
47
  ast (~> 2.4.1)
48
+ racc
37
49
  pry (0.14.2)
38
50
  coderay (~> 1.1)
39
51
  method_source (~> 1.0)
40
52
  pry-byebug (3.10.1)
41
53
  byebug (~> 11.0)
42
54
  pry (>= 0.13, < 0.15)
55
+ racc (1.7.3)
43
56
  rainbow (3.1.1)
44
- rake (13.0.6)
45
- regexp_parser (2.8.0)
46
- rexml (3.2.5)
47
- rouge (4.1.1)
57
+ rake (13.1.0)
58
+ regexp_parser (2.8.2)
59
+ rexml (3.2.6)
60
+ rouge (4.2.0)
48
61
  rspec (3.12.0)
49
62
  rspec-core (~> 3.12.0)
50
63
  rspec-expectations (~> 3.12.0)
@@ -54,40 +67,44 @@ GEM
54
67
  rspec-expectations (3.12.3)
55
68
  diff-lcs (>= 1.2.0, < 2.0)
56
69
  rspec-support (~> 3.12.0)
57
- rspec-mocks (3.12.5)
70
+ rspec-mocks (3.12.6)
58
71
  diff-lcs (>= 1.2.0, < 2.0)
59
72
  rspec-support (~> 3.12.0)
60
- rspec-support (3.12.0)
61
- rubocop (1.51.0)
73
+ rspec-support (3.12.1)
74
+ rubocop (1.57.2)
62
75
  json (~> 2.3)
76
+ language_server-protocol (>= 3.17.0)
63
77
  parallel (~> 1.10)
64
- parser (>= 3.2.0.0)
78
+ parser (>= 3.2.2.4)
65
79
  rainbow (>= 2.2.2, < 4.0)
66
80
  regexp_parser (>= 1.8, < 3.0)
67
81
  rexml (>= 3.2.5, < 4.0)
68
- rubocop-ast (>= 1.28.0, < 2.0)
82
+ rubocop-ast (>= 1.28.1, < 2.0)
69
83
  ruby-progressbar (~> 1.7)
70
84
  unicode-display_width (>= 2.4.0, < 3.0)
71
- rubocop-ast (1.28.1)
85
+ rubocop-ast (1.30.0)
72
86
  parser (>= 3.2.1.0)
73
- rubocop-capybara (2.18.0)
87
+ rubocop-capybara (2.19.0)
74
88
  rubocop (~> 1.41)
75
- rubocop-factory_bot (2.22.0)
89
+ rubocop-factory_bot (2.24.0)
76
90
  rubocop (~> 1.33)
77
- rubocop-performance (1.18.0)
91
+ rubocop-performance (1.19.1)
78
92
  rubocop (>= 1.7.0, < 2.0)
79
93
  rubocop-ast (>= 0.4.0)
80
- rubocop-rspec (2.22.0)
81
- rubocop (~> 1.33)
94
+ rubocop-rspec (2.25.0)
95
+ rubocop (~> 1.40)
82
96
  rubocop-capybara (~> 2.17)
83
97
  rubocop-factory_bot (~> 2.22)
84
98
  ruby-progressbar (1.13.0)
85
- runger_release_assistant (0.4.0)
99
+ ruby2_keywords (0.0.5)
100
+ runger_config (3.0.1)
101
+ activesupport (>= 7.1.2)
102
+ runger_release_assistant (0.5.0)
86
103
  activesupport (>= 6, < 8)
87
- colorize (~> 0.8)
88
- memoist (~> 0.16)
104
+ memo_wise (>= 1.7, < 2)
105
+ rainbow (>= 3.0, < 4)
89
106
  slop (~> 4.8)
90
- runger_style (0.3.0)
107
+ runger_style (0.5.1)
91
108
  rubocop (>= 1.38.0, < 2)
92
109
  simplecov (0.22.0)
93
110
  docile (~> 1.1)
@@ -101,7 +118,7 @@ GEM
101
118
  slop (4.10.1)
102
119
  tzinfo (2.0.6)
103
120
  concurrent-ruby (~> 1.0)
104
- unicode-display_width (2.4.2)
121
+ unicode-display_width (2.5.0)
105
122
 
106
123
  PLATFORMS
107
124
  ruby
data/README.md CHANGED
@@ -37,6 +37,16 @@ SimpleCov.start
37
37
  spec file (e.g. `bin/rspec spec/models/user_spec.rb`) and not when multiple specs are executed (e.g.
38
38
  when simply running `bin/rspec` without any argument).
39
39
 
40
+ ## Which lines to print
41
+
42
+ By default, only uncovered lines will be printed.
43
+
44
+ If you would like to print all lines, add this to your `spec_helper.rb` file:
45
+
46
+ ```rb
47
+ SimpleCov::Formatter::Terminal.config.lines_to_print = :all
48
+ ```
49
+
40
50
  ### Modifying the `spec_to_app_file_map`
41
51
 
42
52
  `SimpleCov::Formatter::Terminal` has a default hash that is used to map spec files to their
@@ -25,4 +25,12 @@ module SimpleCov::Formatter::Terminal::BranchCoverage
25
25
  join(', ').
26
26
  presence
27
27
  end
28
+
29
+ memo_wise \
30
+ def line_numbers_with_missing_branches(sourcefile)
31
+ uncovered_branches(sourcefile).
32
+ map(&:start_line).
33
+ uniq.
34
+ sort
35
+ end
28
36
  end
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './spec_to_app_mapping'
3
+ require_relative 'spec_to_app_mapping'
4
4
  require 'memo_wise'
5
5
 
6
- class SimpleCov::Formatter::Terminal::Config
6
+ class SimpleCov::Formatter::Terminal::Config < Anyway::Config
7
7
  prepend MemoWise
8
8
  include SimpleCov::Formatter::Terminal::SpecToAppMapping
9
9
 
10
- attr_accessor :spec_to_app_file_map, :unmappable_spec_regexes
11
-
12
- def initialize
13
- @spec_to_app_file_map =
14
- SimpleCov::Formatter::Terminal::SpecToAppMapping.default_spec_to_app_map
15
- @unmappable_spec_regexes =
16
- SimpleCov::Formatter::Terminal::SpecToAppMapping::DEFAULT_UNMAPPABLE_SPEC_REGEXES
10
+ module LinesToPrint
11
+ ALL = :all
12
+ UNCOVERED = :uncovered
17
13
  end
18
14
 
15
+ attr_config(
16
+ lines_to_print: LinesToPrint::UNCOVERED,
17
+ spec_to_app_file_map:
18
+ SimpleCov::Formatter::Terminal::SpecToAppMapping.default_spec_to_app_map,
19
+ unmappable_spec_regexes:
20
+ SimpleCov::Formatter::Terminal::SpecToAppMapping::DEFAULT_UNMAPPABLE_SPEC_REGEXES,
21
+ )
22
+
19
23
  memo_wise \
20
24
  def write_target_info_file?
21
25
  ENV.fetch('SIMPLECOV_WRITE_TARGET_TO_FILE', nil) == '1'
@@ -7,7 +7,7 @@ class SimpleCov::Formatter::Terminal::LinePrinter
7
7
  include SimpleCov::Formatter::Terminal::BranchCoverage
8
8
  include SimpleCov::Formatter::Terminal::ColorPrinting
9
9
 
10
- def initialize(targeted_application_file)
10
+ def initialize(targeted_application_file = nil)
11
11
  @targeted_application_file = targeted_application_file
12
12
  end
13
13
 
@@ -30,18 +30,27 @@ class SimpleCov::Formatter::Terminal::LinePrinter
30
30
  end
31
31
 
32
32
  # rubocop:disable Style/StringConcatenation
33
- def numbered_line_output(line_number, color, source_code, missed_branch_info = nil)
33
+ def numbered_line_output(line_number, color, source_code = '', missed_branch_info = nil)
34
34
  colored_space =
35
35
  case color
36
36
  when :red_on_yellow, :white_on_red then color(' ', color)
37
37
  else color(' ', :white_on_green)
38
38
  end
39
39
 
40
- line_number_string =
40
+ line_number_width =
41
41
  if SimpleCov::Formatter::Terminal.config.write_target_info_file?
42
- ":::#{line_number}".rjust(6, ' ')
42
+ 6
43
+ else
44
+ 3
45
+ end
46
+
47
+ line_number_string =
48
+ if line_number.blank?
49
+ ' ' * line_number_width
50
+ elsif SimpleCov::Formatter::Terminal.config.write_target_info_file?
51
+ ":::#{line_number}".rjust(line_number_width, ' ')
43
52
  else
44
- line_number.to_s.rjust(3, ' ')
53
+ line_number.to_s.rjust(line_number_width, ' ')
45
54
  end
46
55
 
47
56
  output =
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './branch_coverage'
4
- require_relative './color_printing'
5
- require_relative './line_printer'
6
- require_relative './target_file_writer'
3
+ require_relative 'branch_coverage'
4
+ require_relative 'color_printing'
5
+ require_relative 'line_printer'
6
+ require_relative 'target_file_writer'
7
7
 
8
8
  class SimpleCov::Formatter::Terminal::ResultPrinter
9
9
  extend Forwardable
@@ -48,14 +48,32 @@ class SimpleCov::Formatter::Terminal::ResultPrinter
48
48
  end
49
49
 
50
50
  def print_coverage_details(sourcefile)
51
+ @sourcefile = sourcefile
52
+
51
53
  if SimpleCov::Formatter::Terminal.config.write_target_info_file?
52
54
  target_file_writer.write_target_info_file
53
55
  end
54
56
 
55
57
  puts("---- Coverage for #{targeted_application_file} ".ljust(80, '-').rstrip)
58
+
59
+ skipped_lines = []
56
60
  sourcefile.lines.each do |line|
57
- puts(line_printer.colored_line(line, sourcefile))
61
+ if print_line?(line.line_number)
62
+ if skipped_lines.any?
63
+ print_skipped_lines(skipped_lines)
64
+ end
65
+
66
+ puts(line_printer.colored_line(line, sourcefile))
67
+ skipped_lines = []
68
+ else
69
+ skipped_lines << line.line_number
70
+ end
71
+ end
72
+
73
+ if skipped_lines.any?
74
+ print_skipped_lines(skipped_lines)
58
75
  end
76
+
59
77
  puts(<<~LOG.squish)
60
78
  ----
61
79
  Line coverage: #{colorized_coverage(sourcefile.covered_percent)}
@@ -65,6 +83,20 @@ class SimpleCov::Formatter::Terminal::ResultPrinter
65
83
  LOG
66
84
  end
67
85
 
86
+ def print_skipped_lines(skipped_lines)
87
+ divider = ' -' * 40
88
+
89
+ puts(line_printer.numbered_line_output(nil, :white, divider))
90
+ puts(
91
+ line_printer.numbered_line_output(
92
+ nil,
93
+ :white,
94
+ "#{skipped_lines.size} covered line(s) omitted".center(80, ' '),
95
+ ),
96
+ )
97
+ puts(line_printer.numbered_line_output(nil, :white, divider))
98
+ end
99
+
68
100
  def print_no_coverage_info_found
69
101
  puts(<<~LOG.squish)
70
102
  No code coverage info was found for "#{targeted_application_file}". Try stopping and
@@ -120,6 +152,52 @@ class SimpleCov::Formatter::Terminal::ResultPrinter
120
152
  end
121
153
  end
122
154
 
155
+ def print_line?(line_number)
156
+ line_numbers_to_print.include?(line_number)
157
+ end
158
+
159
+ def sourcefile
160
+ @sourcefile ||= @result.files.find { _1.filename.end_with?(targeted_application_file) }
161
+ end
162
+
163
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
164
+ memo_wise \
165
+ def line_numbers_to_print
166
+ max_line_number = sourcefile.lines.map(&:line_number).max
167
+
168
+ begin
169
+ case SimpleCov::Formatter::Terminal.config.lines_to_print.to_sym
170
+ in SimpleCov::Formatter::Terminal::Config::LinesToPrint::ALL
171
+ (1..max_line_number).to_a
172
+ in SimpleCov::Formatter::Terminal::Config::LinesToPrint::UNCOVERED
173
+ line_numbers_to_print = []
174
+
175
+ sourcefile.lines.each do |line|
176
+ if (
177
+ line.coverage.nil? || (
178
+ (line.coverage > 0) &&
179
+ !line_numbers_with_missing_branches(sourcefile).include?(line.line_number)
180
+ )
181
+ )
182
+ next
183
+ end
184
+
185
+ line_number = line.line_number
186
+ contextualized_line_numbers =
187
+ ((line_number - 2)..(line_number + 2)).
188
+ to_a.
189
+ select do |context_line_number|
190
+ context_line_number.positive? && context_line_number <= max_line_number
191
+ end
192
+ line_numbers_to_print += contextualized_line_numbers
193
+ end
194
+
195
+ line_numbers_to_print
196
+ end
197
+ end.to_set
198
+ end
199
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
200
+
123
201
  memo_wise \
124
202
  def line_printer
125
203
  SimpleCov::Formatter::Terminal::LinePrinter.new(targeted_application_file)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './rails_awareness'
3
+ require_relative 'rails_awareness'
4
4
 
5
5
  module SimpleCov::Formatter::Terminal::SpecToAppMapping
6
6
  # rubocop:disable Lint/OrAssignmentToConstant
@@ -5,6 +5,6 @@ module SimpleCov::Formatter; end
5
5
 
6
6
  # rubocop:disable Style/StaticClass
7
7
  class SimpleCov::Formatter::Terminal
8
- VERSION = '0.2.4'
8
+ VERSION = '0.3.0'
9
9
  end
10
10
  # rubocop:enable Style/StaticClass
@@ -2,18 +2,20 @@
2
2
 
3
3
  class SimpleCov::Formatter::Terminal ; end # rubocop:disable Lint/EmptyClass
4
4
 
5
- require_relative 'terminal/config'
6
- require_relative 'terminal/file_determiner'
7
- require_relative 'terminal/r_spec_integration'
8
- require_relative 'terminal/result_printer'
9
- require_relative 'terminal/version'
10
5
  require 'active_support/core_ext/object/blank'
11
6
  require 'active_support/core_ext/string/filters'
7
+ require 'anyway_config'
12
8
  require 'memo_wise'
13
9
  require 'rouge'
14
10
  require 'rspec/core'
15
11
  require 'simplecov'
16
12
 
13
+ require_relative 'terminal/config'
14
+ require_relative 'terminal/file_determiner'
15
+ require_relative 'terminal/r_spec_integration'
16
+ require_relative 'terminal/result_printer'
17
+ require_relative 'terminal/version'
18
+
17
19
  class SimpleCov::Formatter::Terminal
18
20
  extend Forwardable
19
21
  prepend MemoWise
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency('memo_wise', '>= 1.7.0', '< 2')
37
37
  spec.add_dependency('rouge', '>= 4.0.0', '< 5')
38
38
  spec.add_dependency('rspec-core', '>= 3.11.0', '< 4')
39
+ spec.add_dependency('runger_config', '>= 3.0.0')
39
40
  spec.add_dependency('simplecov', '>= 0.21.2', '< 1')
40
41
 
41
42
  # For more information and examples about making a new gem, check out our
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_cov-formatter-terminal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Runger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-30 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -90,6 +90,20 @@ dependencies:
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '4'
93
+ - !ruby/object:Gem::Dependency
94
+ name: runger_config
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 3.0.0
100
+ type: :runtime
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 3.0.0
93
107
  - !ruby/object:Gem::Dependency
94
108
  name: simplecov
95
109
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
176
  - !ruby/object:Gem::Version
163
177
  version: '0'
164
178
  requirements: []
165
- rubygems_version: 3.4.13
179
+ rubygems_version: 3.4.22
166
180
  signing_key:
167
181
  specification_version: 4
168
182
  summary: Print detailed code coverage info to the terminal