Class: DeepCover::Analyser::PerLine
- Inherits:
-
DeepCover::Analyser
- Object
- DeepCover::Analyser
- DeepCover::Analyser::PerLine
- Defined in:
- lib/deep_cover/analyser/per_line.rb
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
- #missed_empty_branch?(node) ⇒ Boolean
-
#results ⇒ Object
Returns an array of runs, one per line.
Methods included from Base
#covered_code, #each_node, #initialize, #node_children, #node_covered?, #node_runs, #node_runs_map, #node_stat_contributions, #node_stat_type, #stats
Methods included from Tools::Covered
Instance Method Details
#missed_empty_branch?(node) ⇒ Boolean
37 38 39 |
# File 'lib/deep_cover/analyser/per_line.rb', line 37 def missed_empty_branch?(node) node.is_a?(Node::Branch) && node.branches.any? { |b| b.is_a?(Node::EmptyBody) && !Tools.covered?(node_runs(b)) } end |
#results ⇒ Object
Returns an array of runs, one per line. allow_partial can be one of:
true: Allow any partial covering. Basically ruby's line coverage,
if any thing is executed, it is considered executed
branch: Only allow branches to be partially covered.
if a node is not executed, the line has to be marked as not executed, even if part of it was.
false: Allow nothing to be partially covered.
same as :branch, but also:
if an empty branch is not executed, the line has to be marked as not executed.
This is only for empty branches because, if they are not empty, there will already
be some red from the partial node covering. We don't everything to become red,
just want 100% coverage to be as hard as branch + node coverage.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deep_cover/analyser/per_line.rb', line 17 def results allow_partial = .fetch(:allow_partial, true) line_hits = Array.new(covered_code.nb_lines + covered_code.lineno - 1) disallowed_lines = Set.new each_node do |node| next unless (runs = node_runs(node)) node.executed_locs.each do |loc| line_index = loc.line - 1 next if disallowed_lines.include?(line_index) disallowed_lines << line_index if [nil, false, :branch].include?(allow_partial) && runs == 0 disallowed_lines << line_index if !allow_partial && missed_empty_branch?(node) line_hits[line_index] = [line_hits[line_index] || 0, runs].max end end disallowed_lines.each { |line_index| line_hits[line_index] = 0 } line_hits end |