test_bench-detect_coverage 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8498d7d7cd5488c17f17d3d0dbf5785723752bbcb7e463dcf8c559191b5437d3
4
+ data.tar.gz: 5aaf9b5e117fc818b2e72dcb1da6b6fdfffb41c287cb368217ae52eef2c10e38
5
+ SHA512:
6
+ metadata.gz: f6c131e9aa636b359219febed909fe7e33ae1c89db4338146a1c5335bbc3d1cb4a7b52b91501111b3b13a88bbfbd05870adedb4cc3abb6be4d19e3e5fd052017
7
+ data.tar.gz: 21aaa577b43cc0a0075c18bf8694ff1a069533a0fa8b9e7c4f1dec56cb50eb3978a36a343a5fd9b435c17ea7faa07a25221b1af0ebf8055647070648cd72fa7e
@@ -0,0 +1,96 @@
1
+ module TestBench
2
+ class DetectCoverage
3
+ module Controls
4
+ module Receiver
5
+ def self.example
6
+ Class::Example.build
7
+ end
8
+
9
+ module Module
10
+ def self.example
11
+ Example
12
+ end
13
+
14
+ module Example
15
+ def some_module_instance_method
16
+ end
17
+
18
+ def self.some_module_class_method
19
+ end
20
+
21
+ class << Example
22
+ def some_module_singleton_method
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ module Class
29
+ def self.example
30
+ Example
31
+ end
32
+
33
+ class Example
34
+ include Module::Example
35
+
36
+ def self.build
37
+ instance = new
38
+
39
+ class << instance
40
+ def some_singleton_method
41
+ end
42
+ end
43
+
44
+ instance
45
+ end
46
+
47
+ def some_instance_method
48
+ end
49
+
50
+ def self.some_class_method
51
+ end
52
+
53
+ class << self
54
+ def some_singleton_class_method
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ module Internal
61
+ def self.example
62
+ Dir
63
+ end
64
+
65
+ def self.method_id
66
+ :[]
67
+ end
68
+ end
69
+
70
+ module External
71
+ def self.example
72
+ Receiver.example
73
+ end
74
+
75
+ def self.local_directory
76
+ '/tmp'
77
+ end
78
+
79
+ def self.method_id
80
+ :some_instance_method
81
+ end
82
+
83
+ module Gem
84
+ def self.example
85
+ ::TestBench::Defaults
86
+ end
87
+
88
+ def self.method_id
89
+ :abort_on_error
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1 @@
1
+ require 'test_bench/detect_coverage/controls/receiver'
@@ -0,0 +1,92 @@
1
+ module TestBench
2
+ class DetectCoverage
3
+ attr_reader :paths
4
+ attr_reader :run_arguments
5
+
6
+ def initialize(paths, run_arguments)
7
+ @paths = paths
8
+ @run_arguments = run_arguments
9
+ end
10
+
11
+ def self.build(path, *additional_paths, **run_arguments)
12
+ paths = [path, *additional_paths]
13
+
14
+ new(paths, run_arguments)
15
+ end
16
+
17
+ def self.call(path, *additional_paths, **run_arguments, &block)
18
+ instance = build(path, *additional_paths, **run_arguments)
19
+ instance.(&block)
20
+ end
21
+
22
+ def call(&block)
23
+ reader, writer = IO.pipe
24
+
25
+ child_process = fork do
26
+ reader.close
27
+
28
+ output = Output.new
29
+
30
+ session = TestBench::Session.build(output:)
31
+
32
+ TestBench::Run.(session: session, **run_arguments) do |run|
33
+ actuator = proc {
34
+ paths.each do |path|
35
+ run.path(path)
36
+ end
37
+ }
38
+
39
+ Trace.(actuator) do |method_specifier|
40
+ if method_specifier.start_with?(TestBench::DetectCoverage.name)
41
+ next
42
+ end
43
+
44
+ test_file = output.current_test_file
45
+
46
+ text = [
47
+ method_specifier,
48
+ test_file
49
+ ].join("\t")
50
+
51
+ writer.puts(text)
52
+ end
53
+
54
+ writer.puts
55
+
56
+ ensure
57
+ writer.close
58
+ end
59
+ end
60
+
61
+ writer.close
62
+
63
+ until reader.eof?
64
+ text = reader.gets.chomp
65
+
66
+ break if text.empty?
67
+
68
+ method_specifier, test_file = text.split("\t", 2)
69
+
70
+ invocation = Invocation.new(method_specifier, test_file)
71
+
72
+ block.(invocation)
73
+ end
74
+
75
+ Process.wait(child_process)
76
+ end
77
+
78
+ Invocation = Struct.new(:method_specifier, :test_file) do
79
+ def method = method_specifier
80
+ end
81
+
82
+ class Output
83
+ include TestBench::Fixture::Output
84
+
85
+ attr_accessor :current_test_file
86
+
87
+ def enter_file(path)
88
+ self.current_test_file = path
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,106 @@
1
+ module TestBench
2
+ class DetectCoverage
3
+ class Trace
4
+ attr_reader :actuator
5
+ attr_reader :probe
6
+ attr_reader :local_directory
7
+
8
+ def initialize(actuator, probe, local_directory)
9
+ @actuator = actuator
10
+ @probe = probe
11
+ @local_directory = local_directory
12
+ end
13
+
14
+ def self.build(actuator, local_directory: nil, &probe)
15
+ local_directory ||= Dir.pwd
16
+
17
+ new(actuator, probe, local_directory)
18
+ end
19
+
20
+ def self.call(...)
21
+ instance = build(...)
22
+ instance.()
23
+ end
24
+
25
+ def call
26
+ trace = TracePoint.trace(:call) do |trace_point|
27
+ trace_point(trace_point)
28
+ end
29
+
30
+ actuator.()
31
+ ensure
32
+ trace.disable
33
+ end
34
+
35
+ def trace_point(trace_point)
36
+ if internal?(trace_point)
37
+ return
38
+ elsif external?(trace_point)
39
+ return
40
+ end
41
+
42
+ path = trace_point.path
43
+
44
+ cls = trace_point.defined_class
45
+
46
+ if cls.singleton_class?
47
+ receiver = trace_point.self
48
+
49
+ if receiver.is_a?(Module)
50
+ cls = trace_point.self
51
+
52
+ scope_symbol = '.'
53
+ else
54
+ cls = trace_point.self.class
55
+
56
+ scope_symbol = '#'
57
+ end
58
+ else
59
+ scope_symbol = '#'
60
+ end
61
+
62
+ constant_name = cls.name
63
+
64
+ method_specifier = [
65
+ constant_name,
66
+ scope_symbol,
67
+ trace_point.method_id
68
+ ].join
69
+
70
+ probe.(method_specifier)
71
+ end
72
+
73
+ def internal?(trace_point)
74
+ path = trace_point.path
75
+
76
+ self.class.internal_path_pattern.match?(path)
77
+ end
78
+
79
+ def self.internal_path_pattern
80
+ %r{\A<internal:[[:graph:]]+>\z}
81
+ end
82
+
83
+ def external?(trace_point)
84
+ path = trace_point.path
85
+
86
+ gem_path = File.fnmatch?(self.class.gem_path_pattern, path)
87
+ if gem_path
88
+ return true
89
+ end
90
+
91
+ external_path = !path.start_with?(local_directory)
92
+ if external_path
93
+ return true
94
+ end
95
+
96
+ false
97
+ end
98
+
99
+ def self.gem_path_pattern
100
+ ruby_version = RbConfig::CONFIG['ruby_version']
101
+
102
+ File.join('**', 'gems', 'ruby', ruby_version, 'gems', '**')
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,6 @@
1
+ require 'rbconfig'
2
+
3
+ require 'test_bench'
4
+
5
+ require 'test_bench/detect_coverage/trace'
6
+ require 'test_bench/detect_coverage/detect_coverage'
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_bench-detect_coverage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Ladd
8
+ autorequire:
9
+ bindir: script
10
+ cert_chain: []
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test_bench
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0.0
27
+ description:
28
+ email: nathanladd+github@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/test_bench/detect_coverage.rb
34
+ - lib/test_bench/detect_coverage/controls.rb
35
+ - lib/test_bench/detect_coverage/controls/receiver.rb
36
+ - lib/test_bench/detect_coverage/detect_coverage.rb
37
+ - lib/test_bench/detect_coverage/trace.rb
38
+ homepage: https://github.com/test-bench/test-bench-detect-coverage
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.3.4
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Capture method invocations caused by TestBench tests
61
+ test_files: []