deep-cover-core 0.7.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbe41efeca9abba7b516658844fb4517fdc0a2c06ca55f4001e2226ba0f896d2
4
- data.tar.gz: 0caf291ac3b17a9331f81a8834b3e62c383ba2df48ae7593461e366220a8d1db
3
+ metadata.gz: 7e54c0b378f86ce59192fb96bf48ab337224c393b0fd8001aca282e0cd6089b4
4
+ data.tar.gz: 0b2e4d4be1a54115f0246faf36aa3de60c9f223f615bf6346e183f502308dd80
5
5
  SHA512:
6
- metadata.gz: dc9f2a11db1a305236bc244ef66178bed2763b2e3608872412719560576fd8c9db680ce4a58c37f9bc49c82a003777bce3c534df7fc7a845bfaa604814f2c81a
7
- data.tar.gz: f1ad943d6d731465e73dbca9964fe253723c684e4905e2434f122f53c402b384f47b4e48f63fa503bfa24626ddc142e49926e1866f7eab593d9dc852b00e0d97
6
+ metadata.gz: ec49f79fe4432b3bf3f70567561226c9834b7f456afe03f820a4ee1c25b52f770c8303e5869be09f55db8ab3361a44c25aa1facb6881a67d1276992d695c83e2
7
+ data.tar.gz: ef087d944754939b47106482ef6a9813783f5fb8f55608a45e27533fc2263fa9a965555f01f85618e7e41d8981c676515339f81300733e911b3adbee57851066
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.required_ruby_version = '>= 2.1.0'
25
25
 
26
26
  # Main dependency
27
- spec.add_runtime_dependency 'parser', '>= 2.5', '< 2.7'
27
+ spec.add_runtime_dependency 'parser', '>= 2.5'
28
28
 
29
29
  # Support
30
30
  spec.add_runtime_dependency 'backports', '>= 3.11.0'
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
45
45
  # About every single release breaks something
46
46
  # Ruby 2.1 is no longer supported
47
47
  if RUBY_VERSION >= '2.3.0'
48
- spec.add_development_dependency 'rubocop', '~> 0.74.0'
48
+ spec.add_development_dependency 'rubocop', '~> 0.81.0'
49
49
  spec.add_development_dependency 'rubocop-performance'
50
50
  end
51
51
  end
@@ -35,7 +35,7 @@ module DeepCover
35
35
  end
36
36
 
37
37
  def missed_empty_branch?(node)
38
- node.is_a?(Node::Branch) && node.branches.any? { |b| b.is_a?(Node::EmptyBody) && !Tools.covered?(node_runs(b)) }
38
+ node.is_a?(Node::Branch) && node.branches.any? { |b| b.is_a?(Node::EmptyBody) && node_runs(b) == 0 }
39
39
  end
40
40
  end
41
41
  end
@@ -48,7 +48,7 @@ module DeepCover
48
48
  memoize :percent
49
49
 
50
50
  def percent
51
- Analyser::StatsBase.new(to_h.transform_values { |v| (100 * v).fdiv(total).round(DECIMALS) })
51
+ Analyser::StatsBase.new(**to_h.transform_values { |v| (100 * v).fdiv(total).round(DECIMALS) })
52
52
  end
53
53
  end
54
54
  end
@@ -17,6 +17,7 @@ require 'backports/2.4.0/false_class/dup'
17
17
  require 'backports/2.4.0/true_class/dup'
18
18
  require 'backports/2.4.0/hash/transform_values'
19
19
  require 'backports/2.4.0/enumerable/sum'
20
+ require 'backports/2.4.0/regexp/match'
20
21
  require 'backports/2.5.0/hash/slice'
21
22
  require 'backports/2.5.0/hash/transform_keys'
22
23
  require 'backports/2.5.0/kernel/yield_self'
@@ -38,7 +38,9 @@ module DeepCover
38
38
  end
39
39
 
40
40
  def line_coverage(filename)
41
- coverage.line_coverage(handle_relative_filename(filename), **config.to_h)
41
+ filename = handle_relative_filename(filename)
42
+ return unless coverage.covered_code?(filename)
43
+ coverage.line_coverage(filename, **config.to_h)
42
44
  end
43
45
 
44
46
  def covered_code(filename)
@@ -62,6 +64,9 @@ module DeepCover
62
64
  when :paths
63
65
  warn "Changing DeepCover's paths after starting coverage is highly discouraged" if running?
64
66
  @lookup_globs = @all_tracked_file_paths = nil
67
+ when :excluded_paths
68
+ warn "Changing DeepCover's excluded_paths after starting coverage is highly discouraged" if running?
69
+ @all_tracked_file_paths = nil
65
70
  when :tracker_global
66
71
  raise NotImplementedError, "Changing DeepCover's tracker global after starting coverage is not supported" if running?
67
72
  @coverage = nil
@@ -79,8 +84,13 @@ module DeepCover
79
84
  @coverage ||= Coverage.new
80
85
  end
81
86
 
87
+ def lookup_exclusion
88
+ @lookup_exclusion ||= Regexp.union(*
89
+ config.exclude_paths.map { |x| Tools.to_regexp(x) })
90
+ end
91
+
82
92
  def lookup_globs
83
- return @lookup_globs if @lookup_globs
93
+ return @lookup_globs if defined?(@lookup_globs) && @lookup_globs
84
94
  paths = Array(config.paths || :auto_detect).dup
85
95
  paths.concat(auto_detected_paths) if paths.delete(:auto_detect)
86
96
 
@@ -143,6 +153,7 @@ module DeepCover
143
153
  end
144
154
 
145
155
  def tracked_file_path?(path)
156
+ return false if lookup_exclusion.match?(path)
146
157
  # The flags are to make fnmatch match the same things as Dir.glob... This doesn't seem to be documented anywhere
147
158
  # EXTGLOB: allow matching {lib,app} as either lib or app
148
159
  # PATHNAME: Makes wildcard match not match /, and make /**/ (and pattern starting with **/) be any number of nested directory
@@ -155,6 +166,7 @@ module DeepCover
155
166
  paths_found.select! { |path| path.end_with?('.rb') }
156
167
  paths_found.select! { |path| File.file?(path) }
157
168
  paths_found.uniq!
169
+ paths_found.reject! { |path| lookup_exclusion.match?(path) }
158
170
  @all_tracked_file_paths = paths_found
159
171
  @all_tracked_file_paths.dup
160
172
  end
@@ -178,7 +190,7 @@ module DeepCover
178
190
  relative_to = File.dirname(caller(2..2).first.partition(/\.rb:\d/).first)
179
191
  filename = File.absolute_path(filename, relative_to)
180
192
  end
181
- filename += '.rb' unless filename =~ /\.rb$/
193
+ filename += '.rb' unless filename.end_with? 'rb'
182
194
  filename
183
195
  end
184
196
  end
@@ -10,6 +10,7 @@ module DeepCover
10
10
 
11
11
  DEFAULTS = {
12
12
  paths: [:auto_detect].freeze,
13
+ exclude_paths: [].freeze,
13
14
  allow_partial: false,
14
15
  tracker_global: '$_cov',
15
16
  reporter: :html,
@@ -20,7 +20,7 @@ module DeepCover
20
20
  hash = to_hash
21
21
  # TODO: (Max) I don't like mixup of configs being partly on DeepCover and Config like that...
22
22
  hash[:paths] = DeepCover.lookup_globs
23
- hash[:output] = hash[:output] ? File.expand_path(hash[:output]) : hash[:output]
23
+ hash[:output] &&= File.expand_path(hash[:output])
24
24
  hash[:cache_directory] = File.expand_path(hash[:cache_directory])
25
25
  hash
26
26
  end
@@ -42,7 +42,7 @@ module DeepCover
42
42
  end
43
43
  unless keywords.empty?
44
44
  keywords = check_uncovered(keywords)
45
- set(keywords.to_h { |kind| [FILTER_NAME[kind], true] })
45
+ set(**keywords.to_h { |kind| [FILTER_NAME[kind], true] })
46
46
  end
47
47
  Config.options_to_ignored(**@options)
48
48
  end
@@ -51,7 +51,7 @@ module DeepCover
51
51
  raise ArgumentError, 'No block is accepted' if block_given?
52
52
  unless keywords.empty?
53
53
  keywords = check_uncovered(keywords)
54
- set(keywords.to_h { |kind| [FILTER_NAME[kind], false] })
54
+ set(**keywords.to_h { |kind| [FILTER_NAME[kind], false] })
55
55
  end
56
56
  OPTIONALLY_COVERED - Config.options_to_ignored(**@options)
57
57
  end
@@ -65,13 +65,18 @@ module DeepCover
65
65
  end
66
66
  end
67
67
 
68
- %i[paths tracker_global reporter output cache_directory allow_partial]
68
+ %i[paths exclude_paths tracker_global reporter output cache_directory allow_partial]
69
69
  .concat(OPTIONALLY_COVERED.map { |filter| FILTER_NAME[filter] })
70
70
  .each { |attr| define_accessor(attr) }
71
71
  end
72
72
 
73
73
  include AttributeAccessors
74
74
 
75
+ def exclude_paths(paths = NOT_SPECIFIED)
76
+ paths = Array(paths).dup unless paths == NOT_SPECIFIED
77
+ super
78
+ end
79
+
75
80
  def paths(paths = NOT_SPECIFIED)
76
81
  paths = Array(paths).dup unless paths == NOT_SPECIFIED
77
82
  super
@@ -3,12 +3,12 @@
3
3
  module DeepCover
4
4
  bootstrap
5
5
 
6
- require_relative_dir 'coverage'
7
-
8
6
  # A collection of CoveredCode
9
7
  class Coverage
10
8
  include Enumerable
11
9
 
10
+ DeepCover.require_relative_dir 'coverage'
11
+
12
12
  def initialize
13
13
  @covered_code_per_path = {}
14
14
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DeepCover
4
4
  class Coverage
5
- class Analysis < Struct.new(:covered_codes, :options)
5
+ class Analysis < StructWithOptions.new(:covered_codes)
6
6
  include Memoize
7
7
  memoize :analyser_map, :stat_map
8
8
 
@@ -13,6 +13,7 @@ module DeepCover
13
13
  def executed_loc_keys(*loc_keys)
14
14
  # #flatten allows passing an empty array to be explicit
15
15
  loc_keys = loc_keys.flatten
16
+ undef_method :executed_loc_keys
16
17
  define_method :executed_loc_keys do
17
18
  loc_keys
18
19
  end
@@ -31,10 +31,7 @@ module top_level_module::DeepCover # rubocop:disable Naming/ClassAndModuleCamelC
31
31
  # returns a TrackerHitsPerPath
32
32
  def load_trackers
33
33
  tracker_hits_per_path_hashes = tracker_files.map do |full_path|
34
- JSON.parse(full_path.binread).transform_keys(&:to_sym).yield_self do |version:, tracker_hits_per_path:|
35
- raise "dump version mismatch: #{version}, currently #{VERSION}" unless version == VERSION
36
- tracker_hits_per_path
37
- end
34
+ check_tracker_file(**JSON.parse(full_path.binread).transform_keys(&:to_sym))
38
35
  end
39
36
 
40
37
  self.class.merge_tracker_hits_per_paths(*tracker_hits_per_path_hashes)
@@ -56,7 +53,7 @@ module top_level_module::DeepCover # rubocop:disable Naming/ClassAndModuleCamelC
56
53
  delete_trackers
57
54
  begin
58
55
  dir_path.rmdir
59
- rescue SystemCallError # rubocop:disable Lint/HandleExceptions
56
+ rescue SystemCallError # rubocop:disable Lint/SuppressedException
60
57
  end
61
58
  end
62
59
 
@@ -88,6 +85,11 @@ module top_level_module::DeepCover # rubocop:disable Naming/ClassAndModuleCamelC
88
85
 
89
86
  private
90
87
 
88
+ def check_tracker_file(version:, tracker_hits_per_path:)
89
+ raise "dump version mismatch: #{version}, currently #{VERSION}" unless version == VERSION
90
+ tracker_hits_per_path
91
+ end
92
+
91
93
  def create_directory_if_needed
92
94
  dir_path.mkpath
93
95
  end
@@ -68,7 +68,7 @@ module DeepCover
68
68
  end
69
69
  end
70
70
 
71
- class CoveredCodeConverter < Struct.new(:covered_code, :options)
71
+ class CoveredCodeConverter < StructWithOptions.new(:covered_code)
72
72
  include Converters
73
73
 
74
74
  def node_analyser
@@ -172,7 +172,7 @@ module DeepCover
172
172
 
173
173
  class << self
174
174
  def report(coverage, **options)
175
- new(coverage, options).report
175
+ new(coverage, **options).report
176
176
  end
177
177
 
178
178
  def available?
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepCover
4
+ module StructWithOptions
5
+ module Initializer
6
+ def initialize(*args, **options)
7
+ super(*args, options)
8
+ end
9
+ end
10
+
11
+ def self.new(*args)
12
+ Struct.new(*args, :options).tap do |klass|
13
+ klass.include Initializer
14
+ class << klass
15
+ undef_method :new
16
+ end
17
+ klass.define_singleton_method(:new, Class.method(:new))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepCover
4
+ module Tools::ToRegexp
5
+ def to_regexp(regexp_or_str)
6
+ case regexp_or_str
7
+ when Regexp
8
+ regexp_or_str
9
+ when String
10
+ Regexp.new(Regexp.quote(regexp_or_str))
11
+ else
12
+ raise TypeError
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,5 +3,5 @@
3
3
  top_level_module = Thread.current['_deep_cover_top_level_module'] || Object
4
4
 
5
5
  module top_level_module::DeepCover # rubocop:disable Naming/ClassAndModuleCamelCase
6
- VERSION = '0.7.9'
6
+ VERSION = '1.1.0'
7
7
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep-cover-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Lafortune
8
8
  - Maxime Lapointe
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-04-12 00:00:00.000000000 Z
12
+ date: 2021-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parser
@@ -18,9 +18,6 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '2.5'
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '2.7'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,9 +25,6 @@ dependencies:
28
25
  - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: '2.5'
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '2.7'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: backports
36
30
  requirement: !ruby/object:Gem::Requirement
@@ -149,14 +143,14 @@ dependencies:
149
143
  requirements:
150
144
  - - "~>"
151
145
  - !ruby/object:Gem::Version
152
- version: 0.74.0
146
+ version: 0.81.0
153
147
  type: :development
154
148
  prerelease: false
155
149
  version_requirements: !ruby/object:Gem::Requirement
156
150
  requirements:
157
151
  - - "~>"
158
152
  - !ruby/object:Gem::Version
159
- version: 0.74.0
153
+ version: 0.81.0
160
154
  - !ruby/object:Gem::Dependency
161
155
  name: rubocop-performance
162
156
  requirement: !ruby/object:Gem::Requirement
@@ -309,6 +303,8 @@ files:
309
303
  - lib/deep_cover/tools/silence_warnings.rb
310
304
  - lib/deep_cover/tools/slice.rb
311
305
  - lib/deep_cover/tools/strip_heredoc.rb
306
+ - lib/deep_cover/tools/struct_with_options.rb
307
+ - lib/deep_cover/tools/to_regexp.rb
312
308
  - lib/deep_cover/tools/truncate_backtrace.rb
313
309
  - lib/deep_cover/tools/with_unbundled_env.rb
314
310
  - lib/deep_cover/version.rb
@@ -316,7 +312,7 @@ homepage: https://github.com/deep-cover/deep-cover
316
312
  licenses:
317
313
  - MIT
318
314
  metadata: {}
319
- post_install_message:
315
+ post_install_message:
320
316
  rdoc_options: []
321
317
  require_paths:
322
318
  - lib
@@ -331,8 +327,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
331
327
  - !ruby/object:Gem::Version
332
328
  version: '0'
333
329
  requirements: []
334
- rubygems_version: 3.1.2
335
- signing_key:
330
+ rubygems_version: 3.1.4
331
+ signing_key:
336
332
  specification_version: 4
337
333
  summary: In depth coverage of your Ruby code.
338
334
  test_files: []