Class: Evilution::Coverage::Map Private

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/coverage/map.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Immutable query over a per-example line-coverage index:

source file -> line -> [example locations ("spec.rb:line")].

built_files records the source files for which the build completed, so callers can distinguish "line genuinely uncovered" (file built, no entry) from "we never built this file" (must fall back, not assert a gap).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index:, built_files:, executed_lines: {}) ⇒ Map

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

executed_lines records, per file, the lines that ran at all during the build (including lines covered only at load, e.g. a def line, which are attributed to no single example). It lets a caller tell a TRUE coverage gap (line never executed) from a load-covered line an example may still exercise indirectly -- so the latter falls back instead of being mis-skipped.



24
25
26
27
28
29
# File 'lib/evilution/coverage/map.rb', line 24

def initialize(index:, built_files:, executed_lines: {})
  @index = deep_freeze_index(index)
  @built_files = built_files.to_a.freeze
  @executed_lines = deep_freeze_executed(executed_lines)
  freeze
end

Class Method Details

.from_h(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
# File 'lib/evilution/coverage/map.rb', line 11

def self.from_h(hash)
  index = (hash["index"] || {}).transform_values do |lines|
    lines.transform_keys(&:to_i)
  end
  executed = (hash["executed_lines"] || {}).transform_values { |lines| lines.map(&:to_i) }
  new(index: index, built_files: hash["built_files"] || [], executed_lines: executed)
end

Instance Method Details

#built?(file) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
# File 'lib/evilution/coverage/map.rb', line 35

def built?(file)
  @built_files.include?(file)
end

#examples_for(file, line) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
# File 'lib/evilution/coverage/map.rb', line 31

def examples_for(file, line)
  @index.dig(file, line) || []
end

#executed?(file, line) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/evilution/coverage/map.rb', line 39

def executed?(file, line)
  lines = @executed_lines[file]
  !lines.nil? && lines.include?(line)
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'lib/evilution/coverage/map.rb', line 44

def to_h
  { "index" => @index, "built_files" => @built_files, "executed_lines" => @executed_lines }
end