solargraph_test_coverage 0.3.0 → 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/README.md +1 -1
- data/lib/solargraph_test_coverage/config.rb +6 -6
- data/lib/solargraph_test_coverage/diagnostic_messages.rb +13 -13
- data/lib/solargraph_test_coverage/example_status_reporter.rb +8 -5
- data/lib/solargraph_test_coverage/file_helpers.rb +17 -9
- data/lib/solargraph_test_coverage/reporter_guards.rb +10 -12
- data/lib/solargraph_test_coverage/reporter_helpers.rb +20 -23
- data/lib/solargraph_test_coverage/test_coverage_reporter.rb +8 -9
- data/lib/solargraph_test_coverage/version.rb +1 -1
- metadata +2 -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/README.md
CHANGED
@@ -57,6 +57,10 @@ module SolargraphTestCoverage
|
|
57
57
|
plugin_config['test_framework']
|
58
58
|
end
|
59
59
|
|
60
|
+
def full_test_dir
|
61
|
+
File.join(Dir.pwd, test_dir)
|
62
|
+
end
|
63
|
+
|
60
64
|
def test_dir
|
61
65
|
case test_framework
|
62
66
|
when 'rspec'
|
@@ -102,9 +106,9 @@ module SolargraphTestCoverage
|
|
102
106
|
def preload_rails!
|
103
107
|
return if defined?(Rails) || !File.file?('spec/rails_helper.rb')
|
104
108
|
|
105
|
-
$LOAD_PATH.unshift(
|
109
|
+
$LOAD_PATH.unshift(full_test_dir) unless $LOAD_PATH.include?(full_test_dir)
|
106
110
|
|
107
|
-
require File.join(
|
111
|
+
require File.join(full_test_dir, 'rails_helper')
|
108
112
|
Coverage.result(stop: true, clear: true) if Coverage.running?
|
109
113
|
|
110
114
|
true
|
@@ -126,9 +130,5 @@ module SolargraphTestCoverage
|
|
126
130
|
def workspace_config
|
127
131
|
Solargraph::Workspace::Config.new(Dir.pwd).raw_data.fetch('test_coverage', {})
|
128
132
|
end
|
129
|
-
|
130
|
-
def test_path
|
131
|
-
FileHelpers.test_path
|
132
|
-
end
|
133
133
|
end
|
134
134
|
end
|
@@ -2,64 +2,64 @@
|
|
2
2
|
|
3
3
|
module SolargraphTestCoverage
|
4
4
|
module DiagnosticMessages
|
5
|
-
def line_coverage_warning(
|
5
|
+
def line_coverage_warning(line)
|
6
6
|
return unless Config.line_coverage?
|
7
7
|
|
8
8
|
{
|
9
|
-
range: range(line, 0, line, source.code.lines[line].length),
|
9
|
+
range: range(line, 0, line, @source.code.lines[line].length),
|
10
10
|
severity: Solargraph::Diagnostics::Severities::WARNING,
|
11
11
|
source: 'TestCoverage',
|
12
12
|
message: 'Line is missing test coverage'
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
|
-
def branch_coverage_warning(
|
16
|
+
def branch_coverage_warning(report)
|
17
17
|
return unless Config.branch_coverage?
|
18
18
|
|
19
19
|
{
|
20
|
-
range: range(report[:line] - 1, 0, report[:line] - 1, source.code.lines[report[:line] - 1].length),
|
20
|
+
range: range(report[:line] - 1, 0, report[:line] - 1, @source.code.lines[report[:line] - 1].length),
|
21
21
|
severity: Solargraph::Diagnostics::Severities::WARNING,
|
22
22
|
source: 'TestCoverage',
|
23
23
|
message: "'#{report[:type].upcase}' branch is missing test coverage"
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
-
def test_failing_error
|
27
|
+
def test_failing_error
|
28
28
|
return unless Config.test_failing_coverage?
|
29
29
|
|
30
30
|
{
|
31
|
-
range: range(0, 0, 0, source.code.lines[0].length),
|
31
|
+
range: range(0, 0, 0, @source.code.lines[0].length),
|
32
32
|
severity: Solargraph::Diagnostics::Severities::ERROR,
|
33
33
|
source: 'TestCoverage',
|
34
34
|
message: 'Unit Test is currently failing.'
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
|
-
def test_missing_error
|
38
|
+
def test_missing_error
|
39
39
|
return unless Config.test_missing_coverage?
|
40
40
|
|
41
41
|
{
|
42
|
-
range: range(0, 0, 0, source.code.lines[0].length),
|
42
|
+
range: range(0, 0, 0, @source.code.lines[0].length),
|
43
43
|
severity: Solargraph::Diagnostics::Severities::HINT,
|
44
44
|
source: 'TestCoverage',
|
45
|
-
message: "No test file found at '#{FileHelpers.
|
45
|
+
message: "No test file found at '#{FileHelpers.relative_test_file(@filename)}'"
|
46
46
|
}
|
47
47
|
end
|
48
48
|
|
49
|
-
def example_failing_error(example
|
49
|
+
def example_failing_error(example)
|
50
50
|
return unless Config.example_failing_coverage?
|
51
51
|
|
52
52
|
{
|
53
|
-
range: range(example[:line_number], 0, example[:line_number], source.code.lines[example[:line_number]].length),
|
53
|
+
range: range(example[:line_number], 0, example[:line_number], @source.code.lines[example[:line_number]].length),
|
54
54
|
severity: Solargraph::Diagnostics::Severities::ERROR,
|
55
55
|
source: 'ExampleStatus',
|
56
56
|
message: example[:message]
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
60
|
-
def debug_message(exception
|
60
|
+
def debug_message(exception)
|
61
61
|
{
|
62
|
-
range: range(0, 0, 0, source.code.lines[0].length),
|
62
|
+
range: range(0, 0, 0, @source.code.lines[0].length),
|
63
63
|
severity: Solargraph::Diagnostics::Severities::ERROR,
|
64
64
|
source: 'SolargraphTestCoverage Plugin',
|
65
65
|
message: "DEBUG: (ChildFailedError) #{exception.message}"
|
@@ -8,13 +8,16 @@ module SolargraphTestCoverage
|
|
8
8
|
include DiagnosticMessages
|
9
9
|
|
10
10
|
def diagnose(source, _api_map)
|
11
|
-
|
12
|
-
|
13
|
-
end
|
11
|
+
@source = source
|
12
|
+
@filename = source.location.filename
|
14
13
|
|
15
|
-
|
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
|
16
19
|
rescue ChildFailedError => e
|
17
|
-
Config.debug? ? [debug_message(e
|
20
|
+
Config.debug? ? [debug_message(e)] : []
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -4,19 +4,27 @@ module SolargraphTestCoverage
|
|
4
4
|
module FileHelpers
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def test_file(
|
8
|
-
|
7
|
+
def test_file(filename)
|
8
|
+
return filename if test_file?(filename)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
path = relative_path(filename).split('/')
|
11
|
+
path[0] = Config.test_dir
|
12
|
+
path[-1] = path.last.sub(/\.rb$/, Config.test_file_suffix)
|
13
13
|
|
14
|
-
|
15
|
-
File.join(Dir.pwd, relative_filepath.join('/')).sub('.rb', Config.test_file_suffix)
|
14
|
+
File.join(Dir.pwd, path.join('/'))
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
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)
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
@@ -3,26 +3,24 @@
|
|
3
3
|
module SolargraphTestCoverage
|
4
4
|
# Some guard functions for the diagnostics
|
5
5
|
module ReporterGuards
|
6
|
-
def
|
7
|
-
File.file? FileHelpers.test_file(
|
6
|
+
def test_file_exists?
|
7
|
+
File.file? FileHelpers.test_file(@filename)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def in_test_dir?
|
11
|
+
@filename.start_with? Config.full_test_dir
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def test_support_file?
|
15
|
+
in_test_dir? && !@filename.end_with?(Config.test_file_suffix)
|
16
16
|
end
|
17
17
|
|
18
|
-
def exclude_file?
|
19
|
-
Config.exclude_paths.any? { |path|
|
18
|
+
def exclude_file?
|
19
|
+
Config.exclude_paths.any? { |path| FileHelpers.relative_path(@filename).include? path }
|
20
20
|
end
|
21
21
|
|
22
|
-
def using_debugger?
|
23
|
-
source.code.
|
24
|
-
source.code.include?('byebug') ||
|
25
|
-
source.code.include?('debugger')
|
22
|
+
def using_debugger?
|
23
|
+
@source.code.match?(/(binding\.pry|byebug|debugger)/)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -4,32 +4,33 @@ module SolargraphTestCoverage
|
|
4
4
|
# Some helper functions for the diagnostics
|
5
5
|
module ReporterHelpers
|
6
6
|
# @return [Hash]
|
7
|
-
def run_test(
|
7
|
+
def run_test(test_file)
|
8
8
|
ForkProcess.call do
|
9
9
|
Coverage.start(lines: true, branches: true)
|
10
10
|
runner = TestRunner.with(test_file).run!
|
11
|
+
extra = { test_status: runner.passed?, failed_examples: runner.failed_examples }
|
11
12
|
|
12
|
-
Coverage.result
|
13
|
-
.fetch(source.location.filename, {})
|
14
|
-
.merge({ test_status: runner.passed?, failed_examples: runner.failed_examples })
|
13
|
+
Coverage.result.fetch(@filename, {}).merge(extra)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
17
|
+
def branch_warnings
|
18
|
+
Branch.build_from(@results)
|
19
|
+
.reject(&:covered?)
|
20
|
+
.map { |branch| branch_coverage_warning(branch.report) }
|
20
21
|
end
|
21
22
|
|
22
|
-
def
|
23
|
-
|
23
|
+
def test_passing_error
|
24
|
+
@results[:test_status] ? [] : [test_failing_error]
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
results
|
27
|
+
def example_failing_errors
|
28
|
+
@results.fetch(:failed_examples, [])
|
29
|
+
.map { |example| example_failing_error(example) }
|
28
30
|
end
|
29
31
|
|
30
|
-
def
|
31
|
-
|
32
|
-
.map { |example| example_failing_error(example, source) }
|
32
|
+
def line_warnings
|
33
|
+
uncovered_lines.map { |line| line_coverage_warning(line) }
|
33
34
|
end
|
34
35
|
|
35
36
|
# Adapted from SingleCov
|
@@ -38,17 +39,13 @@ module SolargraphTestCoverage
|
|
38
39
|
#
|
39
40
|
# [nil, 1, 0, 1, 0] -> [3, 5]
|
40
41
|
# Returns array of line numbers with 0 coverage
|
41
|
-
def uncovered_lines
|
42
|
-
return [] unless results[:lines]
|
42
|
+
def uncovered_lines
|
43
|
+
return [] unless @results[:lines]
|
43
44
|
|
44
|
-
results[:lines].each_with_index
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def uncovered_branches(results)
|
51
|
-
Branch.build_from(results).reject(&:covered?)
|
45
|
+
@results[:lines].each_with_index
|
46
|
+
.select { |c, _| c&.zero? }
|
47
|
+
.map { |_, i| i }
|
48
|
+
.compact
|
52
49
|
end
|
53
50
|
end
|
54
51
|
end
|
@@ -8,18 +8,17 @@ module SolargraphTestCoverage
|
|
8
8
|
include DiagnosticMessages
|
9
9
|
|
10
10
|
def diagnose(source, _api_map)
|
11
|
-
|
12
|
-
|
11
|
+
@source = source
|
12
|
+
@filename = source.location.filename
|
13
13
|
|
14
|
-
|
14
|
+
return [] if source.code.empty? || using_debugger? || exclude_file? || in_test_dir?
|
15
|
+
return [test_missing_error] unless test_file_exists?
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
test_passing_error(source, results)
|
20
|
-
].flatten.compact
|
17
|
+
@results = run_test(FileHelpers.test_file(@filename))
|
18
|
+
|
19
|
+
[line_warnings, branch_warnings, test_passing_error].flatten.compact
|
21
20
|
rescue ChildFailedError => e
|
22
|
-
Config.debug? ? [debug_message(e
|
21
|
+
Config.debug? ? [debug_message(e)] : []
|
23
22
|
end
|
24
23
|
end
|
25
24
|
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.3.
|
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
|