affected_tests 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcc672116e5bb9b0e2da893b7210c77f11e5b95e3c64fc4c217edb1f06f2e7d2
4
- data.tar.gz: 1f03fe6932d5f970ee5606501412f30cc397163e86b3a543fe1e95c2d04c3dbd
3
+ metadata.gz: 9f7612b94dce034b4d89f2891cdc08bc1ee7781449b1f99c5896a22654e9c9e1
4
+ data.tar.gz: c56ce89c20979413b0af7f0bef9566bf19d6d073b01a27d79a98ac57b2d738da
5
5
  SHA512:
6
- metadata.gz: 2f92a2f7dd2d2f322d27ca90ebeeaffb18d765145d51efcd6b2df571dd95ffe6a67ba27b3a16e25736853cc148f07f3d064fee1b28f843cbfe43150872757d8e
7
- data.tar.gz: ac127737a5b1555e35d18eb3ce9b0cde6adfd679b8bb852482934296e0ec371ed9f14027c1614af98e436f52896c59053094be5b6016c296a481f3b45ffd5078
6
+ metadata.gz: b19b06a01002be005295109ca9cf81c1d8177f40730ade142f9e3a5293fcb91286302398fb06299d5c56e8248615adae0223735302a4bd60ec845467d85af5fd
7
+ data.tar.gz: f52bf08410c743a5032ebae1fb260a54ab0fa8098d3f76e043855d18d92df8c4bdf27e637b962a45fbda5c4aa5cec56d8954efebe6be201fd989d6040ac0ac28
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- affected_tests (0.3.0)
4
+ affected_tests (0.5.0)
5
5
  rotoscope
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -27,6 +27,7 @@ require "affected_tests"
27
27
  require "affected_tests/rspec"
28
28
 
29
29
  AffectedTests.setup(
30
+ engine: :rotoscope,
30
31
  project_path: File.expand_path("../../", __FILE__),
31
32
  test_dir_path: "spec/",
32
33
  output_path: "log/affected-tests-map.json",
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AffectedTests
4
+ module Engine
5
+ class Coverage
6
+ def initialize(config)
7
+ @config = config
8
+
9
+ ::Coverage.start(lines: true)
10
+ end
11
+
12
+ def start_trace
13
+ # Clear buffer in coverage
14
+ ::Coverage.result(stop: false, clear: true)
15
+ end
16
+
17
+ def stop_trace
18
+ # Do nothing
19
+ end
20
+
21
+ def tracing?
22
+ ::Coverage.running?
23
+ end
24
+
25
+ def checkpoint(target_test_path)
26
+ result = ::Coverage.result(stop: false, clear: true)
27
+ actual_used = result.select do |_file_path, coverage|
28
+ coverage[:lines].any? { |line| line && line > 0 }
29
+ end
30
+ import(target_test_path, actual_used.keys)
31
+ end
32
+
33
+ def import(target_test_path, used_file_paths)
34
+ all_related_paths = used_file_paths.select do |file_path|
35
+ @config.target_path?(file_path)
36
+ end
37
+
38
+ formatted_target_test_path = @config.format_path(target_test_path)
39
+
40
+ all_related_paths.each do |path|
41
+ formatted_path = @config.format_path(path)
42
+
43
+ next if formatted_path.start_with?(@config.test_dir_path)
44
+
45
+ if formatted_path != formatted_target_test_path
46
+ add(formatted_target_test_path, formatted_path)
47
+ end
48
+ end
49
+ end
50
+
51
+ def add(caller, callee)
52
+ cache[callee] ||= Set.new
53
+ cache[callee].add(caller)
54
+ end
55
+
56
+ def cache
57
+ Thread.current[:cache] ||= {}
58
+ end
59
+
60
+ def dump
61
+ ::Coverage.result(stop: true, clear: true)
62
+
63
+ cache.transform_values(&:to_a)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AffectedTests
4
+ module Engine
5
+ class Rotoscope
6
+ def initialize(config)
7
+ @config = config
8
+
9
+ @rotoscope = ::Rotoscope.new do |call|
10
+ next if self == call.receiver
11
+
12
+ if call.caller_path && @config.target_path?(call.caller_path)
13
+ buffer << call.caller_path
14
+ end
15
+ end
16
+ end
17
+
18
+ def start_trace
19
+ @rotoscope.start_trace
20
+ end
21
+
22
+ def stop_trace
23
+ @rotoscope.stop_trace
24
+ end
25
+
26
+ def tracing?
27
+ @rotoscope.tracing?
28
+ end
29
+
30
+ def checkpoint(target_test_path)
31
+ diff = buffer
32
+ import(target_test_path, diff)
33
+ buffer.clear
34
+ end
35
+
36
+ def import(target_test_path, result)
37
+ all_related_paths = result.uniq.map do |caller_path|
38
+ @config.format_path(caller_path)
39
+ end
40
+
41
+ formatted_target_test_path = @config.format_path(target_test_path)
42
+
43
+ all_related_paths.each do |path|
44
+ next if path.start_with?(@config.test_dir_path)
45
+
46
+ if path != formatted_target_test_path
47
+ add(formatted_target_test_path, path)
48
+ end
49
+ end
50
+ end
51
+
52
+ def add(caller, callee)
53
+ cache[callee] ||= Set.new
54
+ cache[callee].add(caller)
55
+ end
56
+
57
+ def buffer
58
+ Thread.current[:buffer] ||= []
59
+ end
60
+
61
+ def cache
62
+ Thread.current[:cache] ||= {}
63
+ end
64
+
65
+ def dump
66
+ cache.transform_values(&:to_a)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AffectedTests
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -3,75 +3,80 @@
3
3
  require "set"
4
4
  require "json"
5
5
 
6
- require "rotoscope"
7
-
8
6
  require_relative "affected_tests/version"
9
7
 
10
8
  module AffectedTests
11
- module_function
12
-
13
- def setup(project_path:, test_dir_path:, output_path:, revision: nil)
14
- @project_path = project_path
15
- @test_dir_path = test_dir_path
16
- @output_path = output_path
17
- @revision = revision
18
- @rotoscope = Rotoscope.new do |call|
19
- next if self == call.receiver
9
+ class Configuration
10
+ attr_reader :project_path, :bundler_path, :test_dir_path, :output_path, :revision
11
+
12
+ def initialize(project_path:, test_dir_path:, output_path:, revision:)
13
+ @project_path = project_path
14
+ @test_dir_path = test_dir_path
15
+ @bundler_path = Bundler.bundle_path.to_s
16
+ @output_path = output_path
17
+ @revision = revision
18
+ end
20
19
 
21
- if call.caller_path && target_path?(call.caller_path)
22
- buffer << call.caller_path
20
+ def format_path(path)
21
+ if path&.start_with?(@project_path)
22
+ path.sub(@project_path + "/", "")
23
+ else
24
+ path
23
25
  end
24
26
  end
25
- end
26
27
 
27
- def start_trace
28
- @rotoscope.start_trace
29
- end
28
+ def target_path?(path)
29
+ return false if path.nil?
30
30
 
31
- def stop_trace
32
- @rotoscope.stop_trace
31
+ path.start_with?(@project_path) && !path.start_with?(@bundler_path)
32
+ end
33
33
  end
34
34
 
35
- def import_from_rotoscope(target_test_path, result)
36
- all_related_paths = result.uniq.map do |caller_path|
37
- format_path(caller_path)
38
- end
35
+ module_function
39
36
 
40
- formatted_target_test_path = format_path(target_test_path)
37
+ def setup(engine: :rotoscope, project_path:, test_dir_path:, output_path:, revision: nil)
38
+ @config = Configuration.new(
39
+ project_path: project_path,
40
+ output_path: output_path,
41
+ revision: revision,
42
+ test_dir_path: test_dir_path
43
+ )
41
44
 
42
- all_related_paths.each do |path|
43
- next if path.start_with?(@test_dir_path)
45
+ @engine = select_engine(engine).new(@config)
46
+ end
44
47
 
45
- if path != formatted_target_test_path
46
- add(formatted_target_test_path, path)
47
- end
48
+ def select_engine(engine)
49
+ case engine
50
+ when :rotoscope
51
+ require "rotoscope"
52
+ require "affected_tests/engine/rotoscope"
53
+ AffectedTests::Engine::Rotoscope
54
+ when :coverage
55
+ require "coverage"
56
+ require "affected_tests/engine/coverage"
57
+ AffectedTests::Engine::Coverage
58
+ else
59
+ raise "Unknown engine: #{engine}"
48
60
  end
49
61
  end
50
62
 
51
- def checkpoint(target_test_path)
52
- diff = buffer
53
- import_from_rotoscope(target_test_path, diff)
54
- buffer.clear
63
+ def start_trace
64
+ @engine.start_trace
55
65
  end
56
66
 
57
- def dump
58
- data = { revision: @revision || build_revision, map: cache.transform_values(&:to_a) }
59
- File.write(@output_path, JSON.dump(data))
60
- ensure
61
- @rotoscope.stop_trace if @rotoscope.tracing?
67
+ def stop_trace
68
+ @engine.stop_trace
62
69
  end
63
70
 
64
- def format_path(path)
65
- if path&.start_with?(@project_path)
66
- path.sub(@project_path + "/", "")
67
- else
68
- path
69
- end
71
+ def checkpoint(target_test_path)
72
+ @engine.checkpoint(target_test_path)
70
73
  end
71
74
 
72
- def add(caller, callee)
73
- cache[callee] ||= Set.new
74
- cache[callee].add(caller)
75
+ def dump
76
+ data = { revision: @config.revision || build_revision, map: @engine.dump }
77
+ File.write(@config.output_path, JSON.dump(data))
78
+ ensure
79
+ @engine.stop_trace if @engine.tracing?
75
80
  end
76
81
 
77
82
  def build_revision
@@ -86,22 +91,4 @@ module AffectedTests
86
91
  "UNKNOWN"
87
92
  end
88
93
  end
89
-
90
- def buffer
91
- Thread.current[:buffer] ||= []
92
- end
93
-
94
- def cache
95
- Thread.current[:cache] ||= {}
96
- end
97
-
98
- def bundler_path
99
- @bundler_path ||= Bundler.bundle_path.to_s
100
- end
101
-
102
- def target_path?(path)
103
- return false if path.nil?
104
-
105
- path.start_with?(@project_path) && !path.start_with?(bundler_path)
106
- end
107
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: affected_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-29 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rotoscope
@@ -39,6 +39,8 @@ files:
39
39
  - Rakefile
40
40
  - lib/affected_tests.rb
41
41
  - lib/affected_tests/differ.rb
42
+ - lib/affected_tests/engine/coverage.rb
43
+ - lib/affected_tests/engine/rotoscope.rb
42
44
  - lib/affected_tests/map_merger.rb
43
45
  - lib/affected_tests/rspec.rb
44
46
  - lib/affected_tests/version.rb