affected_tests 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32deac2b7ba23269acfb008ef35c099cc3c109200169485edb240fd7287daae3
4
- data.tar.gz: c0fa16f41e7043e39443b7813504711d7be5b4e2004aea06518e190ce28b5ae8
3
+ metadata.gz: aba033bbf0c484e7a26a9a58cecdf28da51caa55ba9ccd4f12c4ff63f5db1dd8
4
+ data.tar.gz: 9669ed400572ff49bf35c4e1d6e0912b8a53332646e93a0fef73231ba81a8e6d
5
5
  SHA512:
6
- metadata.gz: 64f16bea896df2943bfd71f506ad664b8d2d4206ecf2527912eedc62776e8a0a8d7b3aa9bb25e24b4621e468d496601c41e03ee7157cf30da6eb004dea743837
7
- data.tar.gz: b568db5e8c365b6f39c0198aa3930d7d52f2d824c9429cd3eb4709ae2905fc48c27d48e4a11272111e26dc9afcfeb61ccd5c361149ac218a95c408d9a70e8b96
6
+ metadata.gz: bdf0dcb1bf128f8dced4830d52ff426ca203fc03d6981a5e18ad6d8a19b0ffec6e8894687defa80f6b16ac43961862fda67e0abc921d6a69684e0bdc82842296
7
+ data.tar.gz: 4caeeedab8d327fa963859a5de7b768096b66f1050ce00dd1b7383b8da97d6b746e5a23127c30a40fe63ee7d7061f07cccfecf394c249026efe1149b1424c718
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --exclude-pattern spec/fixtures/**/*_spec.rb
data/Gemfile CHANGED
@@ -6,3 +6,7 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
+ gem "rspec"
10
+
11
+ # Optional engine, which users choose by themselves
12
+ gem "calleree"
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # AffectedTests
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/affected_tests`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Install the gem and add to the application's Gemfile by executing:
@@ -14,6 +10,15 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
10
 
15
11
  $ gem install affected_tests
16
12
 
13
+ ### About engine
14
+
15
+ affected_tests support 2 engines to find out test, source relation:
16
+
17
+ - coverage (default)
18
+ - calleree
19
+
20
+ each engine require its library, so you need to add proper gem according to your selection(except coverage which is stdlib).
21
+
17
22
  ## Usage
18
23
 
19
24
  ### Aggregate data
@@ -27,7 +32,7 @@ require "affected_tests"
27
32
  require "affected_tests/rspec"
28
33
 
29
34
  AffectedTests.setup(
30
- engine: :rotoscope,
35
+ engine: :coverage,
31
36
  project_path: File.expand_path("../../", __FILE__),
32
37
  test_dir_path: "spec/",
33
38
  output_path: "log/affected-tests-map.json",
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AffectedTests
4
+ module Engine
5
+ class Calleree
6
+ def initialize(config)
7
+ @config = config
8
+ @tracing = true
9
+
10
+ ::Calleree.start
11
+ end
12
+
13
+ def start_trace
14
+ # Clear buffer in calleree
15
+ ::Calleree.result(clear: true)
16
+ end
17
+
18
+ def stop_trace
19
+ # do nothing
20
+ end
21
+
22
+ def tracing?
23
+ @tracing # Calleree doesn't have tracing status
24
+ end
25
+
26
+ def checkpoint(target_test_path)
27
+ res = ::Calleree.result(clear: true)
28
+ import(target_test_path, res)
29
+ end
30
+
31
+ def import(target_test_path, result)
32
+ caller_in_project = result.select do |(caller_info, _callee_info, _count)|
33
+ caller_path = caller_info.first
34
+ @config.target_path?(caller_path)
35
+ end.map do |(caller_info, _callee_info, _count)|
36
+ @config.format_path(caller_info.first)
37
+ end
38
+
39
+ called_in_project = result.select do |(_caller_info, callee_info, _count)|
40
+ callee_path = callee_info.first
41
+ @config.target_path?(callee_path)
42
+ end.map do |(_caller_info, callee_info, _count)|
43
+ @config.format_path(callee_info.first)
44
+ end
45
+
46
+ all_related_paths = (called_in_project + caller_in_project).uniq
47
+ formatted_target_test_path = @config.format_path(target_test_path)
48
+
49
+ all_related_paths.each do |path|
50
+ next if path.start_with?(@config.test_dir_path)
51
+
52
+ if path != formatted_target_test_path
53
+ add(formatted_target_test_path, path)
54
+ end
55
+ end
56
+ end
57
+
58
+ def add(caller, callee)
59
+ cache[callee] ||= Set.new
60
+ cache[callee].add(caller)
61
+ end
62
+
63
+ def cache
64
+ Thread.current[:cache] ||= {}
65
+ end
66
+
67
+ def dump
68
+ cache.transform_values(&:to_a)
69
+ ensure
70
+ ::Calleree.stop
71
+ @tracing = false
72
+ end
73
+ end
74
+ end
75
+ end
@@ -8,6 +8,12 @@ RSpec.configure do |config|
8
8
  config.append_after(:each) do
9
9
  AffectedTests.stop_trace
10
10
  target_spec = self.class.declaration_locations.last[0]
11
+ # Shared examples are declared outside of the spec file including them,
12
+ # so walk up to the group which the spec file itself declares.
13
+ unless target_spec.end_with?("_spec.rb")
14
+ spec_group = self.class.parent_groups.detect { |group| group.declaration_locations.first[0].end_with?("_spec.rb") }
15
+ target_spec = spec_group.declaration_locations.first[0] if spec_group
16
+ end
11
17
  AffectedTests.checkpoint(target_spec)
12
18
  end
13
19
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AffectedTests
4
- VERSION = "0.7.0"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -34,7 +34,7 @@ module AffectedTests
34
34
 
35
35
  module_function
36
36
 
37
- def setup(engine: :rotoscope, project_path:, test_dir_path:, output_path:, revision: nil)
37
+ def setup(engine: :coverage, project_path:, test_dir_path:, output_path:, revision: nil)
38
38
  @config = Configuration.new(
39
39
  project_path: project_path,
40
40
  output_path: output_path,
@@ -47,10 +47,10 @@ module AffectedTests
47
47
 
48
48
  def select_engine(engine)
49
49
  case engine
50
- when :rotoscope
51
- require "rotoscope"
52
- require "affected_tests/engine/rotoscope"
53
- AffectedTests::Engine::Rotoscope
50
+ when :calleree
51
+ require "calleree"
52
+ require "affected_tests/engine/calleree"
53
+ AffectedTests::Engine::Calleree
54
54
  when :coverage
55
55
  require "coverage"
56
56
  require "affected_tests/engine/coverage"
data/mise.toml ADDED
@@ -0,0 +1,3 @@
1
+ [tools]
2
+ ruby = "4.0"
3
+ pinact = "latest"
metadata CHANGED
@@ -1,29 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: affected_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rotoscope
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
27
12
  description: Tool-kit for testing based on changed files.
28
13
  email:
29
14
  - rise.shia@gmail.com
@@ -31,19 +16,20 @@ executables: []
31
16
  extensions: []
32
17
  extra_rdoc_files: []
33
18
  files:
19
+ - ".rspec"
34
20
  - CODE_OF_CONDUCT.md
35
21
  - Gemfile
36
- - Gemfile.lock
37
22
  - LICENSE.txt
38
23
  - README.md
39
24
  - Rakefile
40
25
  - lib/affected_tests.rb
41
26
  - lib/affected_tests/differ.rb
27
+ - lib/affected_tests/engine/calleree.rb
42
28
  - lib/affected_tests/engine/coverage.rb
43
- - lib/affected_tests/engine/rotoscope.rb
44
29
  - lib/affected_tests/map_merger.rb
45
30
  - lib/affected_tests/rspec.rb
46
31
  - lib/affected_tests/version.rb
32
+ - mise.toml
47
33
  - scripts/calculate-target-tests
48
34
  - scripts/generate-diff-files-from-github
49
35
  homepage: https://github.com/riseshia/affected_tests
@@ -52,7 +38,6 @@ licenses:
52
38
  metadata:
53
39
  homepage_uri: https://github.com/riseshia/affected_tests
54
40
  source_code_uri: https://github.com/riseshia/affected_tests
55
- post_install_message:
56
41
  rdoc_options: []
57
42
  require_paths:
58
43
  - lib
@@ -67,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
52
  - !ruby/object:Gem::Version
68
53
  version: '0'
69
54
  requirements: []
70
- rubygems_version: 3.3.7
71
- signing_key:
55
+ rubygems_version: 4.0.16
72
56
  specification_version: 4
73
57
  summary: Tool-kit for testing based on changed files.
74
58
  test_files: []
data/Gemfile.lock DELETED
@@ -1,21 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- affected_tests (0.5.0)
5
- rotoscope
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- rake (13.0.6)
11
- rotoscope (0.3.0)
12
-
13
- PLATFORMS
14
- ruby
15
-
16
- DEPENDENCIES
17
- affected_tests!
18
- rake (~> 13.0)
19
-
20
- BUNDLED WITH
21
- 2.3.17
@@ -1,73 +0,0 @@
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
- @rotoscope.start_trace
17
- end
18
-
19
- def start_trace
20
- # Clear buffer
21
- buffer.clear
22
- end
23
-
24
- def stop_trace
25
- # do nothing
26
- end
27
-
28
- def tracing?
29
- @rotoscope.tracing?
30
- end
31
-
32
- def checkpoint(target_test_path)
33
- diff = buffer
34
- import(target_test_path, diff)
35
- buffer.clear
36
- end
37
-
38
- def import(target_test_path, result)
39
- all_related_paths = result.uniq.map do |caller_path|
40
- @config.format_path(caller_path)
41
- end
42
-
43
- formatted_target_test_path = @config.format_path(target_test_path)
44
-
45
- all_related_paths.each do |path|
46
- next if path.start_with?(@config.test_dir_path)
47
-
48
- if path != formatted_target_test_path
49
- add(formatted_target_test_path, path)
50
- end
51
- end
52
- end
53
-
54
- def add(caller, callee)
55
- cache[callee] ||= Set.new
56
- cache[callee].add(caller)
57
- end
58
-
59
- def buffer
60
- Thread.current[:buffer] ||= []
61
- end
62
-
63
- def cache
64
- Thread.current[:cache] ||= {}
65
- end
66
-
67
- def dump
68
- @rotoscope.stop_trace
69
- cache.transform_values(&:to_a)
70
- end
71
- end
72
- end
73
- end