uncov 0.5.0 → 0.6.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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +21 -7
- data/lib/{uncov → plugins/uncov}/formatter/terminal.rb +19 -8
- data/lib/plugins/uncov/report/filters/diff_files.rb +33 -0
- data/lib/plugins/uncov/report/filters/diff_lines.rb +33 -0
- data/lib/plugins/uncov/report/filters/file_system.rb +33 -0
- data/lib/plugins/uncov/report/filters/git_files.rb +33 -0
- data/lib/plugins/uncov/report/filters/nocov_lines.rb +35 -0
- data/lib/plugins/uncov/report/filters/simplecov.rb +33 -0
- data/lib/uncov/configuration.rb +6 -6
- data/lib/uncov/finder/file_system.rb +11 -9
- data/lib/uncov/finder/files.rb +30 -0
- data/lib/uncov/finder/git.rb +9 -5
- data/lib/uncov/finder/git_diff.rb +11 -12
- data/lib/uncov/finder/{no_cov.rb → nocov.rb} +4 -12
- data/lib/uncov/finder/{simple_cov.rb → simplecov.rb} +3 -3
- data/lib/uncov/finder.rb +43 -58
- data/lib/uncov/formatter.rb +5 -18
- data/lib/uncov/report/context.rb +24 -0
- data/lib/uncov/report/file/line.rb +8 -8
- data/lib/uncov/report/filters.rb +20 -0
- data/lib/uncov/report.rb +1 -1
- data/lib/uncov/version.rb +1 -1
- data/lib/uncov.rb +10 -6
- metadata +29 -12
- data/lib/uncov/report/generator/diff_files.rb +0 -57
- data/lib/uncov/report/generator/diff_lines.rb +0 -65
- data/lib/uncov/report/generator/git_files.rb +0 -57
- data/lib/uncov/report/generator/nocov_lines.rb +0 -67
- data/lib/uncov/report/generator.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc5eb3c1149eba5de56dd2bd43a4bf9a450abc25689456ef9290da0bb903b657
|
4
|
+
data.tar.gz: '08567ab62f909c0b8ebdf9f8bc8793edcb0e96e77408b10a5249da61cab7e42d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 849aec6d7483b7e76349d714ed59a7c53f0f3d9dd7c04e1423b808c0f00559274ef541fff97a024e001f7861a171c1079769229bc2bb2652500568f14f1f4283
|
7
|
+
data.tar.gz: 07eda0122c302e6003ed972585f7d0103985bbf56a5bf778029a3c3591ab9535cc94c8d3b83cc211f94eace1ebf495ef10eb365d8339807179e3ec3d8e294ad7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2025-05-26: [v0.6.0](https://github.com/mpapis/uncov/releases/tag/v0.6.0)
|
4
|
+
|
5
|
+
### Minor
|
6
|
+
|
7
|
+
- [#47](https://github.com/mpapis/uncov/pull/47): Extensible with plugins, by [@mpapis](https://github.com/mpapis)
|
8
|
+
- [#56](https://github.com/mpapis/uncov/pull/56): Add Simplecov and FileSystem filters, by [@mpapis](https://github.com/mpapis)
|
9
|
+
|
10
|
+
### Patch
|
11
|
+
|
12
|
+
- [#59](https://github.com/mpapis/uncov/pull/59): Simplify git rev-parse target, by [@mpapis](https://github.com/mpapis)
|
13
|
+
|
14
|
+
|
3
15
|
## 2025-05-12: [v0.5.0](https://github.com/mpapis/uncov/releases/tag/v0.5.0)
|
4
16
|
|
5
17
|
### Minor
|
data/README.md
CHANGED
@@ -13,6 +13,8 @@ Uncov uses `git diff` to detect changes and `simplecov` reports to detect uncove
|
|
13
13
|
- Identify changed Ruby files
|
14
14
|
- Run tests automatically for (changed) relevant files
|
15
15
|
- Print report of uncovered lines in (changed) files
|
16
|
+
- Print report of covered :nocov: lines in (changed) files
|
17
|
+
- Extensible with gem plugins
|
16
18
|
|
17
19
|
|
18
20
|
## Installation
|
@@ -36,8 +38,8 @@ uncov
|
|
36
38
|
$ uncov -h
|
37
39
|
Usage: uncov [options]
|
38
40
|
-t, --target TARGET Target branch for comparison, default: "HEAD"
|
39
|
-
-r, --report FILTER Report filter to generate file/line list, one_of: "
|
40
|
-
-o, --output-format FORMAT Output format, one_of: "
|
41
|
+
-r, --report FILTER Report filter to generate file/line list, one_of: "DiffFiles", "DiffLines"(default), "FileSystem", "GitFiles", "NocovLines", "Simplecov"
|
42
|
+
-o, --output-format FORMAT Output format, one_of: "Terminal"(default)
|
41
43
|
-C, --context LINES_NUMBER Additional lines context in output, default: 1
|
42
44
|
--test-command COMMAND Test command that generates SimpleCov, default: "COVERAGE=true bundle exec rake test"
|
43
45
|
--simplecov-file PATH SimpleCov results file, default: "autodetect"
|
@@ -49,10 +51,12 @@ Usage: uncov [options]
|
|
49
51
|
-h, --help Print this help
|
50
52
|
|
51
53
|
Report FILTERs:
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
DiffFiles - Report missing coverage on added/changed files in the git diff
|
55
|
+
DiffLines - Report missing coverage on added lines in the git diff
|
56
|
+
FileSystem - Report missing coverage on file system
|
57
|
+
GitFiles - Report missing coverage on files tracked with git
|
58
|
+
NocovLines - Report coverage on nocov lines, requires one or both: --nocov-ignore / --nocov-covered
|
59
|
+
Simplecov - Report missing coverage on files tracked with simplecov
|
56
60
|
|
57
61
|
Report FILTERs take NOTICE:
|
58
62
|
git*/diff* - filters will not consider new files unless added to the git index with `git add`.
|
@@ -62,7 +66,7 @@ nocov* - filters/flags only work with coverage/.resultset.json SimpleCov fi
|
|
62
66
|
FN_GLOB: shell filename globing -> https://ruby-doc.org/core-3.1.1/File.html#method-c-fnmatch
|
63
67
|
in bash: `shopt -s extglob dotglob globstar` and test with `ls {app,lib}/**/*.rb`
|
64
68
|
|
65
|
-
uncov 0.
|
69
|
+
uncov 0.6.0 by Michal Papis <mpapis@gmail.com>
|
66
70
|
```
|
67
71
|
|
68
72
|
|
@@ -79,6 +83,16 @@ COVERAGE=1 rspec
|
|
79
83
|
```
|
80
84
|
|
81
85
|
|
86
|
+
## Plugins
|
87
|
+
Uncov uses [pluginator](https://github.com/rvm/pluginator) to load plugins.
|
88
|
+
|
89
|
+
See [lib/plugins/uncov](lib/plugins/uncov) for default plugins.
|
90
|
+
|
91
|
+
To create your own plugin, create a gem with a `lib/plugins/uncov/...` structure - same as uncov has,
|
92
|
+
the plugins will be loaded automatically.
|
93
|
+
|
94
|
+
When you use uncov from a Gemfile then the new gam has to be added there too.
|
95
|
+
|
82
96
|
## Using in CI
|
83
97
|
`uncov` uses itself to check new missing code coverage [.github/workflows/ci.yml](.github/workflows/ci.yml),
|
84
98
|
no need to set minimal, always get better.
|
@@ -13,15 +13,16 @@ class Uncov::Formatter::Terminal
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def output
|
16
|
-
puts
|
16
|
+
return puts 'No files to report.'.green if report.files.empty?
|
17
|
+
return puts "All changed files(#{report.files.count}) have 100% test coverage!".green unless report.trigger?
|
18
|
+
|
19
|
+
output_header
|
17
20
|
output_files
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
relevant_lines: report.relevant_lines_count
|
24
|
-
).yellow
|
21
|
+
output_summary
|
22
|
+
end
|
23
|
+
|
24
|
+
def output_header
|
25
|
+
puts "Files with uncovered changes: (#{report.display_files.size} / #{report.files.count})".yellow
|
25
26
|
end
|
26
27
|
|
27
28
|
def output_files
|
@@ -70,4 +71,14 @@ class Uncov::Formatter::Terminal
|
|
70
71
|
def number_length(file_coverage)
|
71
72
|
file_coverage.display_lines.last.number.to_s.length
|
72
73
|
end
|
74
|
+
|
75
|
+
def output_summary
|
76
|
+
puts
|
77
|
+
puts format(
|
78
|
+
'Overall coverage of changes: %<coverage>.2f%% (%<covered_lines>d / %<relevant_lines>d)',
|
79
|
+
coverage: report.coverage,
|
80
|
+
covered_lines: report.covered_lines_count,
|
81
|
+
relevant_lines: report.relevant_lines_count
|
82
|
+
).yellow
|
83
|
+
end
|
73
84
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# report only files lines from the diff
|
4
|
+
module Uncov::Report::Filters::DiffFiles
|
5
|
+
class << self
|
6
|
+
def description = 'Report missing coverage on added/changed files in the git diff'
|
7
|
+
def simplecov_trigger = :git_diff
|
8
|
+
|
9
|
+
def files(finder)
|
10
|
+
finder.git_diff_files.file_names.map do |file_name|
|
11
|
+
Uncov::Report::File.new(
|
12
|
+
file_name:,
|
13
|
+
git: true,
|
14
|
+
lines: lines(finder, file_name)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def lines(finder, file_name)
|
22
|
+
lines_hash = file_lines(finder, file_name)
|
23
|
+
Uncov::Report::Context.add_context(finder, file_name, lines_hash)
|
24
|
+
lines_hash.sort.to_h.values
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_lines(finder, file_name)
|
28
|
+
finder.file_system_files.lines(file_name).keys.to_h do |line_number|
|
29
|
+
[line_number, finder.build_line(file_name, line_number)]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# report only files lines from the diff
|
4
|
+
module Uncov::Report::Filters::DiffLines
|
5
|
+
class << self
|
6
|
+
def description = 'Report missing coverage on added lines in the git diff'
|
7
|
+
def simplecov_trigger = :git_diff
|
8
|
+
|
9
|
+
def files(finder)
|
10
|
+
finder.git_diff_files.file_names.map do |file_name|
|
11
|
+
Uncov::Report::File.new(
|
12
|
+
file_name:,
|
13
|
+
git: true,
|
14
|
+
lines: lines(finder, file_name)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def lines(finder, file_name)
|
22
|
+
lines_hash = git_diff_files_lines(finder, file_name)
|
23
|
+
Uncov::Report::Context.add_context(finder, file_name, lines_hash)
|
24
|
+
lines_hash.sort.to_h.values
|
25
|
+
end
|
26
|
+
|
27
|
+
def git_diff_files_lines(finder, file_name)
|
28
|
+
finder.git_diff_files.lines(file_name).keys.to_h do |line_number|
|
29
|
+
[line_number, finder.build_line(file_name, line_number)]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# report all files lines from the file system
|
4
|
+
module Uncov::Report::Filters::FileSystem
|
5
|
+
class << self
|
6
|
+
def description = 'Report missing coverage on file system'
|
7
|
+
def simplecov_trigger = :file_system
|
8
|
+
|
9
|
+
def files(finder)
|
10
|
+
finder.file_system_files.file_names.map do |file_name|
|
11
|
+
Uncov::Report::File.new(
|
12
|
+
file_name:,
|
13
|
+
git: finder.git_files.file?(file_name),
|
14
|
+
lines: lines(finder, file_name)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def lines(finder, file_name)
|
22
|
+
lines_hash = file_lines(finder, file_name)
|
23
|
+
Uncov::Report::Context.add_context(finder, file_name, lines_hash)
|
24
|
+
lines_hash.sort.to_h.values
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_lines(finder, file_name)
|
28
|
+
finder.file_system_files.lines(file_name).keys.to_h do |line_number|
|
29
|
+
[line_number, finder.build_line(file_name, line_number)]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# report only files lines from the diff
|
4
|
+
module Uncov::Report::Filters::GitFiles
|
5
|
+
class << self
|
6
|
+
def description = 'Report missing coverage on files tracked with git'
|
7
|
+
def simplecov_trigger = :git
|
8
|
+
|
9
|
+
def files(finder)
|
10
|
+
finder.git_files.file_names.map do |file_name|
|
11
|
+
Uncov::Report::File.new(
|
12
|
+
file_name:,
|
13
|
+
git: true,
|
14
|
+
lines: lines(finder, file_name)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def lines(finder, file_name)
|
22
|
+
lines_hash = file_lines(finder, file_name)
|
23
|
+
Uncov::Report::Context.add_context(finder, file_name, lines_hash)
|
24
|
+
lines_hash.sort.to_h.values
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_lines(finder, file_name)
|
28
|
+
finder.file_system_files.lines(file_name).keys.to_h do |line_number|
|
29
|
+
[line_number, finder.build_line(file_name, line_number)]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# report only files lines from the diff
|
4
|
+
module Uncov::Report::Filters::NocovLines
|
5
|
+
class << self
|
6
|
+
def description = 'Report coverage on nocov lines, requires one or both: --nocov-ignore / --nocov-covered'
|
7
|
+
def simplecov_trigger = :file_system
|
8
|
+
|
9
|
+
def files(finder)
|
10
|
+
finder.nocov_files.file_names.filter_map do |file_name|
|
11
|
+
next if finder.nocov_files.lines(file_name).empty?
|
12
|
+
|
13
|
+
Uncov::Report::File.new(
|
14
|
+
file_name:,
|
15
|
+
git: finder.git_files.file?(file_name),
|
16
|
+
lines: lines(finder, file_name)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def lines(finder, file_name)
|
24
|
+
lines_hash = nocov_files_lines(finder, file_name)
|
25
|
+
Uncov::Report::Context.add_context(finder, file_name, lines_hash)
|
26
|
+
lines_hash.sort.to_h.values
|
27
|
+
end
|
28
|
+
|
29
|
+
def nocov_files_lines(finder, file_name)
|
30
|
+
finder.nocov_files.lines(file_name).keys.to_h do |line_number|
|
31
|
+
[line_number, finder.build_line(file_name, line_number)]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# report only files lines from the simplecov
|
4
|
+
module Uncov::Report::Filters::Simplecov
|
5
|
+
class << self
|
6
|
+
def description = 'Report missing coverage on files tracked with simplecov'
|
7
|
+
def simplecov_trigger = :file_system
|
8
|
+
|
9
|
+
def files(finder)
|
10
|
+
finder.simplecov_files.file_names.map do |file_name|
|
11
|
+
Uncov::Report::File.new(
|
12
|
+
file_name:,
|
13
|
+
git: finder.git_files.file?(file_name),
|
14
|
+
lines: lines(finder, file_name)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def lines(finder, file_name)
|
22
|
+
lines_hash = file_lines(finder, file_name)
|
23
|
+
Uncov::Report::Context.add_context(finder, file_name, lines_hash)
|
24
|
+
lines_hash.sort.to_h.values
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_lines(finder, file_name)
|
28
|
+
finder.file_system_files.lines(file_name).keys.to_h do |line_number|
|
29
|
+
[line_number, finder.build_line(file_name, line_number)]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/uncov/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'formatter'
|
4
|
-
require_relative 'report/
|
4
|
+
require_relative 'report/filters'
|
5
5
|
|
6
6
|
# handle configuration for uncov
|
7
7
|
class Uncov::Configuration
|
@@ -21,9 +21,9 @@ class Uncov::Configuration
|
|
21
21
|
|
22
22
|
option 'target', 'Target branch for comparison', options: ['-t', '--target TARGET'], default: 'HEAD'
|
23
23
|
option 'report', 'Report filter to generate file/line list',
|
24
|
-
options: ['-r', '--report FILTER'], default: '
|
24
|
+
options: ['-r', '--report FILTER'], default: 'DiffLines', allowed_values: -> { Uncov::Report::Filters.filters.keys }
|
25
25
|
option 'output_format', 'Output format',
|
26
|
-
options: ['-o', '--output-format FORMAT'], default: '
|
26
|
+
options: ['-o', '--output-format FORMAT'], default: 'Terminal', allowed_values: -> { Uncov::Formatter.formatters.keys }
|
27
27
|
option 'context', 'Additional lines context in output',
|
28
28
|
options: ['-C', '--context LINES_NUMBER'], default: 1, value_parse: lambda(&:to_i)
|
29
29
|
option 'test_command', 'Test command that generates SimpleCov',
|
@@ -101,9 +101,9 @@ class Uncov::Configuration
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def footer_extras_types
|
104
|
-
report_type_length = Uncov::Report::
|
105
|
-
Uncov::Report::
|
106
|
-
"
|
104
|
+
report_type_length = Uncov::Report::Filters.filters.keys.map(&:length).max
|
105
|
+
Uncov::Report::Filters.filters.map do |name, filter|
|
106
|
+
format("%#{report_type_length}s - %s", name, filter.description)
|
107
107
|
end.join("\n")
|
108
108
|
end
|
109
109
|
|
@@ -4,22 +4,24 @@
|
|
4
4
|
class Uncov::Finder::FileSystem
|
5
5
|
include Uncov::Cache
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
[file_name,
|
7
|
+
def code_files
|
8
|
+
list_files(Uncov.configuration.relevant_files).to_h do |file_name|
|
9
|
+
[file_name, read_lines(file_name)]
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
def simplecov_trigger_files
|
14
|
+
code_files.keys + test_files
|
15
|
+
end
|
16
|
+
|
13
17
|
private
|
14
18
|
|
15
|
-
def
|
16
|
-
|
19
|
+
def test_files
|
20
|
+
list_files(Uncov.configuration.relevant_tests)
|
17
21
|
end
|
18
22
|
|
19
|
-
def
|
20
|
-
|
21
|
-
read_lines(file_name)
|
22
|
-
end
|
23
|
+
def list_files(glob)
|
24
|
+
Dir.glob(glob, Uncov::Configuration::FILE_MATCH_FLAGS).select { |f| File.file?(f) }
|
23
25
|
end
|
24
26
|
|
25
27
|
def read_lines(file_name)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# wrap finder results to have the same interface as finder
|
4
|
+
class Uncov::Finder::Files
|
5
|
+
attr_reader :files
|
6
|
+
|
7
|
+
def initialize(files)
|
8
|
+
@files = files
|
9
|
+
end
|
10
|
+
|
11
|
+
def file?(file_name)
|
12
|
+
@files.key?(file_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_names
|
16
|
+
@files.keys
|
17
|
+
end
|
18
|
+
|
19
|
+
def lines(file_name)
|
20
|
+
@files[file_name] || {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def line(file_name, line_number)
|
24
|
+
@files.dig(file_name, line_number)
|
25
|
+
end
|
26
|
+
|
27
|
+
def line?(file_name, line_number)
|
28
|
+
lines(file_name)&.key?(line_number)
|
29
|
+
end
|
30
|
+
end
|
data/lib/uncov/finder/git.rb
CHANGED
@@ -14,16 +14,20 @@ class Uncov::Finder::Git
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def simplecov_trigger_files
|
18
|
+
code_files.keys + test_files
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
17
23
|
def test_files
|
18
24
|
cache(:test_files) do
|
19
|
-
all_file_names.
|
20
|
-
|
21
|
-
end
|
25
|
+
all_file_names.select do |file_name|
|
26
|
+
relevant_test_file?(file_name)
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
25
|
-
private
|
26
|
-
|
27
31
|
def all_file_names
|
28
32
|
cache(:all_files) do
|
29
33
|
open_repo.ls_files.keys
|
@@ -15,16 +15,20 @@ class Uncov::Finder::GitDiff
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def simplecov_trigger_files
|
19
|
+
code_files.keys + test_files
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
18
24
|
def test_files
|
19
25
|
cache(:test_files) do
|
20
26
|
all_files_diff.filter_map do |file_diff|
|
21
|
-
|
22
|
-
end
|
27
|
+
file_diff.path if relevant_test_file?(file_diff.path) && File.exist?(file_diff.path)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
26
|
-
private
|
27
|
-
|
28
32
|
def all_files_diff
|
29
33
|
cache(:all_files) do
|
30
34
|
git_diff
|
@@ -43,15 +47,10 @@ class Uncov::Finder::GitDiff
|
|
43
47
|
|
44
48
|
def git_diff
|
45
49
|
repo = open_repo
|
46
|
-
|
47
|
-
git_target = repo.lib.send(:command, 'rev-parse', '--verify', target)
|
50
|
+
git_target = repo.rev_parse(target)
|
48
51
|
repo.diff(git_target)
|
49
|
-
rescue Git::FailedError
|
50
|
-
raise Uncov::NotGitObjectError, target
|
51
|
-
|
52
|
-
# :nocov: when we find a failing example, we can test it
|
53
|
-
raise
|
54
|
-
# :nocov:
|
52
|
+
rescue Git::FailedError
|
53
|
+
raise Uncov::NotGitObjectError, target
|
55
54
|
end
|
56
55
|
|
57
56
|
def target
|
@@ -1,24 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# collect nocov information from files
|
4
|
-
class Uncov::Finder::
|
5
|
-
include Uncov::Cache
|
6
|
-
|
4
|
+
class Uncov::Finder::Nocov
|
7
5
|
def files(all_files)
|
8
|
-
all_files.
|
9
|
-
|
6
|
+
all_files.files.transform_values do |lines|
|
7
|
+
nocov_lines(lines)
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
13
11
|
private
|
14
12
|
|
15
|
-
def nocov_lines(
|
16
|
-
cache(file_name) do
|
17
|
-
read_nocov(lines)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def read_nocov(lines)
|
13
|
+
def nocov_lines(lines)
|
22
14
|
nocov = false
|
23
15
|
lines.filter_map do |number, line|
|
24
16
|
line_nocov = line.strip.start_with?('# :nocov:')
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
# collect coverage information, regenerates report if any trigger_files are newer then the report
|
6
|
-
module Uncov::Finder::
|
6
|
+
module Uncov::Finder::Simplecov
|
7
7
|
class << self
|
8
8
|
def files(trigger_files)
|
9
9
|
regenerate_report if requires_regeneration?(trigger_files)
|
@@ -67,9 +67,9 @@ module Uncov::Finder::SimpleCov
|
|
67
67
|
def raise_on_missing_coverage_path!
|
68
68
|
return if coverage_path && File.exist?(coverage_path)
|
69
69
|
|
70
|
-
raise Uncov::
|
70
|
+
raise Uncov::AutodetectSimplecovPathError if Uncov.configuration.simplecov_file == 'autodetect'
|
71
71
|
|
72
|
-
raise Uncov::
|
72
|
+
raise Uncov::MissingSimplecovReport, coverage_path
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
data/lib/uncov/finder.rb
CHANGED
@@ -4,94 +4,79 @@
|
|
4
4
|
class Uncov::Finder
|
5
5
|
include Uncov::Cache
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
|
9
|
-
def git_file_names = git_files.keys
|
10
|
-
def git_diff_file_names = git_diff_files.keys
|
11
|
-
def git_diff_file_lines(file_name) = git_diff_files[file_name]
|
12
|
-
def git_diff_file_line?(file_name, line_number) = git_diff_files[file_name]&.key?(line_number)
|
13
|
-
def file_system_file_names = file_system_files.keys
|
14
|
-
def file_system_file_line(file_name, line_number) = file_system_files[file_name]&.dig(line_number)
|
15
|
-
def file_system_file_lines(file_name) = file_system_files[file_name]
|
16
|
-
def no_cov_file_names = no_cov_files.keys
|
17
|
-
def no_cov_file_lines(file_name) = no_cov_files[file_name]
|
18
|
-
def no_cov_file_line?(file_name, line_number) = no_cov_files[file_name]&.dig(line_number)
|
19
|
-
def simple_cov_file_line?(file_name, line_number) = simple_cov_files.dig(file_name, line_number)
|
20
|
-
|
21
|
-
def debug
|
22
|
-
{
|
23
|
-
git_files:,
|
24
|
-
git_test_files:,
|
25
|
-
git_diff_files:,
|
26
|
-
git_diff_test_files:,
|
27
|
-
file_system_files:,
|
28
|
-
no_cov_files:,
|
29
|
-
simple_cov_files:
|
30
|
-
}
|
7
|
+
def initialize(simplecov_trigger)
|
8
|
+
@simplecov_trigger = simplecov_trigger
|
31
9
|
end
|
32
10
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
11
|
+
def build_line(file_name, line_number, context: false)
|
12
|
+
Uncov::Report::File::Line.new(
|
13
|
+
number: line_number,
|
14
|
+
content: file_system_files.line(file_name, line_number),
|
15
|
+
nocov: nocov_files.line(file_name, line_number),
|
16
|
+
simplecov: simplecov_files.line(file_name, line_number),
|
17
|
+
git_diff: git_diff_files.line?(file_name, line_number),
|
18
|
+
context:
|
19
|
+
)
|
39
20
|
end
|
40
21
|
|
41
|
-
def
|
42
|
-
|
22
|
+
def file_system_files
|
23
|
+
Uncov::Finder::Files.new(file_system_finder.code_files)
|
43
24
|
end
|
44
25
|
|
45
|
-
def
|
46
|
-
|
47
|
-
Uncov::Finder::Git.new
|
48
|
-
end
|
26
|
+
def git_files
|
27
|
+
Uncov::Finder::Files.new(git_finder.code_files)
|
49
28
|
end
|
50
29
|
|
51
30
|
def git_diff_files
|
52
|
-
git_diff_finder.code_files
|
31
|
+
Uncov::Finder::Files.new(git_diff_finder.code_files)
|
53
32
|
end
|
54
33
|
|
55
|
-
def
|
56
|
-
|
34
|
+
def nocov_files
|
35
|
+
cache(:nocov_files) do
|
36
|
+
Uncov::Finder::Files.new(Uncov::Finder::Nocov.new.files(file_system_files))
|
37
|
+
end
|
57
38
|
end
|
58
39
|
|
59
|
-
def
|
60
|
-
cache(:
|
61
|
-
Uncov::Finder::
|
40
|
+
def simplecov_files
|
41
|
+
cache(:simplecov_files) do
|
42
|
+
Uncov::Finder::Files.new(Uncov::Finder::Simplecov.files(simplecov_trigger_files))
|
62
43
|
end
|
63
44
|
end
|
64
45
|
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_reader :simplecov_trigger
|
49
|
+
|
50
|
+
def file_system_finder
|
51
|
+
cache(:file_system_finder) do
|
52
|
+
Uncov::Finder::FileSystem.new
|
68
53
|
end
|
69
54
|
end
|
70
55
|
|
71
|
-
def
|
72
|
-
cache(:
|
73
|
-
Uncov::Finder::
|
56
|
+
def git_finder
|
57
|
+
cache(:git_finder) do
|
58
|
+
Uncov::Finder::Git.new
|
74
59
|
end
|
75
60
|
end
|
76
61
|
|
77
|
-
def
|
78
|
-
cache(:
|
79
|
-
Uncov::Finder::
|
62
|
+
def git_diff_finder
|
63
|
+
cache(:git_diff_finder) do
|
64
|
+
Uncov::Finder::GitDiff.new
|
80
65
|
end
|
81
66
|
end
|
82
67
|
|
83
|
-
def
|
84
|
-
case
|
68
|
+
def simplecov_trigger_files
|
69
|
+
case simplecov_trigger
|
85
70
|
when :git
|
86
|
-
|
71
|
+
git_finder
|
87
72
|
when :git_diff
|
88
|
-
|
73
|
+
git_diff_finder
|
89
74
|
when :file_system
|
90
|
-
|
75
|
+
file_system_finder
|
91
76
|
else
|
92
77
|
# :nocov:
|
93
|
-
raise Uncov::
|
78
|
+
raise Uncov::UnsupportedSimplecovTriggerError, simplecov_trigger
|
94
79
|
# :nocov:
|
95
|
-
end
|
80
|
+
end.simplecov_trigger_files
|
96
81
|
end
|
97
82
|
end
|
data/lib/uncov/formatter.rb
CHANGED
@@ -3,27 +3,14 @@
|
|
3
3
|
# chose formater to output the report
|
4
4
|
module Uncov::Formatter
|
5
5
|
class << self
|
6
|
-
def
|
7
|
-
|
8
|
-
def output(report)
|
9
|
-
if report.files.empty?
|
10
|
-
return puts 'No files to report.'.green
|
11
|
-
elsif !report.trigger?
|
12
|
-
return puts "All changed files(#{report.files.count}) have 100% test coverage!".green
|
13
|
-
end
|
14
|
-
|
15
|
-
output_report(report)
|
6
|
+
def formatters
|
7
|
+
@formatters ||= Uncov.plugins.plugins_map('formatter')
|
16
8
|
end
|
17
9
|
|
18
|
-
|
10
|
+
def output(report)
|
11
|
+
raise Uncov::UnsupportedFormatterError, Uncov.configuration.output_format unless formatters.key?(Uncov.configuration.output_format)
|
19
12
|
|
20
|
-
|
21
|
-
case Uncov.configuration.output_format
|
22
|
-
when 'terminal'
|
23
|
-
Uncov::Formatter::Terminal.new(report).output
|
24
|
-
else
|
25
|
-
raise Uncov::UnsupportedFormatterError, Uncov.configuration.output_format
|
26
|
-
end
|
13
|
+
formatters[Uncov.configuration.output_format].new(report).output
|
27
14
|
end
|
28
15
|
end
|
29
16
|
end
|
data/lib/uncov/report/context.rb
CHANGED
@@ -4,6 +4,20 @@
|
|
4
4
|
# @return [Integer] only added context lines matching all_line_numbers and not in important_line_numbers
|
5
5
|
module Uncov::Report::Context
|
6
6
|
class << self
|
7
|
+
def add_context(finder, file_name, lines_hash)
|
8
|
+
return if Uncov.configuration.context.zero?
|
9
|
+
|
10
|
+
line_numbers =
|
11
|
+
lines_hash.filter_map do |line_number, line|
|
12
|
+
line_number if line.trigger?
|
13
|
+
end
|
14
|
+
all_line_numbers = finder.file_system_files.lines(file_name).keys
|
15
|
+
context_line_numbers = calculate(all_line_numbers, line_numbers, Uncov.configuration.context)
|
16
|
+
context_line_numbers.each do |line_number|
|
17
|
+
mark_context_line(finder, file_name, lines_hash, line_number)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
7
21
|
def calculate(all_line_numbers, important_line_number, context)
|
8
22
|
context_line_numbers = {}
|
9
23
|
important_line_number.each do |line_number|
|
@@ -14,5 +28,15 @@ module Uncov::Report::Context
|
|
14
28
|
end
|
15
29
|
(context_line_numbers.keys.sort & all_line_numbers) - important_line_number
|
16
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def mark_context_line(finder, file_name, lines_hash, line_number)
|
35
|
+
if lines_hash.key?(line_number)
|
36
|
+
lines_hash[line_number].context = true
|
37
|
+
else
|
38
|
+
lines_hash[line_number] = finder.build_line(file_name, line_number, context: true)
|
39
|
+
end
|
40
|
+
end
|
17
41
|
end
|
18
42
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# represents file line coverage in report
|
4
|
-
class Uncov::Report::File::Line < Uncov::Struct.new(:number, :content, :
|
5
|
-
def
|
4
|
+
class Uncov::Report::File::Line < Uncov::Struct.new(:number, :content, :simplecov, :nocov, :context, :git_diff)
|
5
|
+
def nocov
|
6
6
|
return false if Uncov.configuration.nocov_ignore
|
7
7
|
|
8
|
-
self[:
|
8
|
+
self[:nocov]
|
9
9
|
end
|
10
10
|
|
11
11
|
def uncov?
|
12
|
-
|
12
|
+
simplecov == false && !nocov
|
13
13
|
end
|
14
14
|
|
15
15
|
def nocov_covered?
|
16
16
|
# :nocov
|
17
|
-
Uncov.configuration.nocov_covered &&
|
17
|
+
Uncov.configuration.nocov_covered && simplecov == true && self[:nocov]
|
18
18
|
# :nocov
|
19
19
|
end
|
20
20
|
|
21
21
|
def covered?
|
22
|
-
return false if Uncov.configuration.nocov_ignore && self[:
|
22
|
+
return false if Uncov.configuration.nocov_ignore && self[:nocov]
|
23
23
|
|
24
|
-
(
|
25
|
-
(Uncov.configuration.nocov_covered &&
|
24
|
+
(simplecov == true && !nocov) ||
|
25
|
+
(Uncov.configuration.nocov_covered && simplecov == false && self[:nocov])
|
26
26
|
end
|
27
27
|
|
28
28
|
def trigger?
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pluginator'
|
4
|
+
require_relative '../report'
|
5
|
+
|
6
|
+
# generate report files and lines for the configured report type
|
7
|
+
module Uncov::Report::Filters
|
8
|
+
class << self
|
9
|
+
def filters
|
10
|
+
@filters ||= Uncov.plugins.plugins_map('report/filters')
|
11
|
+
end
|
12
|
+
|
13
|
+
def files
|
14
|
+
raise Uncov::UnsupportedReportTypeError, Uncov.configuration.report unless filters.key?(Uncov.configuration.report)
|
15
|
+
|
16
|
+
filter = filters[Uncov.configuration.report]
|
17
|
+
filter.files(Uncov::Finder.new(filter.simplecov_trigger))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/uncov/report.rb
CHANGED
data/lib/uncov/version.rb
CHANGED
data/lib/uncov.rb
CHANGED
@@ -21,6 +21,10 @@ module Uncov
|
|
21
21
|
def configuration_reset!
|
22
22
|
@configuration = Configuration.new
|
23
23
|
end
|
24
|
+
|
25
|
+
def plugins
|
26
|
+
@plugins ||= Pluginator.find('uncov', extends: ['plugins_map'])
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
class Error < StandardError
|
@@ -30,7 +34,7 @@ module Uncov
|
|
30
34
|
class ConfigurationError < Error; end
|
31
35
|
class GitError < Error; end
|
32
36
|
class FinderError < Error; end
|
33
|
-
class
|
37
|
+
class SimplecovError < FinderError; end
|
34
38
|
class FormatterError < Error; end
|
35
39
|
class ReportError < Error; end
|
36
40
|
class OptionValueNotAllowed < ConfigurationError; end
|
@@ -49,25 +53,25 @@ module Uncov
|
|
49
53
|
def message = "Git target #{target_branch.inspect} not found locally"
|
50
54
|
end
|
51
55
|
|
52
|
-
class
|
56
|
+
class UnsupportedSimplecovTriggerError < FinderError
|
53
57
|
attr_reader :trigger
|
54
58
|
|
55
59
|
def initialize(trigger) = @trigger = trigger
|
56
|
-
def message = "#{trigger.inspect} is not a supported
|
60
|
+
def message = "#{trigger.inspect} is not a supported simplecov_trigger type"
|
57
61
|
end
|
58
62
|
|
59
|
-
class FailedToGenerateReport <
|
63
|
+
class FailedToGenerateReport < SimplecovError
|
60
64
|
def message = cause.message
|
61
65
|
end
|
62
66
|
|
63
|
-
class
|
67
|
+
class MissingSimplecovReport < SimplecovError
|
64
68
|
attr_reader :coverage_path
|
65
69
|
|
66
70
|
def initialize(coverage_path) = @coverage_path = coverage_path
|
67
71
|
def message = "SimpleCov results not found at #{coverage_path.inspect}"
|
68
72
|
end
|
69
73
|
|
70
|
-
class
|
74
|
+
class AutodetectSimplecovPathError < SimplecovError
|
71
75
|
def message = 'Could not autodetect coverage report path'
|
72
76
|
end
|
73
77
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uncov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michał Papis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: git_diff_parser
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pluginator
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.5'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.5'
|
83
97
|
description: uncov compares your current branch with a target branch, identifies changed
|
84
98
|
files, and reports on test coverage for those changes
|
85
99
|
email:
|
@@ -95,6 +109,13 @@ files:
|
|
95
109
|
- PHILOSOPHY.md
|
96
110
|
- README.md
|
97
111
|
- bin/uncov
|
112
|
+
- lib/plugins/uncov/formatter/terminal.rb
|
113
|
+
- lib/plugins/uncov/report/filters/diff_files.rb
|
114
|
+
- lib/plugins/uncov/report/filters/diff_lines.rb
|
115
|
+
- lib/plugins/uncov/report/filters/file_system.rb
|
116
|
+
- lib/plugins/uncov/report/filters/git_files.rb
|
117
|
+
- lib/plugins/uncov/report/filters/nocov_lines.rb
|
118
|
+
- lib/plugins/uncov/report/filters/simplecov.rb
|
98
119
|
- lib/uncov.rb
|
99
120
|
- lib/uncov/cache.rb
|
100
121
|
- lib/uncov/cli.rb
|
@@ -102,22 +123,18 @@ files:
|
|
102
123
|
- lib/uncov/configuration/option.rb
|
103
124
|
- lib/uncov/finder.rb
|
104
125
|
- lib/uncov/finder/file_system.rb
|
126
|
+
- lib/uncov/finder/files.rb
|
105
127
|
- lib/uncov/finder/git.rb
|
106
128
|
- lib/uncov/finder/git_base.rb
|
107
129
|
- lib/uncov/finder/git_diff.rb
|
108
|
-
- lib/uncov/finder/
|
109
|
-
- lib/uncov/finder/
|
130
|
+
- lib/uncov/finder/nocov.rb
|
131
|
+
- lib/uncov/finder/simplecov.rb
|
110
132
|
- lib/uncov/formatter.rb
|
111
|
-
- lib/uncov/formatter/terminal.rb
|
112
133
|
- lib/uncov/report.rb
|
113
134
|
- lib/uncov/report/context.rb
|
114
135
|
- lib/uncov/report/file.rb
|
115
136
|
- lib/uncov/report/file/line.rb
|
116
|
-
- lib/uncov/report/
|
117
|
-
- lib/uncov/report/generator/diff_files.rb
|
118
|
-
- lib/uncov/report/generator/diff_lines.rb
|
119
|
-
- lib/uncov/report/generator/git_files.rb
|
120
|
-
- lib/uncov/report/generator/nocov_lines.rb
|
137
|
+
- lib/uncov/report/filters.rb
|
121
138
|
- lib/uncov/struct.rb
|
122
139
|
- lib/uncov/version.rb
|
123
140
|
homepage: https://github.com/mpapis/uncov
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# report only files lines from the diff
|
4
|
-
module Uncov::Report::Generator::DiffFiles
|
5
|
-
Uncov::Report::Generator.register(self, :git_diff, 'Report missing coverage on added/changed files in the git diff')
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def files(finder)
|
9
|
-
finder.git_diff_file_names.map do |file_name|
|
10
|
-
Uncov::Report::File.new(
|
11
|
-
file_name:,
|
12
|
-
git: true,
|
13
|
-
lines: lines(finder, file_name)
|
14
|
-
)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def lines(finder, file_name)
|
21
|
-
lines_hash = file_lines(finder, file_name)
|
22
|
-
add_context(lines_hash)
|
23
|
-
lines_hash.sort.to_h.values
|
24
|
-
end
|
25
|
-
|
26
|
-
def file_lines(finder, file_name)
|
27
|
-
finder.file_system_file_lines(file_name).to_h do |line_number, content|
|
28
|
-
[line_number, new_line(finder, file_name, line_number, content)]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_context(lines_hash)
|
33
|
-
return if Uncov.configuration.context.zero?
|
34
|
-
|
35
|
-
line_numbers =
|
36
|
-
lines_hash.filter_map do |line_number, line|
|
37
|
-
line_number if line.trigger?
|
38
|
-
end
|
39
|
-
all_line_numbers = lines_hash.keys
|
40
|
-
context_line_numbers = Uncov::Report::Context.calculate(all_line_numbers, line_numbers, Uncov.configuration.context)
|
41
|
-
context_line_numbers.each do |line_number|
|
42
|
-
lines_hash[line_number].context = true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def new_line(finder, file_name, line_number, content)
|
47
|
-
Uncov::Report::File::Line.new(
|
48
|
-
number: line_number,
|
49
|
-
content:,
|
50
|
-
no_cov: finder.no_cov_file_line?(file_name, line_number),
|
51
|
-
simple_cov: finder.simple_cov_file_line?(file_name, line_number),
|
52
|
-
git_diff: finder.git_diff_file_line?(file_name, line_number),
|
53
|
-
context: false
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# report only files lines from the diff
|
4
|
-
module Uncov::Report::Generator::DiffLines
|
5
|
-
Uncov::Report::Generator.register(self, :git_diff, 'Report missing coverage on added lines in the git diff')
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def files(finder)
|
9
|
-
finder.git_diff_file_names.map do |file_name|
|
10
|
-
Uncov::Report::File.new(
|
11
|
-
file_name:,
|
12
|
-
git: true,
|
13
|
-
lines: lines(finder, file_name)
|
14
|
-
)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def lines(finder, file_name)
|
21
|
-
lines_hash = git_diff_files_lines(finder, file_name)
|
22
|
-
add_context(finder, file_name, lines_hash)
|
23
|
-
lines_hash.sort.to_h.values
|
24
|
-
end
|
25
|
-
|
26
|
-
def git_diff_files_lines(finder, file_name)
|
27
|
-
finder.git_diff_file_lines(file_name).keys.to_h do |line_number|
|
28
|
-
[line_number, new_line(finder, file_name, line_number)]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_context(finder, file_name, lines_hash)
|
33
|
-
return if Uncov.configuration.context.zero?
|
34
|
-
|
35
|
-
line_numbers =
|
36
|
-
lines_hash.filter_map do |line_number, line|
|
37
|
-
line_number if line.trigger?
|
38
|
-
end
|
39
|
-
all_line_numbers = finder.file_system_file_lines(file_name).keys
|
40
|
-
context_line_numbers = Uncov::Report::Context.calculate(all_line_numbers, line_numbers, Uncov.configuration.context)
|
41
|
-
context_line_numbers.each do |line_number|
|
42
|
-
context_line(finder, file_name, lines_hash, line_number)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def context_line(finder, file_name, lines_hash, line_number)
|
47
|
-
if lines_hash.key?(line_number)
|
48
|
-
lines_hash[line_number].context = true
|
49
|
-
else
|
50
|
-
lines_hash[line_number] = new_line(finder, file_name, line_number, context: true)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def new_line(finder, file_name, line_number, context: false)
|
55
|
-
Uncov::Report::File::Line.new(
|
56
|
-
number: line_number,
|
57
|
-
content: finder.file_system_file_line(file_name, line_number),
|
58
|
-
no_cov: finder.no_cov_file_line?(file_name, line_number),
|
59
|
-
simple_cov: finder.simple_cov_file_line?(file_name, line_number),
|
60
|
-
git_diff: finder.git_diff_file_line?(file_name, line_number),
|
61
|
-
context:
|
62
|
-
)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# report only files lines from the diff
|
4
|
-
module Uncov::Report::Generator::GitFiles
|
5
|
-
Uncov::Report::Generator.register(self, :git, 'Report missing coverage on files tracked with git')
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def files(finder)
|
9
|
-
finder.git_file_names.map do |file_name|
|
10
|
-
Uncov::Report::File.new(
|
11
|
-
file_name:,
|
12
|
-
git: true,
|
13
|
-
lines: lines(finder, file_name)
|
14
|
-
)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def lines(finder, file_name)
|
21
|
-
lines_hash = file_lines(finder, file_name)
|
22
|
-
add_context(lines_hash)
|
23
|
-
lines_hash.sort.to_h.values
|
24
|
-
end
|
25
|
-
|
26
|
-
def file_lines(finder, file_name)
|
27
|
-
finder.file_system_file_lines(file_name).to_h do |line_number, content|
|
28
|
-
[line_number, new_line(finder, file_name, line_number, content)]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_context(lines_hash)
|
33
|
-
return if Uncov.configuration.context.zero?
|
34
|
-
|
35
|
-
line_numbers =
|
36
|
-
lines_hash.filter_map do |line_number, line|
|
37
|
-
line_number if line.trigger?
|
38
|
-
end
|
39
|
-
all_line_numbers = lines_hash.keys
|
40
|
-
context_line_numbers = Uncov::Report::Context.calculate(all_line_numbers, line_numbers, Uncov.configuration.context)
|
41
|
-
context_line_numbers.each do |line_number|
|
42
|
-
lines_hash[line_number].context = true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def new_line(finder, file_name, line_number, content)
|
47
|
-
Uncov::Report::File::Line.new(
|
48
|
-
number: line_number,
|
49
|
-
content:,
|
50
|
-
no_cov: finder.no_cov_file_line?(file_name, line_number),
|
51
|
-
simple_cov: finder.simple_cov_file_line?(file_name, line_number),
|
52
|
-
git_diff: finder.git_diff_file_line?(file_name, line_number),
|
53
|
-
context: false
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# report only files lines from the diff
|
4
|
-
module Uncov::Report::Generator::NocovLines
|
5
|
-
Uncov::Report::Generator.register(self, :file_system, 'Report coverage on nocov lines, requires one or both: --nocov-ignore / --nocov-covered')
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def files(finder)
|
9
|
-
finder.no_cov_file_names.filter_map do |file_name|
|
10
|
-
next if finder.no_cov_file_lines(file_name).empty?
|
11
|
-
|
12
|
-
Uncov::Report::File.new(
|
13
|
-
file_name:,
|
14
|
-
git: finder.git_file?(file_name),
|
15
|
-
lines: lines(finder, file_name)
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def lines(finder, file_name)
|
23
|
-
lines_hash = nocov_files_lines(finder, file_name)
|
24
|
-
add_context(finder, file_name, lines_hash)
|
25
|
-
lines_hash.sort.to_h.values
|
26
|
-
end
|
27
|
-
|
28
|
-
def nocov_files_lines(finder, file_name)
|
29
|
-
finder.no_cov_file_lines(file_name).keys.to_h do |line_number|
|
30
|
-
[line_number, new_line(finder, file_name, line_number)]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def add_context(finder, file_name, lines_hash)
|
35
|
-
return if Uncov.configuration.context.zero?
|
36
|
-
|
37
|
-
line_numbers =
|
38
|
-
lines_hash.filter_map do |line_number, line|
|
39
|
-
line_number if line.trigger?
|
40
|
-
end
|
41
|
-
all_line_numbers = finder.file_system_file_lines(file_name).keys
|
42
|
-
context_line_numbers = Uncov::Report::Context.calculate(all_line_numbers, line_numbers, Uncov.configuration.context)
|
43
|
-
context_line_numbers.each do |line_number|
|
44
|
-
context_line(finder, file_name, lines_hash, line_number)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def context_line(finder, file_name, lines_hash, line_number)
|
49
|
-
if lines_hash.key?(line_number)
|
50
|
-
lines_hash[line_number].context = true
|
51
|
-
else
|
52
|
-
lines_hash[line_number] = new_line(finder, file_name, line_number, context: true)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def new_line(finder, file_name, line_number, context: false)
|
57
|
-
Uncov::Report::File::Line.new(
|
58
|
-
number: line_number,
|
59
|
-
content: finder.file_system_file_line(file_name, line_number),
|
60
|
-
no_cov: finder.no_cov_file_line?(file_name, line_number),
|
61
|
-
simple_cov: finder.simple_cov_file_line?(file_name, line_number),
|
62
|
-
git_diff: finder.git_diff_file_line?(file_name, line_number),
|
63
|
-
context:
|
64
|
-
)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../report'
|
4
|
-
|
5
|
-
# generate report files and lines for the configured report type
|
6
|
-
module Uncov::Report::Generator
|
7
|
-
class << self
|
8
|
-
def filters
|
9
|
-
@filters ||= {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def register(generator_class, simple_cov_trigger, description)
|
13
|
-
class_name = generator_class.to_s.split('::').last
|
14
|
-
generator_name = class_name.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
|
15
|
-
filters[generator_name] = { generator_class:, simple_cov_trigger:, description: }
|
16
|
-
end
|
17
|
-
|
18
|
-
def generate
|
19
|
-
raise Uncov::UnsupportedReportTypeError, Uncov.configuration.report unless filters.key?(Uncov.configuration.report)
|
20
|
-
|
21
|
-
filters[Uncov.configuration.report] => { generator_class:, simple_cov_trigger: }
|
22
|
-
generator_class.files(Uncov::Finder.new(simple_cov_trigger))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|