deep-cover 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3b9feb6fdad25312b0111faf653599e6019c51ddbcd31446ec2c45d7c5403f3
4
- data.tar.gz: 18c532649cdc00a98690fc3d66ced732e11b1c97a2787ab36d0d5e3151e20601
3
+ metadata.gz: b07ad13bcfdc6616d61b1a80bd632d8b41e105a942b91e526b6a794a7b0315ba
4
+ data.tar.gz: 12c59e6a8ae6e161e1bf93306cebae6f0281204d3dc41241f6dc20f025102eb3
5
5
  SHA512:
6
- metadata.gz: 1b68e3fc7a62f263f1971b7b50b753d5ca5472bee6231eba897771ff1e036efcc6f8cc5625b1e5b6ef3422a978f1e2876ba7b6f8488d176705e0b8f465d9786d
7
- data.tar.gz: 9fcf65daa4618b3c9d056ed95fe1a3f7e9ae1e4d67768940989630fa9c1a45ff05c7504bffae5058e0597fea8f661e730d59fa0ec089446d2ad28ec5f4ab963c
6
+ metadata.gz: 1421c160b9eb370663025c4704ab69fb061686301d694d65554fd3cd8a10211e1376ca072a7744e3f1568bd93e851d2889ad4f1c09b8d86f0a19fe08d59b04c9
7
+ data.tar.gz: 0b3a75ff09297e170ffe800bcbe6fb4a0ad22e1bac1ca91d4b0d10fb8e79f96030e117845953c25f0a182708e1aace7e67ca7b97efccafbeb830d4a353df139c
@@ -3,22 +3,39 @@
3
3
  module DeepCover
4
4
  class Analyser::PerLine < Analyser
5
5
  # Returns an array of runs, one per line.
6
+ # allow_partial can be one of:
7
+ # true: Allow any partial covering. Basically ruby's line coverage,
8
+ # if any thing is executed, it is considered executed
9
+ # branch: Only allow branches to be partially covered.
10
+ # if a node is not executed, the line has to be marked as not executed, even if part of it was.
11
+ # false: Allow nothing to be partially covered.
12
+ # same as :branch, but also:
13
+ # if an empty branch is not executed, the line has to be marked as not executed.
14
+ # This is only for empty branches because, if they are not empty, there will already
15
+ # be some red from the partial node covering. We don't everything to become red,
16
+ # just want 100% coverage to be as hard as branch + node coverage.
6
17
  def results
7
- disallow_partial = !options.fetch(:allow_partial, true)
18
+ allow_partial = options.fetch(:allow_partial, true)
8
19
  line_hits = Array.new(covered_code.nb_lines + covered_code.lineno - 1)
20
+ disallowed_lines = Set.new
9
21
  each_node do |node|
10
22
  next unless (runs = node_runs(node))
11
23
  node.executed_locs.each do |loc|
12
- lineno = loc.line - 1
13
- if disallow_partial
14
- line_hits[lineno] = 0 if runs == 0
15
- next if line_hits[lineno] == 0
16
- end
17
- line_hits[lineno] = [line_hits[lineno] || 0, runs].max
24
+ line_index = loc.line - 1
25
+
26
+ next if disallowed_lines.include?(line_index)
27
+ disallowed_lines << line_index if [nil, false, :branch].include?(allow_partial) && runs == 0
28
+ disallowed_lines << line_index if !allow_partial && missed_empty_branch?(node)
29
+
30
+ line_hits[line_index] = [line_hits[line_index] || 0, runs].max
18
31
  end
19
32
  end
20
-
33
+ disallowed_lines.each { |line_index| line_hits[line_index] = 0 }
21
34
  line_hits
22
35
  end
36
+
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)) }
39
+ end
23
40
  end
24
41
  end
@@ -85,10 +85,12 @@ module DeepCover
85
85
  end
86
86
 
87
87
  def handle_csend
88
- cond_info = [:"&.", *node_loc_infos]
88
+ # csend wraps the comment but not the newlines
89
+ node_range = node.expression.wrap_rwhitespace_and_comments(whitespaces: /\A[ \t\r\f]+/)
90
+ cond_info = [:"&.", *node_loc_infos(node_range)]
89
91
  false_branch, true_branch = branches
90
- [cond_info, {[:then, *node_loc_infos] => true_branch.execution_count,
91
- [:else, *node_loc_infos] => false_branch.execution_count,
92
+ [cond_info, {[:then, *node_loc_infos(node_range)] => true_branch.execution_count,
93
+ [:else, *node_loc_infos(node_range)] => false_branch.execution_count,
92
94
  },
93
95
  ]
94
96
  end
@@ -13,14 +13,16 @@ module DeepCover
13
13
  # and that is not available in JRuby. An extension may be able to replace this requirement.
14
14
  # require_relative 'core_ext/autoload_overrides'
15
15
  # AutoloadOverride.active = true
16
+ require_relative 'core_ext/load_overrides'
16
17
  require_relative 'core_ext/require_overrides'
17
- RequireOverride.active = true
18
+ LoadOverride.active = RequireOverride.active = true
18
19
  elsif RUBY_VERSION >= '2.3.0'
19
20
  require_relative 'core_ext/instruction_sequence_load_iseq'
20
21
  else
21
22
  require_relative 'core_ext/autoload_overrides'
23
+ require_relative 'core_ext/load_overrides'
22
24
  require_relative 'core_ext/require_overrides'
23
- AutoloadOverride.active = RequireOverride.active = true
25
+ AutoloadOverride.active = LoadOverride.active = RequireOverride.active = true
24
26
  autoload_tracker.initialize_autoloaded_paths { |mod, name, path| mod.autoload_without_deep_cover(name, path) }
25
27
  end
26
28
 
@@ -97,21 +97,23 @@ module DeepCover
97
97
  true
98
98
  end
99
99
 
100
- ### Not currently used ###
101
100
  # Homemade #load to be able to instrument the code before it gets executed.
102
101
  # Note, this doesn't support the `wrap` parameter that ruby's #load has.
103
- # Same return/throw as CustomRequirer#require, except:
104
- # Cannot return false since #load doesn't care about a file already being executed.
102
+ # Same yield/return behavior as CustomRequirer#require, except that it
103
+ # cannot return false #load doesn't care about a file already being executed.
105
104
  def load(path) # &fallback_block
105
+ path = path.to_s
106
+
106
107
  found_path = resolve_path(path, nil)
107
108
 
108
109
  if found_path.nil?
109
- # #load has a final fallback of always trying relative to current work directory of process
110
+ # #load has a final fallback of always trying relative to current work directory
110
111
  possible_path = File.absolute_path(path)
111
112
  found_path = possible_path if File.exist?(possible_path)
112
113
  end
113
114
 
114
115
  return yield(:not_found) unless found_path
116
+ return yield(:not_in_covered_paths) unless DeepCover.within_lookup_paths?(found_path)
115
117
 
116
118
  cover_and_execute(found_path) { |reason| return yield(reason) }
117
119
 
@@ -5,16 +5,16 @@ class Parser::Source::Range
5
5
  adjust(begin_pos: +1, end_pos: +1)
6
6
  end
7
7
 
8
- def wrap_rwhitespace
9
- whitespace = @source_buffer.slice(end_pos..-1)[/\A\s+/] || ''
8
+ def wrap_rwhitespace(whitespaces: /\A\s+/)
9
+ whitespace = @source_buffer.slice(end_pos..-1)[whitespaces] || ''
10
10
  adjust(end_pos: whitespace.size)
11
11
  end
12
12
 
13
- def wrap_rwhitespace_and_comments
14
- current = wrap_rwhitespace
13
+ def wrap_rwhitespace_and_comments(whitespaces: /\A\s+/)
14
+ current = wrap_rwhitespace(whitespaces: whitespaces)
15
15
  while @source_buffer.slice(current.end_pos) == '#'
16
16
  comment = @source_buffer.slice(current.end_pos..-1)[/\A[^\n]+/] || ''
17
- current = current.adjust(end_pos: comment.size).wrap_rwhitespace
17
+ current = current.adjust(end_pos: comment.size).wrap_rwhitespace(whitespaces: whitespaces)
18
18
  end
19
19
  current
20
20
  end
@@ -6,10 +6,14 @@ module DeepCover
6
6
  require 'coverage'
7
7
  filename = File.absolute_path(File.expand_path(filename))
8
8
  ::Coverage.start
9
- Tools.silence_warnings do
10
- execute_sample -> { run_with_line_coverage(source, filename, lineno) }
9
+ begin
10
+ Tools.silence_warnings do
11
+ execute_sample -> { run_with_line_coverage(source, filename, lineno) }
12
+ end
13
+ ensure
14
+ result = ::Coverage.result
11
15
  end
12
- unshift_coverage(::Coverage.result.fetch(filename), lineno)
16
+ unshift_coverage(result.fetch(filename), lineno)
13
17
  end
14
18
 
15
19
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeepCover
4
+ module Tools::RequireRelativeDir
5
+ # Like String#scan, but return the MatchData object instead
6
+ def scan_match_datas(source, matcher)
7
+ source.to_enum(:scan, matcher).map { Regexp.last_match }
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepCover
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep-cover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Lafortune
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-06-02 00:00:00.000000000 Z
12
+ date: 2018-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parser
@@ -383,6 +383,7 @@ files:
383
383
  - lib/deep_cover/tools/profiling.rb
384
384
  - lib/deep_cover/tools/render_template.rb
385
385
  - lib/deep_cover/tools/require_relative_dir.rb
386
+ - lib/deep_cover/tools/scan_match_datas.rb
386
387
  - lib/deep_cover/tools/silence_warnings.rb
387
388
  - lib/deep_cover/tools/slice.rb
388
389
  - lib/deep_cover/tools/strip_heredoc.rb