Class: SimpleCov::TestTracker::Delta

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/test_tracker/delta.rb

Overview

The peek-diff arithmetic behind the tracker: which in-root lines grew between two coverage snapshots. This is the part a native Coverage.supported?(:contexts) engine would replace outright.

Instance Method Summary collapse

Constructor Details

#initialize(root_regex:) ⇒ Delta

Returns a new instance of Delta.



9
10
11
12
# File 'lib/simplecov/test_tracker/delta.rb', line 9

def initialize(root_regex:)
  @root_regex = root_regex
  @in_root = {} #: Hash[String, bool]
end

Instance Method Details

#call(before, after) ⇒ Object

Files outside the root are skipped; a file absent from before was loaded by the test itself, so everything it executed is the test's. The root match is memoized, so the regex runs once per file the process ever loads rather than once per file per test.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simplecov/test_tracker/delta.rb', line 18

def call(before, after)
  changed = {} #: Hash[String, Integer]
  after.each do |path, file_coverage|
    in_root = @in_root.fetch(path) { @in_root[path] = @root_regex.match?(path) }
    next unless in_root

    bitmap = line_delta(lines_in(before[path]), lines_in(file_coverage))
    changed[path] = bitmap unless bitmap.zero?
  end
  changed
end