solargraph_test_coverage 0.2.6 → 0.3.1.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.lock +5 -5
- data/README.md +7 -2
- data/lib/solargraph_test_coverage/config.rb +17 -7
- data/lib/solargraph_test_coverage/diagnostic_messages.rb +75 -0
- data/lib/solargraph_test_coverage/example_status_reporter.rb +23 -0
- data/lib/solargraph_test_coverage/file_helpers.rb +30 -0
- data/lib/solargraph_test_coverage/fork_process.rb +26 -12
- data/lib/solargraph_test_coverage/reporter_guards.rb +26 -0
- data/lib/solargraph_test_coverage/reporter_helpers.rb +23 -59
- data/lib/solargraph_test_coverage/test_coverage_reporter.rb +10 -50
- data/lib/solargraph_test_coverage/test_runner.rb +36 -6
- data/lib/solargraph_test_coverage/version.rb +1 -1
- data/lib/solargraph_test_coverage.rb +6 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dca8ac48cbb879d7410d76d58772620fa7468e60732adda23449bb356b5e492a
|
4
|
+
data.tar.gz: f469cbc81df6451f4b9ccc43d33caccdeb9f931ab66f562789cc659719c35907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaef9767e530370fd3ccc9a15583e29a8d7d20838efc51a3bc17c2e04d08522121a694e6afae9cbd79a198151d092778b68e0196dffa2e2871cf9fe8e77a8079
|
7
|
+
data.tar.gz: c7882927c706580ae3d21e58de450b535258d5455f5e97826a3f59876480624d68ddafabbc4f1da7b5606ae4a7b2d6b8b2f02dccbc0514329be3255be8c464fe
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
solargraph_test_coverage (0.
|
4
|
+
solargraph_test_coverage (0.3.0)
|
5
5
|
solargraph (~> 0.40, > 0.40)
|
6
6
|
|
7
7
|
GEM
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
kramdown (~> 2.0)
|
20
20
|
nokogiri (1.12.4-x86_64-darwin)
|
21
21
|
racc (~> 1.4)
|
22
|
-
parallel (1.
|
22
|
+
parallel (1.21.0)
|
23
23
|
parser (3.0.2.0)
|
24
24
|
ast (~> 2.4.1)
|
25
25
|
racc (1.5.2)
|
@@ -29,7 +29,7 @@ GEM
|
|
29
29
|
reverse_markdown (2.0.0)
|
30
30
|
nokogiri
|
31
31
|
rexml (3.2.5)
|
32
|
-
rubocop (1.
|
32
|
+
rubocop (1.21.0)
|
33
33
|
parallel (~> 1.10)
|
34
34
|
parser (>= 3.0.0.0)
|
35
35
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
rubocop-ast (1.11.0)
|
42
42
|
parser (>= 3.0.1.1)
|
43
43
|
ruby-progressbar (1.11.0)
|
44
|
-
solargraph (0.43.
|
44
|
+
solargraph (0.43.2)
|
45
45
|
backport (~> 1.2)
|
46
46
|
benchmark
|
47
47
|
bundler (>= 1.17.2)
|
@@ -58,7 +58,7 @@ GEM
|
|
58
58
|
yard (~> 0.9, >= 0.9.24)
|
59
59
|
thor (1.1.0)
|
60
60
|
tilt (2.0.10)
|
61
|
-
unicode-display_width (2.
|
61
|
+
unicode-display_width (2.1.0)
|
62
62
|
yard (0.9.26)
|
63
63
|
|
64
64
|
PLATFORMS
|
data/README.md
CHANGED
@@ -2,19 +2,22 @@
|
|
2
2
|
|
3
3
|
Solargraph Plugin that provides a diagnostic reporter for unit-test coverage.
|
4
4
|
|
5
|
-
Currently there are four different diagnostics:
|
5
|
+
Currently there are four different diagnostics when viewing an app/unit file:
|
6
6
|
- Line is not covered
|
7
7
|
- Branch is not covered (With a note if it's the 'THEN' or 'ELSE' branch)
|
8
8
|
- Spec is failing (Error message will be on line 1)
|
9
9
|
- Spec cannot be found (Error message will be on line 1)
|
10
10
|
|
11
|
+
There's one diagnostic if you're viewing a spec file:
|
12
|
+
- Example Status. Reports if an `it` block is currently failing (rspec only for now)
|
13
|
+
|
11
14
|
|
12
15
|
## Installation
|
13
16
|
|
14
17
|
Add this line to your application's Gemfile:
|
15
18
|
|
16
19
|
```ruby
|
17
|
-
gem 'solargraph_test_coverage'
|
20
|
+
gem 'solargraph_test_coverage', require: false
|
18
21
|
```
|
19
22
|
|
20
23
|
Then add this to your `.solargraph.yml` config:
|
@@ -24,6 +27,7 @@ plugins:
|
|
24
27
|
- solargraph_test_coverage
|
25
28
|
reporters:
|
26
29
|
- test_coverage
|
30
|
+
- example_status
|
27
31
|
```
|
28
32
|
|
29
33
|
Additionally, a `test_coverage` key can be added to `.solargraph.yml`. The default values are shown below:
|
@@ -37,6 +41,7 @@ test_coverage:
|
|
37
41
|
- branch
|
38
42
|
- test_failing
|
39
43
|
- test_missing
|
44
|
+
- example_failing
|
40
45
|
exclude_paths:
|
41
46
|
- 'app/controller'
|
42
47
|
- 'concerns'
|
@@ -6,12 +6,14 @@ module SolargraphTestCoverage
|
|
6
6
|
|
7
7
|
DEFAULTS = {
|
8
8
|
'preload_rails' => true, # can be true or false - performance optimization
|
9
|
+
'debug' => false, # can be true or false - shows debug messages when ChildFailedError is raised
|
9
10
|
'test_framework' => 'rspec', # can be 'rspec' or 'minitest'
|
10
11
|
'coverage' => [ # All diagnostics are enabled by default
|
11
12
|
'line', # Specifying an array with fewer diagnostics will overwrite this
|
12
13
|
'branch',
|
13
14
|
'test_failing',
|
14
|
-
'test_missing'
|
15
|
+
'test_missing',
|
16
|
+
'example_failing'
|
15
17
|
],
|
16
18
|
'exclude_paths' => [ # don't attempt to find/run a spec for files that match these paths
|
17
19
|
'app/controller',
|
@@ -19,6 +21,10 @@ module SolargraphTestCoverage
|
|
19
21
|
]
|
20
22
|
}.freeze
|
21
23
|
|
24
|
+
def debug?
|
25
|
+
plugin_config['debug']
|
26
|
+
end
|
27
|
+
|
22
28
|
def preload_rails?
|
23
29
|
plugin_config['preload_rails']
|
24
30
|
end
|
@@ -43,10 +49,18 @@ module SolargraphTestCoverage
|
|
43
49
|
plugin_config['coverage'].include? 'test_missing'
|
44
50
|
end
|
45
51
|
|
52
|
+
def example_failing_coverage?
|
53
|
+
plugin_config['coverage'].include? 'example_failing'
|
54
|
+
end
|
55
|
+
|
46
56
|
def test_framework
|
47
57
|
plugin_config['test_framework']
|
48
58
|
end
|
49
59
|
|
60
|
+
def full_test_dir
|
61
|
+
File.join(Dir.pwd, test_dir)
|
62
|
+
end
|
63
|
+
|
50
64
|
def test_dir
|
51
65
|
case test_framework
|
52
66
|
when 'rspec'
|
@@ -92,9 +106,9 @@ module SolargraphTestCoverage
|
|
92
106
|
def preload_rails!
|
93
107
|
return if defined?(Rails) || !File.file?('spec/rails_helper.rb')
|
94
108
|
|
95
|
-
$LOAD_PATH.unshift(
|
109
|
+
$LOAD_PATH.unshift(full_test_dir) unless $LOAD_PATH.include?(full_test_dir)
|
96
110
|
|
97
|
-
require File.join(
|
111
|
+
require File.join(full_test_dir, 'rails_helper')
|
98
112
|
Coverage.result(stop: true, clear: true) if Coverage.running?
|
99
113
|
|
100
114
|
true
|
@@ -116,9 +130,5 @@ module SolargraphTestCoverage
|
|
116
130
|
def workspace_config
|
117
131
|
Solargraph::Workspace::Config.new(Dir.pwd).raw_data.fetch('test_coverage', {})
|
118
132
|
end
|
119
|
-
|
120
|
-
def test_path
|
121
|
-
ReporterHelpers.test_path
|
122
|
-
end
|
123
133
|
end
|
124
134
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolargraphTestCoverage
|
4
|
+
module DiagnosticMessages
|
5
|
+
def line_coverage_warning(line)
|
6
|
+
return unless Config.line_coverage?
|
7
|
+
|
8
|
+
{
|
9
|
+
range: range(line, 0, line, @source.code.lines[line].length),
|
10
|
+
severity: Solargraph::Diagnostics::Severities::WARNING,
|
11
|
+
source: 'TestCoverage',
|
12
|
+
message: 'Line is missing test coverage'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def branch_coverage_warning(report)
|
17
|
+
return unless Config.branch_coverage?
|
18
|
+
|
19
|
+
{
|
20
|
+
range: range(report[:line] - 1, 0, report[:line] - 1, @source.code.lines[report[:line] - 1].length),
|
21
|
+
severity: Solargraph::Diagnostics::Severities::WARNING,
|
22
|
+
source: 'TestCoverage',
|
23
|
+
message: "'#{report[:type].upcase}' branch is missing test coverage"
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_failing_error
|
28
|
+
return unless Config.test_failing_coverage?
|
29
|
+
|
30
|
+
{
|
31
|
+
range: range(0, 0, 0, @source.code.lines[0].length),
|
32
|
+
severity: Solargraph::Diagnostics::Severities::ERROR,
|
33
|
+
source: 'TestCoverage',
|
34
|
+
message: 'Unit Test is currently failing.'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_missing_error
|
39
|
+
return unless Config.test_missing_coverage?
|
40
|
+
|
41
|
+
{
|
42
|
+
range: range(0, 0, 0, @source.code.lines[0].length),
|
43
|
+
severity: Solargraph::Diagnostics::Severities::HINT,
|
44
|
+
source: 'TestCoverage',
|
45
|
+
message: "No test file found at '#{FileHelpers.relative_test_file(@filename)}'"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def example_failing_error(example)
|
50
|
+
return unless Config.example_failing_coverage?
|
51
|
+
|
52
|
+
{
|
53
|
+
range: range(example[:line_number], 0, example[:line_number], @source.code.lines[example[:line_number]].length),
|
54
|
+
severity: Solargraph::Diagnostics::Severities::ERROR,
|
55
|
+
source: 'ExampleStatus',
|
56
|
+
message: example[:message]
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def debug_message(exception)
|
61
|
+
{
|
62
|
+
range: range(0, 0, 0, @source.code.lines[0].length),
|
63
|
+
severity: Solargraph::Diagnostics::Severities::ERROR,
|
64
|
+
source: 'SolargraphTestCoverage Plugin',
|
65
|
+
message: "DEBUG: (ChildFailedError) #{exception.message}"
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def range(start_line, start_column, end_line, end_column)
|
72
|
+
Solargraph::Range.from_to(start_line, start_column, end_line, end_column).to_hash
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# example_status reporter for Solargraph
|
4
|
+
module SolargraphTestCoverage
|
5
|
+
class ExampleStatusReporter < Solargraph::Diagnostics::Base
|
6
|
+
include ReporterHelpers
|
7
|
+
include ReporterGuards
|
8
|
+
include DiagnosticMessages
|
9
|
+
|
10
|
+
def diagnose(source, _api_map)
|
11
|
+
@source = source
|
12
|
+
@filename = source.location.filename
|
13
|
+
|
14
|
+
return [] if source.code.empty? || using_debugger? || !in_test_dir? || test_support_file?
|
15
|
+
|
16
|
+
@results = run_test(@filename)
|
17
|
+
|
18
|
+
example_failing_errors.compact
|
19
|
+
rescue ChildFailedError => e
|
20
|
+
Config.debug? ? [debug_message(e)] : []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolargraphTestCoverage
|
4
|
+
module FileHelpers
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def test_file(filename)
|
8
|
+
return filename if test_file?(filename)
|
9
|
+
|
10
|
+
path = relative_path(filename).split('/')
|
11
|
+
path[0] = Config.test_dir
|
12
|
+
path[-1] = path.last.sub(/\.rb$/, Config.test_file_suffix)
|
13
|
+
|
14
|
+
File.join(Dir.pwd, path.join('/'))
|
15
|
+
end
|
16
|
+
|
17
|
+
def relative_path(path)
|
18
|
+
path.sub("#{Dir.pwd}/", '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def relative_test_file(filename)
|
22
|
+
relative_path test_file(filename)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_file?(filename)
|
26
|
+
filename.start_with?(Config.full_test_dir) &&
|
27
|
+
filename.end_with?(Config.test_file_suffix)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -5,25 +5,39 @@ module SolargraphTestCoverage
|
|
5
5
|
# When called with a block, runs the content of said block in a new (forked) process
|
6
6
|
# the return value of the process/block can be captured and used in parent process
|
7
7
|
class ForkProcess
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def self.call(&block)
|
9
|
+
new.run(&block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@read, @write = IO.pipe
|
14
|
+
end
|
13
15
|
|
16
|
+
def run(&block)
|
14
17
|
pid = fork do
|
15
|
-
read.close
|
16
|
-
|
17
|
-
Marshal.dump(result, write)
|
18
|
+
@read.close
|
19
|
+
Marshal.dump(run_block_with_timeout(&block), @write)
|
18
20
|
exit!(0) # skips exit handlers.
|
19
21
|
end
|
20
22
|
|
21
|
-
write.close
|
22
|
-
result = read.read
|
23
|
+
@write.close
|
24
|
+
result = @read.read
|
25
|
+
|
23
26
|
Process.wait(pid)
|
24
|
-
raise ChildFailedError if result.nil?
|
27
|
+
raise ChildFailedError, "Couldn't read pipe" if result.nil?
|
28
|
+
|
29
|
+
Marshal.load(result).tap do |r|
|
30
|
+
raise ChildFailedError, "Marshal.load(result) returned nil" if r.nil?
|
31
|
+
raise ChildFailedError, r.message if r.is_a? Exception
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
25
36
|
|
26
|
-
|
37
|
+
def run_block_with_timeout(&block)
|
38
|
+
Timeout.timeout(30000, &block)
|
39
|
+
rescue StandardError => e
|
40
|
+
e
|
27
41
|
end
|
28
42
|
end
|
29
43
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolargraphTestCoverage
|
4
|
+
# Some guard functions for the diagnostics
|
5
|
+
module ReporterGuards
|
6
|
+
def test_file_exists?
|
7
|
+
File.file? FileHelpers.test_file(@filename)
|
8
|
+
end
|
9
|
+
|
10
|
+
def in_test_dir?
|
11
|
+
@filename.start_with? Config.full_test_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_support_file?
|
15
|
+
in_test_dir? && !@filename.end_with?(Config.test_file_suffix)
|
16
|
+
end
|
17
|
+
|
18
|
+
def exclude_file?
|
19
|
+
Config.exclude_paths.any? { |path| FileHelpers.relative_path(@filename).include? path }
|
20
|
+
end
|
21
|
+
|
22
|
+
def using_debugger?
|
23
|
+
@source.code.match?(/(binding\.pry|byebug|debugger)/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -3,54 +3,34 @@
|
|
3
3
|
module SolargraphTestCoverage
|
4
4
|
# Some helper functions for the diagnostics
|
5
5
|
module ReporterHelpers
|
6
|
-
def exclude_file?(source_filename)
|
7
|
-
return true if source_filename.start_with? test_path
|
8
|
-
|
9
|
-
Config.exclude_paths.any? { |path| source_filename.sub(Dir.pwd, '').include? path }
|
10
|
-
end
|
11
|
-
|
12
|
-
def using_debugger?(source)
|
13
|
-
source.code.include?('binding.pry') ||
|
14
|
-
source.code.include?('byebug') ||
|
15
|
-
source.code.include?('debugger')
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_file(source)
|
19
|
-
relative_filepath = source.location.filename.sub(Dir.pwd, '').split('/').reject(&:empty?)
|
20
|
-
relative_filepath[0] = Config.test_dir
|
21
|
-
|
22
|
-
File.join(Dir.pwd, relative_filepath.join('/')).sub('.rb', Config.test_file_suffix)
|
23
|
-
end
|
24
|
-
|
25
6
|
# @return [Hash]
|
26
|
-
def run_test(
|
27
|
-
ForkProcess.
|
7
|
+
def run_test(test_file)
|
8
|
+
ForkProcess.call do
|
28
9
|
Coverage.start(lines: true, branches: true)
|
29
|
-
runner = TestRunner.with(test_file
|
30
|
-
|
10
|
+
runner = TestRunner.with(test_file).run!
|
11
|
+
extra = { test_status: runner.passed?, failed_examples: runner.failed_examples }
|
12
|
+
|
13
|
+
Coverage.result.fetch(@filename, {}).merge(extra)
|
31
14
|
end
|
32
15
|
end
|
33
16
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
test_passing_error(source, results)
|
39
|
-
]
|
40
|
-
|
41
|
-
messages.flatten.compact
|
17
|
+
def branch_warnings
|
18
|
+
Branch.build_from(@results)
|
19
|
+
.reject(&:covered?)
|
20
|
+
.map { |branch| branch_coverage_warning(branch.report) }
|
42
21
|
end
|
43
22
|
|
44
|
-
def
|
45
|
-
|
23
|
+
def test_passing_error
|
24
|
+
@results[:test_status] ? [] : [test_failing_error]
|
46
25
|
end
|
47
26
|
|
48
|
-
def
|
49
|
-
|
27
|
+
def example_failing_errors
|
28
|
+
@results.fetch(:failed_examples, [])
|
29
|
+
.map { |example| example_failing_error(example) }
|
50
30
|
end
|
51
31
|
|
52
|
-
def
|
53
|
-
|
32
|
+
def line_warnings
|
33
|
+
uncovered_lines.map { |line| line_coverage_warning(line) }
|
54
34
|
end
|
55
35
|
|
56
36
|
# Adapted from SingleCov
|
@@ -59,29 +39,13 @@ module SolargraphTestCoverage
|
|
59
39
|
#
|
60
40
|
# [nil, 1, 0, 1, 0] -> [3, 5]
|
61
41
|
# Returns array of line numbers with 0 coverage
|
62
|
-
def uncovered_lines
|
63
|
-
return [] unless results[:lines]
|
64
|
-
|
65
|
-
results[:lines].each_with_index
|
66
|
-
.select { |c, _| c&.zero? }
|
67
|
-
.map { |_, i| i }
|
68
|
-
.compact
|
69
|
-
end
|
70
|
-
|
71
|
-
def uncovered_branches(results)
|
72
|
-
Branch.build_from(results).reject(&:covered?)
|
73
|
-
end
|
74
|
-
|
75
|
-
def range(start_line, start_column, end_line, end_column)
|
76
|
-
Solargraph::Range.from_to(start_line, start_column, end_line, end_column).to_hash
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.test_path
|
80
|
-
File.join(Dir.pwd, Config.test_dir)
|
81
|
-
end
|
42
|
+
def uncovered_lines
|
43
|
+
return [] unless @results[:lines]
|
82
44
|
|
83
|
-
|
84
|
-
|
45
|
+
@results[:lines].each_with_index
|
46
|
+
.select { |c, _| c&.zero? }
|
47
|
+
.map { |_, i| i }
|
48
|
+
.compact
|
85
49
|
end
|
86
50
|
end
|
87
51
|
end
|
@@ -4,61 +4,21 @@
|
|
4
4
|
module SolargraphTestCoverage
|
5
5
|
class TestCoverageReporter < Solargraph::Diagnostics::Base
|
6
6
|
include ReporterHelpers
|
7
|
+
include ReporterGuards
|
8
|
+
include DiagnosticMessages
|
7
9
|
|
8
10
|
def diagnose(source, _api_map)
|
9
|
-
|
10
|
-
|
11
|
+
@source = source
|
12
|
+
@filename = source.location.filename
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
rescue ChildFailedError
|
15
|
-
[]
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def line_coverage_warning(source, line)
|
21
|
-
return unless Config.line_coverage?
|
22
|
-
|
23
|
-
{
|
24
|
-
range: range(line, 0, line, source.code.lines[line].length),
|
25
|
-
severity: Solargraph::Diagnostics::Severities::WARNING,
|
26
|
-
source: 'TestCoverage',
|
27
|
-
message: 'Line is missing test coverage'
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
def branch_coverage_warning(source, report)
|
32
|
-
return unless Config.branch_coverage?
|
33
|
-
|
34
|
-
{
|
35
|
-
range: range(report[:line] - 1, 0, report[:line] - 1, source.code.lines[report[:line] - 1].length),
|
36
|
-
severity: Solargraph::Diagnostics::Severities::WARNING,
|
37
|
-
source: 'TestCoverage',
|
38
|
-
message: "'#{report[:type].upcase}' branch is missing test coverage"
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_failing_error(source)
|
43
|
-
return unless Config.test_failing_coverage?
|
44
|
-
|
45
|
-
{
|
46
|
-
range: range(0, 0, 0, source.code.lines[0].length),
|
47
|
-
severity: Solargraph::Diagnostics::Severities::ERROR,
|
48
|
-
source: 'TestCoverage',
|
49
|
-
message: 'Unit Test is currently failing.'
|
50
|
-
}
|
51
|
-
end
|
14
|
+
return [] if source.code.empty? || using_debugger? || exclude_file? || in_test_dir?
|
15
|
+
return [test_missing_error] unless test_file_exists?
|
52
16
|
|
53
|
-
|
54
|
-
return unless Config.test_missing_coverage?
|
17
|
+
@results = run_test(FileHelpers.test_file(@filename))
|
55
18
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
source: 'TestCoverage',
|
60
|
-
message: "No test file found at '#{test_file(source).sub("#{Dir.pwd}/", '')}'"
|
61
|
-
}
|
19
|
+
[line_warnings, branch_warnings, test_passing_error].flatten.compact
|
20
|
+
rescue ChildFailedError => e
|
21
|
+
Config.debug? ? [debug_message(e)] : []
|
62
22
|
end
|
63
23
|
end
|
64
24
|
end
|
@@ -15,14 +15,15 @@ module SolargraphTestCoverage
|
|
15
15
|
def initialize(test_file)
|
16
16
|
@test_file = test_file
|
17
17
|
@result = nil
|
18
|
+
@output = StringIO.new
|
18
19
|
end
|
19
20
|
|
20
21
|
def run!
|
21
|
-
@result = test_framework_runner.run(test_options)
|
22
|
+
@result = test_framework_runner.run(test_options, $stderr, @output)
|
22
23
|
self
|
23
24
|
end
|
24
25
|
|
25
|
-
def
|
26
|
+
def failed_examples
|
26
27
|
raise NotImplementedError
|
27
28
|
end
|
28
29
|
|
@@ -30,21 +31,43 @@ module SolargraphTestCoverage
|
|
30
31
|
raise NotImplementedError
|
31
32
|
end
|
32
33
|
|
34
|
+
private
|
35
|
+
|
36
|
+
def test_options
|
37
|
+
raise NotImplementedError
|
38
|
+
end
|
39
|
+
|
33
40
|
def test_framework_runner
|
34
41
|
raise NotImplementedError
|
35
42
|
end
|
43
|
+
|
44
|
+
def output
|
45
|
+
return if @output.string.empty?
|
46
|
+
|
47
|
+
JSON.parse @output.string
|
48
|
+
end
|
36
49
|
end
|
37
50
|
|
38
51
|
# Test Runner Subclass for RSpec
|
39
52
|
class RSpecRunner < TestRunner
|
40
|
-
def
|
41
|
-
|
53
|
+
def failed_examples
|
54
|
+
return unless output
|
55
|
+
|
56
|
+
output['examples']
|
57
|
+
.select { |example| example['status'] == 'failed' }
|
58
|
+
.map { |example| { line_number: example['line_number'] - 1, message: example.dig('exception', 'message') } }
|
42
59
|
end
|
43
60
|
|
44
61
|
def passed?
|
45
62
|
@result&.zero?
|
46
63
|
end
|
47
64
|
|
65
|
+
private
|
66
|
+
|
67
|
+
def test_options
|
68
|
+
[@test_file, '--format', 'json']
|
69
|
+
end
|
70
|
+
|
48
71
|
def test_framework_runner
|
49
72
|
RSpec::Core::Runner
|
50
73
|
end
|
@@ -52,14 +75,21 @@ module SolargraphTestCoverage
|
|
52
75
|
|
53
76
|
# Test Runner Subclass for Minitest
|
54
77
|
class MinitestRunner < TestRunner
|
55
|
-
|
56
|
-
|
78
|
+
# TODO
|
79
|
+
def failed_examples
|
80
|
+
[]
|
57
81
|
end
|
58
82
|
|
59
83
|
def passed?
|
60
84
|
@result
|
61
85
|
end
|
62
86
|
|
87
|
+
private
|
88
|
+
|
89
|
+
def test_options
|
90
|
+
[@test_file]
|
91
|
+
end
|
92
|
+
|
63
93
|
def test_framework_runner
|
64
94
|
Minitest
|
65
95
|
end
|
@@ -4,12 +4,17 @@ require 'solargraph_test_coverage/version'
|
|
4
4
|
require 'solargraph_test_coverage/branch'
|
5
5
|
require 'solargraph_test_coverage/fork_process'
|
6
6
|
require 'solargraph_test_coverage/reporter_helpers'
|
7
|
+
require 'solargraph_test_coverage/reporter_guards'
|
8
|
+
require 'solargraph_test_coverage/file_helpers'
|
7
9
|
require 'solargraph_test_coverage/config'
|
8
10
|
require 'solargraph_test_coverage/test_runner'
|
11
|
+
require 'solargraph_test_coverage/diagnostic_messages'
|
9
12
|
require 'solargraph_test_coverage/test_coverage_reporter'
|
13
|
+
require 'solargraph_test_coverage/example_status_reporter'
|
10
14
|
|
11
15
|
require 'solargraph'
|
12
16
|
require 'coverage'
|
17
|
+
require 'timeout'
|
13
18
|
|
14
19
|
module SolargraphTestCoverage
|
15
20
|
class ChildFailedError < StandardError; end
|
@@ -20,4 +25,5 @@ module SolargraphTestCoverage
|
|
20
25
|
Config.preload_rails! if Config.preload_rails?
|
21
26
|
|
22
27
|
Solargraph::Diagnostics.register 'test_coverage', TestCoverageReporter
|
28
|
+
Solargraph::Diagnostics.register 'example_status', ExampleStatusReporter
|
23
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solargraph_test_coverage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Kolkey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solargraph
|
@@ -47,7 +47,11 @@ files:
|
|
47
47
|
- lib/solargraph_test_coverage.rb
|
48
48
|
- lib/solargraph_test_coverage/branch.rb
|
49
49
|
- lib/solargraph_test_coverage/config.rb
|
50
|
+
- lib/solargraph_test_coverage/diagnostic_messages.rb
|
51
|
+
- lib/solargraph_test_coverage/example_status_reporter.rb
|
52
|
+
- lib/solargraph_test_coverage/file_helpers.rb
|
50
53
|
- lib/solargraph_test_coverage/fork_process.rb
|
54
|
+
- lib/solargraph_test_coverage/reporter_guards.rb
|
51
55
|
- lib/solargraph_test_coverage/reporter_helpers.rb
|
52
56
|
- lib/solargraph_test_coverage/test_coverage_reporter.rb
|
53
57
|
- lib/solargraph_test_coverage/test_runner.rb
|