Class: Testprune::Analysis

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

Overview

Loads run.json, builds semantic footprints, runs detection + safety, and bundles everything the report and patch writer need.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Analysis

Returns a new instance of Analysis.



21
22
23
# File 'lib/testprune/analysis.rb', line 21

def initialize(config)
  @config = config
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/testprune/analysis.rb', line 25

def call
  unless File.directory?(@config.root)
    raise Error, "root directory #{@config.root.inspect} does not exist. " \
                 "Check TESTPRUNE_ROOT or --root."
  end

  unless File.exist?(@config.run_file)
    raise Error, "no captured data at #{@config.run_file}. Run `testprune run` first."
  end

  run = begin
    JSON.parse(File.read(@config.run_file))
  rescue JSON::ParserError => e
    raise Error, "run.json is not valid JSON (#{e.message}) — it may be truncated. " \
                 "Re-run 'testprune run'."
  end
  index = SemanticIndex.new(run['root'] || @config.root)
  footprints = index.build_footprints(run['tests'] || [])
  detector = DuplicationDetector.new(
    footprints,
    overlap_threshold: @config.overlap_threshold,
    baseline_fraction: @config.baseline_fraction
  ).call

  Result.new(detector_result: detector, index: index,
             savings: SavingsEstimator.new(run, detector), run: run)
end