solargraph_test_coverage 0.2.5 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +10 -7
- 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 -53
- 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: 74b455e9459cc2032d23bcb1acf41d4d31f9ee3b8148c67895598ace977a98e9
|
4
|
+
data.tar.gz: a0c2942f3973466af1d7782363415e5accd17fb1f65c9fcd6d930dedd8b363c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8abcd10d5c816586cab20e0b20ca3925df48723d64c9442fe63d8cbcbfacdc51367da617bf77adb158c22653ca08bf8cc92005cd83ecf170216ccb19eefc3ad
|
7
|
+
data.tar.gz: 7d4fbef5094bb5ebc477daebfe20b70ca0c9e6fd6d3a04053138bafee245094bfe51b38e05251837a665b275b2a16cfd8f6f33ce4dc3839bc9726000eb499b94
|
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
@@ -14,7 +14,7 @@ Currently there are four different diagnostics:
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'solargraph_test_coverage'
|
17
|
+
gem 'solargraph_test_coverage', require: false
|
18
18
|
```
|
19
19
|
|
20
20
|
Then add this to your `.solargraph.yml` config:
|
@@ -33,13 +33,13 @@ test_coverage:
|
|
33
33
|
preload_rails: true
|
34
34
|
test_framework: rspec # or minitest
|
35
35
|
coverage:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
- line
|
37
|
+
- branch
|
38
|
+
- test_failing
|
39
|
+
- test_missing
|
40
40
|
exclude_paths:
|
41
|
-
|
42
|
-
|
41
|
+
- 'app/controller'
|
42
|
+
- 'concerns'
|
43
43
|
```
|
44
44
|
|
45
45
|
|
@@ -51,6 +51,9 @@ And then execute:
|
|
51
51
|
Or install it yourself as:
|
52
52
|
|
53
53
|
$ gem install solargraph_test_coverage
|
54
|
+
|
55
|
+
A note on testing framework:
|
56
|
+
Since both Minitest and RSpec are supported, neither are direct dependencies of this gem. Therefore, you have to have them installed separately either via your bundle or via `gem install`.
|
54
57
|
|
55
58
|
## Usage
|
56
59
|
|
@@ -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
|
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,48 +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 test_file(source)
|
13
|
-
relative_filepath = source.location.filename.sub(Dir.pwd, '').split('/').reject(&:empty?)
|
14
|
-
relative_filepath[0] = Config.test_dir
|
15
|
-
|
16
|
-
File.join(Dir.pwd, relative_filepath.join('/')).sub('.rb', Config.test_file_suffix)
|
17
|
-
end
|
18
|
-
|
19
6
|
# @return [Hash]
|
20
|
-
def run_test(
|
21
|
-
ForkProcess.
|
7
|
+
def run_test(test_file)
|
8
|
+
ForkProcess.call do
|
22
9
|
Coverage.start(lines: true, branches: true)
|
23
|
-
runner = TestRunner.with(test_file
|
24
|
-
|
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)
|
25
14
|
end
|
26
15
|
end
|
27
16
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
test_passing_error(source, results)
|
33
|
-
]
|
34
|
-
|
35
|
-
messages.flatten.compact
|
17
|
+
def branch_warnings
|
18
|
+
Branch.build_from(@results)
|
19
|
+
.reject(&:covered?)
|
20
|
+
.map { |branch| branch_coverage_warning(branch.report) }
|
36
21
|
end
|
37
22
|
|
38
|
-
def
|
39
|
-
|
23
|
+
def test_passing_error
|
24
|
+
@results[:test_status] ? [] : [test_failing_error]
|
40
25
|
end
|
41
26
|
|
42
|
-
def
|
43
|
-
|
27
|
+
def example_failing_errors
|
28
|
+
@results.fetch(:failed_examples, [])
|
29
|
+
.map { |example| example_failing_error(example) }
|
44
30
|
end
|
45
31
|
|
46
|
-
def
|
47
|
-
|
32
|
+
def line_warnings
|
33
|
+
uncovered_lines.map { |line| line_coverage_warning(line) }
|
48
34
|
end
|
49
35
|
|
50
36
|
# Adapted from SingleCov
|
@@ -53,29 +39,13 @@ module SolargraphTestCoverage
|
|
53
39
|
#
|
54
40
|
# [nil, 1, 0, 1, 0] -> [3, 5]
|
55
41
|
# Returns array of line numbers with 0 coverage
|
56
|
-
def uncovered_lines
|
57
|
-
return [] unless results[:lines]
|
58
|
-
|
59
|
-
results[:lines].each_with_index
|
60
|
-
.select { |c, _| c&.zero? }
|
61
|
-
.map { |_, i| i }
|
62
|
-
.compact
|
63
|
-
end
|
64
|
-
|
65
|
-
def uncovered_branches(results)
|
66
|
-
Branch.build_from(results).reject(&:covered?)
|
67
|
-
end
|
68
|
-
|
69
|
-
def range(start_line, start_column, end_line, end_column)
|
70
|
-
Solargraph::Range.from_to(start_line, start_column, end_line, end_column).to_hash
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.test_path
|
74
|
-
File.join(Dir.pwd, Config.test_dir)
|
75
|
-
end
|
42
|
+
def uncovered_lines
|
43
|
+
return [] unless @results[:lines]
|
76
44
|
|
77
|
-
|
78
|
-
|
45
|
+
@results[:lines].each_with_index
|
46
|
+
.select { |c, _| c&.zero? }
|
47
|
+
.map { |_, i| i }
|
48
|
+
.compact
|
79
49
|
end
|
80
50
|
end
|
81
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
|
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
|