Class: Necropsy::Analyzers::Dynamic::CoverageImporter

Inherits:
Necropsy::Analyzer show all
Defined in:
lib/necropsy/analyzers/dynamic/coverage_importer.rb

Direct Known Subclasses

TracePointImporter

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CoverageImporter

Returns a new instance of CoverageImporter.



10
11
12
# File 'lib/necropsy/analyzers/dynamic/coverage_importer.rb', line 10

def initialize(config)
  @config = config || {}
end

Instance Method Details

#analyze(_graph, project) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/necropsy/analyzers/dynamic/coverage_importer.rb', line 14

def analyze(_graph, project)
  source = config['source']
  return AnalyzerResult.empty unless source

  payload = load_payload(File.expand_path(source, project.root))
  alive = Array(payload['executed'] || payload['nodes']).map do |node_id|
    AliveEvidence.new(
      node_id: node_id,
      evidence: evidence(kind: :alive, details: "Coverage marked #{node_id} as executed",
                         metadata: payload['observation'] || {})
    )
  end

  edge_evidences = Array(payload['edges']).map do |edge|
    caller_id = edge['caller_id'] || edge[:caller_id]
    callee_id = edge['callee_id'] || edge[:callee_id]
    EdgeEvidence.new(
      caller_id: caller_id,
      callee_id: callee_id,
      evidence: evidence(kind: :call_edge, details: "Coverage observed #{caller_id} -> #{callee_id}")
    )
  end

  AnalyzerResult.new(
    edge_evidences: edge_evidences,
    alive_evidences: alive,
    uncertainties: {},
    observation: { 'coverage' => payload['observation'] || {} }
  )
end

#profileObject



45
46
47
48
49
50
51
52
# File 'lib/necropsy/analyzers/dynamic/coverage_importer.rb', line 45

def profile
  AnalyzerProfile.new(
    name: :coverage,
    kind: :dynamic,
    soundness: :observational,
    description: 'Imports method execution and observed edges from Ruby Coverage output.'
  )
end