simple_cov-formatter-terminal 1.3.0 → 1.5.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: ff0a8830c6b2de767299678ae7fbff95b236ae0d79de1f5f6abede949bb6f394
4
- data.tar.gz: 48d18ad9742d24dfa1b6a70fc77bd56ebd6574e8c429ab680e4ac6e823946297
3
+ metadata.gz: deae1a8971e620250fa1a1748eaa59bd8b1036396514430f8da0137068d41445
4
+ data.tar.gz: 062c244a99ca1f92f9cff01d1566a24ac4c47b94d891c668d05a8da6f5299302
5
5
  SHA512:
6
- metadata.gz: 5477653a52035b2835c64273a3f0f415ba67d8c66aee98921f6d243b3d698282c4126375cddfc11d37ba58f608bb5600d583b51177e7dab9a4446e38868977e4
7
- data.tar.gz: 446961414ac5865814ed77700635c6243df80f0b064e9b38041bf4639e3cc776c5f2fac4e8d2c82afc5bd40ef8946e01c0afb8e18be45a24db1535027663117f
6
+ metadata.gz: 898eee91d6d0e588826fe800006eb51980a9bbe7af841a4eef025a77a103400a5afd78f16ff750b560651c70d21b57b0530e7ab0387dfed196023e0864a84821
7
+ data.tar.gz: df37c9668c61f2b605e1e4f07267223b138a5bc6ad58071d56f1d99ed421572a894018954889db9f8bfcd4e276fb86e07b63e3bf8fb027f96d59a0c080e5ea42
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.3
1
+ 3.3.4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v1.5.0 (2024-07-28)
2
+ - Print line numbers as terminal hyperlinks if a `SimpleCov::Formatter::Terminal.config.terminal_hyperlink_target_pattern` is provided
3
+
4
+ ## v1.4.0 (2024-07-21)
5
+ - Handle map-spec-file-to-app failure more elegantly (#229)
6
+
1
7
  ## v1.3.0 (2024-06-28)
2
8
  - Enforce only major and minor parts of required Ruby version (loosening the required Ruby version from 3.3.3 to 3.3.0)
3
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_cov-formatter-terminal (1.3.0)
4
+ simple_cov-formatter-terminal (1.5.0)
5
5
  activesupport (>= 7.0.4, < 8)
6
6
  memo_wise (>= 1.7.0, < 2)
7
7
  rouge (>= 4.0.0, < 5)
@@ -31,7 +31,7 @@ GEM
31
31
  concurrent-ruby (1.3.3)
32
32
  connection_pool (2.4.1)
33
33
  diff-lcs (1.5.1)
34
- docile (1.4.0)
34
+ docile (1.4.1)
35
35
  drb (2.2.1)
36
36
  i18n (1.14.5)
37
37
  concurrent-ruby (~> 1.0)
@@ -39,10 +39,10 @@ GEM
39
39
  language_server-protocol (3.17.0.3)
40
40
  memo_wise (1.9.0)
41
41
  method_source (1.1.0)
42
- minitest (5.24.0)
42
+ minitest (5.24.1)
43
43
  mutex_m (0.2.0)
44
44
  parallel (1.25.1)
45
- parser (3.3.3.0)
45
+ parser (3.3.4.0)
46
46
  ast (~> 2.4.1)
47
47
  racc
48
48
  prism (0.30.0)
@@ -56,7 +56,7 @@ GEM
56
56
  rainbow (3.1.1)
57
57
  rake (13.2.1)
58
58
  regexp_parser (2.9.2)
59
- rexml (3.3.1)
59
+ rexml (3.3.2)
60
60
  strscan
61
61
  rouge (4.3.0)
62
62
  rspec (3.13.0)
@@ -72,13 +72,13 @@ GEM
72
72
  diff-lcs (>= 1.2.0, < 2.0)
73
73
  rspec-support (~> 3.13.0)
74
74
  rspec-support (3.13.1)
75
- rubocop (1.64.1)
75
+ rubocop (1.65.0)
76
76
  json (~> 2.3)
77
77
  language_server-protocol (>= 3.17.0)
78
78
  parallel (~> 1.10)
79
79
  parser (>= 3.3.0.2)
80
80
  rainbow (>= 2.2.2, < 4.0)
81
- regexp_parser (>= 1.8, < 3.0)
81
+ regexp_parser (>= 2.4, < 3.0)
82
82
  rexml (>= 3.2.5, < 4.0)
83
83
  rubocop-ast (>= 1.31.1, < 2.0)
84
84
  ruby-progressbar (~> 1.7)
@@ -88,17 +88,17 @@ GEM
88
88
  rubocop-performance (1.21.1)
89
89
  rubocop (>= 1.48.1, < 2.0)
90
90
  rubocop-ast (>= 1.31.1, < 2.0)
91
- rubocop-rspec (3.0.1)
91
+ rubocop-rspec (3.0.3)
92
92
  rubocop (~> 1.61)
93
93
  ruby-progressbar (1.13.0)
94
- runger_config (5.1.0)
94
+ runger_config (5.2.0)
95
95
  activesupport (>= 7.1.2)
96
- runger_release_assistant (0.8.0)
96
+ runger_release_assistant (0.11.0)
97
97
  activesupport (>= 6, < 8)
98
98
  memo_wise (>= 1.7, < 2)
99
99
  rainbow (>= 3.0, < 4)
100
100
  slop (~> 4.8)
101
- runger_style (2.8.0)
101
+ runger_style (2.13.0)
102
102
  prism (>= 0.24.0)
103
103
  rubocop (>= 1.38.0, < 2)
104
104
  simplecov (0.22.0)
@@ -136,7 +136,7 @@ DEPENDENCIES
136
136
  simplecov-cobertura
137
137
 
138
138
  RUBY VERSION
139
- ruby 3.3.3p89
139
+ ruby 3.3.4p94
140
140
 
141
141
  BUNDLED WITH
142
142
  2.5.11
data/README.md CHANGED
@@ -115,6 +115,21 @@ branch is not covered on line 18).
115
115
 
116
116
  [simple-cov-branch-coverage]: https://github.com/simplecov-ruby/simplecov#branch-coverage-ruby--25
117
117
 
118
+ ## Terminal hyperlinks
119
+
120
+ If you provide a `terminal_hyperlink_target_pattern`, then SimpleCov::Formatter::Terminal will attempt to print the line numbers in its display as hyperlinks to the relevant line of code.
121
+
122
+ The pattern can include these interpolation markers:
123
+
124
+ - `%f` - This will be replaced with the absolute path of the application file.
125
+ - `%l` - This will be replaced with the line number.
126
+
127
+ For example, this pattern will work to make the line numbers clickable links that open the appropriate file at the appropriate line in VS Code:
128
+
129
+ ```rb
130
+ SimpleCov::Formatter::Terminal.config.terminal_hyperlink_target_pattern = 'vscode://file/%f:%l'
131
+ ```
132
+
118
133
  ## Development
119
134
 
120
135
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run
@@ -16,12 +16,8 @@ class SimpleCov::Formatter::Terminal::Config < Runger::Config
16
16
  lines_to_print: LinesToPrint::UNCOVERED,
17
17
  spec_to_app_file_map:
18
18
  SimpleCov::Formatter::Terminal::SpecToAppMapping.default_spec_to_app_map,
19
+ terminal_hyperlink_target_pattern: nil,
19
20
  unmappable_spec_regexes:
20
21
  SimpleCov::Formatter::Terminal::SpecToAppMapping::DEFAULT_UNMAPPABLE_SPEC_REGEXES,
21
22
  )
22
-
23
- memo_wise \
24
- def write_target_info_file?
25
- ENV.fetch('SIMPLECOV_WRITE_TARGET_TO_FILE', nil) == '1'
26
- end
27
23
  end
@@ -25,14 +25,18 @@ class SimpleCov::Formatter::Terminal::FileDeterminer
25
25
  return env_variable_file
26
26
  end
27
27
 
28
- return nil if unmappable_spec_regexes.any? { executed_spec_file.match?(_1) }
28
+ return nil if unmappable_spec_file?
29
29
 
30
30
  spec_to_app_file_map.lazy.filter_map do |spec_file_regex, app_file_substitution|
31
31
  if executed_spec_file.match?(spec_file_regex)
32
32
  executed_spec_file.sub(spec_file_regex, app_file_substitution)
33
33
  end
34
- end.first&.sub(/_spec\.rb\z/, '.rb') ||
35
- raise("Could not map executed spec file #{executed_spec_file} to application file!")
34
+ end.first&.sub(/_spec\.rb\z/, '.rb')
35
+ end
36
+
37
+ memo_wise \
38
+ def unmappable_spec_file?
39
+ unmappable_spec_regexes.any? { executed_spec_file.match?(_1) }
36
40
  end
37
41
 
38
42
  memo_wise \
@@ -7,6 +7,8 @@ class SimpleCov::Formatter::Terminal::LinePrinter
7
7
  include SimpleCov::Formatter::Terminal::BranchCoverage
8
8
  include SimpleCov::Formatter::Terminal::ColorPrinting
9
9
 
10
+ LINE_NUMBER_WIDTH = 3
11
+
10
12
  def initialize(targeted_application_file = nil)
11
13
  @targeted_application_file = targeted_application_file
12
14
  end
@@ -37,20 +39,16 @@ class SimpleCov::Formatter::Terminal::LinePrinter
37
39
  else color(' ', :white_on_green)
38
40
  end
39
41
 
40
- line_number_width =
41
- if SimpleCov::Formatter::Terminal.config.write_target_info_file?
42
- 6
43
- else
44
- 3
45
- end
42
+ pattern = SimpleCov::Formatter::Terminal.config.terminal_hyperlink_target_pattern
43
+
44
+ link_text = line_number.to_s.rjust(LINE_NUMBER_WIDTH, ' ')
46
45
 
47
46
  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, ' ')
47
+ if pattern
48
+ link_target = pattern.sub('%f', absolute_target_path).sub('%l', line_number.to_s)
49
+ "\e]8;;#{link_target}\e\\#{link_text}\e]8;;\e\\"
52
50
  else
53
- line_number.to_s.rjust(line_number_width, ' ')
51
+ link_text
54
52
  end
55
53
 
56
54
  output =
@@ -76,4 +74,11 @@ class SimpleCov::Formatter::Terminal::LinePrinter
76
74
  highlighted_source = formatter.format(lexer.lex(source))
77
75
  highlighted_source.split("\n")
78
76
  end
77
+
78
+ private
79
+
80
+ memo_wise \
81
+ def absolute_target_path
82
+ File.join(ENV.fetch('PWD'), @targeted_application_file)
83
+ end
79
84
  end
@@ -3,7 +3,6 @@
3
3
  require_relative 'branch_coverage'
4
4
  require_relative 'color_printing'
5
5
  require_relative 'line_printer'
6
- require_relative 'target_file_writer'
7
6
 
8
7
  class SimpleCov::Formatter::Terminal::ResultPrinter
9
8
  extend Forwardable
@@ -50,10 +49,6 @@ class SimpleCov::Formatter::Terminal::ResultPrinter
50
49
  def print_coverage_details(sourcefile)
51
50
  @sourcefile = sourcefile
52
51
 
53
- if SimpleCov::Formatter::Terminal.config.write_target_info_file?
54
- target_file_writer.write_target_info_file
55
- end
56
-
57
52
  puts("---- Coverage for #{targeted_application_file} ".ljust(80, '-').rstrip)
58
53
 
59
54
  skipped_lines = []
@@ -108,7 +103,7 @@ class SimpleCov::Formatter::Terminal::ResultPrinter
108
103
  puts('Not showing test coverage details because no specs were executed successfully.')
109
104
  end
110
105
 
111
- def print_info_for_undetermined_application_target
106
+ def print_info_for_undeterminable_application_target
112
107
  puts(<<~LOG.squish)
113
108
  Not showing test coverage details because "#{executed_spec_file}" cannot
114
109
  be mapped to a single application file.
@@ -118,6 +113,17 @@ class SimpleCov::Formatter::Terminal::ResultPrinter
118
113
  LOG
119
114
  end
120
115
 
116
+ def print_info_for_undetermined_application_target
117
+ puts(<<~LOG.squish)
118
+ Not showing test coverage details because we could not map "#{executed_spec_file}"
119
+ to an application file.
120
+ LOG
121
+ puts(<<~LOG.squish)
122
+ Tip: You can provide a mapping via
123
+ `SimpleCov::Formatter::Terminal.config.spec_to_app_file_map`.
124
+ LOG
125
+ end
126
+
121
127
  def print_info_for_nonexistent_application_target
122
128
  puts(<<~LOG.squish)
123
129
  Cannot show code coverage. Looked for application file "#{targeted_application_file}",
@@ -131,11 +137,6 @@ class SimpleCov::Formatter::Terminal::ResultPrinter
131
137
  SimpleCov::Formatter::Terminal::RSpecIntegration.failure_occurred?
132
138
  end
133
139
 
134
- memo_wise \
135
- def target_file_writer
136
- SimpleCov::Formatter::Terminal::TargetFileWriter.new(targeted_application_file)
137
- end
138
-
139
140
  def colorized_coverage(covered_percent)
140
141
  case
141
142
  when covered_percent >= 100 then color("#{covered_percent.round(2)}%", :green)
@@ -5,6 +5,6 @@ module SimpleCov::Formatter; end
5
5
 
6
6
  # rubocop:disable Style/StaticClass
7
7
  class SimpleCov::Formatter::Terminal
8
- VERSION = '1.3.0'
8
+ VERSION = '1.5.0'
9
9
  end
10
10
  # rubocop:enable Style/StaticClass
@@ -25,12 +25,14 @@ class SimpleCov::Formatter::Terminal
25
25
  :executed_spec_file,
26
26
  :executed_spec_files,
27
27
  :targeted_application_file,
28
+ :unmappable_spec_file?,
28
29
  )
29
30
  def_delegators(
30
31
  :result_printer,
31
32
  :print_coverage_info,
32
33
  :print_info_for_no_executed_specs,
33
34
  :print_info_for_nonexistent_application_target,
35
+ :print_info_for_undeterminable_application_target,
34
36
  :print_info_for_undetermined_application_target,
35
37
  )
36
38
 
@@ -46,6 +48,8 @@ class SimpleCov::Formatter::Terminal
46
48
  def format(result)
47
49
  if executed_spec_files.nil?
48
50
  print_info_for_no_executed_specs
51
+ elsif unmappable_spec_file?
52
+ print_info_for_undeterminable_application_target
49
53
  elsif targeted_application_file.nil?
50
54
  print_info_for_undetermined_application_target
51
55
  elsif File.exist?(targeted_application_file)
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: 1.3.0
4
+ version: 1.5.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: 2024-06-28 00:00:00.000000000 Z
11
+ date: 2024-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -151,7 +151,6 @@ files:
151
151
  - lib/simple_cov/formatter/terminal/rails_awareness.rb
152
152
  - lib/simple_cov/formatter/terminal/result_printer.rb
153
153
  - lib/simple_cov/formatter/terminal/spec_to_app_mapping.rb
154
- - lib/simple_cov/formatter/terminal/target_file_writer.rb
155
154
  - lib/simple_cov/formatter/terminal/version.rb
156
155
  - simple_cov-formatter-terminal.gemspec
157
156
  homepage: https://github.com/davidrunger/simple_cov-formatter-terminal
@@ -177,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
176
  - !ruby/object:Gem::Version
178
177
  version: '0'
179
178
  requirements: []
180
- rubygems_version: 3.5.14
179
+ rubygems_version: 3.5.16
181
180
  signing_key:
182
181
  specification_version: 4
183
182
  summary: Print detailed code coverage info to the terminal
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'memo_wise'
4
-
5
- class SimpleCov::Formatter::Terminal::TargetFileWriter
6
- def initialize(targeted_application_file)
7
- @targeted_application_file = targeted_application_file
8
- end
9
-
10
- def write_target_info_file
11
- directory = 'tmp/simple_cov/formatter/terminal'
12
- FileUtils.mkdir_p(directory)
13
- File.write("#{directory}/target.txt", "#{@targeted_application_file}\n")
14
- end
15
- end