Class: Testprune::SemanticIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/testprune/footprint.rb

Overview

Turns recorded per-test coverage (run.json) into Footprints by mapping Coverage locations onto Prism semantic units. Caches one SemanticMap per file.

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ SemanticIndex

Returns a new instance of SemanticIndex.



18
19
20
21
# File 'lib/testprune/footprint.rb', line 18

def initialize(root)
  @root = root
  @maps = {}
end

Instance Method Details

#build_footprints(tests) ⇒ Object



23
24
25
# File 'lib/testprune/footprint.rb', line 23

def build_footprints(tests)
  tests.map { |test| footprint(test) }
end

#footprint(test) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/testprune/footprint.rb', line 27

def footprint(test)
  units = Set.new
  (test['coverage'] || {}).each do |file, data|
    next unless File.exist?(file)

    map = map_for(file)
    collect_methods(units, map, data['methods'])
    collect_branches(units, map, data['branches'])
    collect_lines(units, map, data['lines'])
  end

  Footprint.new(
    id: test['id'], description: test['description'], file: test['file'],
    line: test['line'], wall_time: test['wall_time'] || 0.0, units: units
  )
end

#label_for(id) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/testprune/footprint.rb', line 44

def label_for(id)
  @maps.each_value do |map|
    unit = map.units[id]
    return unit.label if unit
  end
  id
end