Class: AppMap::Depends::API

Inherits:
Object show all
Defined in:
lib/appmap/depends/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verbose) ⇒ API

Returns a new instance of API.



13
14
15
# File 'lib/appmap/depends/api.rb', line 13

def initialize(verbose)
  @verbose = verbose
end

Instance Attribute Details

#verboseObject (readonly)

Returns the value of attribute verbose.



11
12
13
# File 'lib/appmap/depends/api.rb', line 11

def verbose
  @verbose
end

Instance Method Details

#inspect_test_files(appmap_dir:, test_file_patterns:) ⇒ Object

Compute which test case files have been added, removed, changed, or failed, relative to the AppMaps.



29
30
31
32
# File 'lib/appmap/depends/api.rb', line 29

def inspect_test_files(appmap_dir:, test_file_patterns:)
  inspector = AppMap::Depends::TestFileInspector.new(appmap_dir, test_file_patterns)
  inspector.report
end

#modified(appmap_dir:, base_dir:) ⇒ Object

Compute the set of test files which are “out of date” with respect to source files in base_dir. Use AppMaps in appmap_dir to make this computation.



19
20
21
22
23
24
25
# File 'lib/appmap/depends/api.rb', line 19

def modified(appmap_dir:, base_dir:)
  depends = AppMap::Depends::NodeCLI.new(verbose: verbose, appmap_dir: appmap_dir)
  depends.base_dir = base_dir if base_dir
  test_files = depends.depends

  Set.new prune_directory_prefix(test_files)
end

#remove_out_of_date_appmaps(since, appmap_dir:, base_dir:) ⇒ Object

Remove out-of-date AppMaps which are unmodified since the start time. This operation is used to remove AppMaps that were previously generated from a test case that has been removed from a test file.

  • since an instance of Time



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/appmap/depends/api.rb', line 56

def remove_out_of_date_appmaps(since, appmap_dir:, base_dir:)
  since_ms = ( since.to_f * 1000 ).to_i

  depends = AppMap::Depends::NodeCLI.new(verbose: verbose, appmap_dir: appmap_dir)
  depends.base_dir = base_dir if base_dir
  depends.field = nil
  out_of_date_appmaps = depends.depends
  removed = []
  out_of_date_appmaps.each do |appmap_path|
    mtime_path = File.join(appmap_path, 'mtime')
    next unless File.exist?(mtime_path)

    appmap_mtime = File.read(mtime_path).to_i
    if appmap_mtime < since_ms
      Util.delete_appmap appmap_path
      removed << appmap_path
    end
  end
  removed.sort
end

#report_list(title, files) ⇒ Object

Print a brief report to STDERR.



35
36
37
# File 'lib/appmap/depends/api.rb', line 35

def report_list(title, files)
  warn [ title, files.to_a.sort.join(' ') ].join(': ') unless files.empty?
end

#run_tests(test_files, appmap_dir:) ⇒ Object

Run the specified test files. After running the tests, update the AppMap index. TODO: If the tests fail, this method will raise, and the index won’t be updated. What’s the right behavior for the index if there is a test failure? Current behavior may not match user expectations.



43
44
45
46
47
48
49
50
# File 'lib/appmap/depends/api.rb', line 43

def run_tests(test_files, appmap_dir:)
  test_files = test_files.to_a.sort
  warn "Running tests: #{test_files.join(' ')}"

  TestRunner.new(test_files).run

  AppMap::NodeCLI.new(verbose: verbose, appmap_dir: appmap_dir).index_appmaps
end