Class: Flutter::Tracker
- Inherits:
-
Object
- Object
- Flutter::Tracker
- Defined in:
- lib/flutter/tracker.rb
Instance Attribute Summary collapse
-
#source_mapping ⇒ Hash<String, Hash<String, String>>
Mapping of source files -> callable_id -> signature.
-
#storage ⇒ Persistence::AbstractStorage
the storage instance used for persisting the state of the tracker.
-
#test_mapping ⇒ Hash<String, Hash<String, Set<String>>>
Mapping of tests to files -> callable_ids.
Instance Method Summary collapse
-
#initialize(sources, exclusions, storage_class, storage_options) ⇒ Tracker
constructor
A new instance of Tracker.
-
#persist! ⇒ void
Persist the state of the tracker to the storage specified by #storage.
-
#reset! ⇒ void
Reset the state of the tracker and the storage that it was configured with.
-
#skip?(test, test_location, test_source) ⇒ TrueClass, FalseClass
Decides if a test should be skipped based on all of the following criteria being met:.
-
#start(test) ⇒ Object
Starts tracking calls made by +test+.
-
#stop(test, success) ⇒ Object
End tracking (should be called after a call to #start).
- #to_s ⇒ Object
Constructor Details
#initialize(sources, exclusions, storage_class, storage_options) ⇒ Tracker
Returns a new instance of Tracker.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/flutter/tracker.rb', line 24 def initialize(sources, exclusions, storage_class, ) @sources = sources.map { |s| File.absolute_path(s) } @exclusions = exclusions.map { |s| File.absolute_path(s) } @storage = storage_class.new(**) @test_mapping = @storage.test_mapping @previous_test_mapping = {} @test_source_mapping = {} @source_mapping = @storage.source_mapping @current_source_mapping = {} @path_mapping = {} @method_prefixes = {} @tracked_files = {} end |
Instance Attribute Details
#source_mapping ⇒ Hash<String, Hash<String, String>>
Mapping of source files -> callable_id -> signature
16 17 18 |
# File 'lib/flutter/tracker.rb', line 16 def source_mapping @source_mapping end |
#storage ⇒ Persistence::AbstractStorage
the storage instance used for persisting the state of the tracker
16 17 18 |
# File 'lib/flutter/tracker.rb', line 16 def storage @storage end |
#test_mapping ⇒ Hash<String, Hash<String, Set<String>>>
Mapping of tests to files -> callable_ids
16 17 18 |
# File 'lib/flutter/tracker.rb', line 16 def test_mapping @test_mapping end |
Instance Method Details
#persist! ⇒ void
This method returns an undefined value.
Persist the state of the tracker to the storage specified by #storage
94 95 96 97 98 |
# File 'lib/flutter/tracker.rb', line 94 def persist! @storage.update_test_mapping!(@test_mapping) @storage.update_source_mapping!(generate_source_mapping) @storage.persist! end |
#reset! ⇒ void
This method returns an undefined value.
Reset the state of the tracker and the storage that it was configured with
104 105 106 107 108 109 |
# File 'lib/flutter/tracker.rb', line 104 def reset! $stdout.puts "Resetting flutter: #{@storage}" @storage.clear! @source_mapping.clear @test_mapping.clear end |
#skip?(test, test_location, test_source) ⇒ TrueClass, FalseClass
Decides if a test should be skipped based on all of the following criteria being met:
- Test was seen before
- Test sources have not changed since the last time it was executed
- All the callables triggered within the scope of this test have no changes in their source since the last time this test was executed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/flutter/tracker.rb', line 71 def skip?(test, test_location, test_source) test_location_rel = relative_path(test_location) @test_source_mapping.fetch(test_location_rel) do @test_source_mapping[test_location_rel] = {} end[test] = Digest::SHA1.hexdigest(test_source) return false unless @test_mapping.key?(test) && @test_source_mapping[test_location_rel][test] == @source_mapping.dig( test_location_rel, test ) sources = @test_mapping[test] sources.map do |file, methods| @current_source_mapping[file] ||= Flutter::Parser.new(file).signatures methods.map do |method| @source_mapping.dig(file, method) == @current_source_mapping.dig(file, method) end.all? end.all? end |
#start(test) ⇒ Object
Starts tracking calls made by +test+
40 41 42 43 44 45 46 47 48 |
# File 'lib/flutter/tracker.rb', line 40 def start(test) # Delete test from the in-memory mapping to allow each new test run # to store all the functions that the test calls into @previous_test_mapping[test] = @test_mapping.delete(test) @current_tracepoint = TracePoint.new(:call) do |tp| hit!(test, tp) end @current_tracepoint&.enable end |
#stop(test, success) ⇒ Object
End tracking (should be called after a call to #start)
53 54 55 56 |
# File 'lib/flutter/tracker.rb', line 53 def stop(test, success) @current_tracepoint&.disable @test_mapping[test].merge!(@previous_test_mapping.delete(test) || {}) { |_, old, new| old + new } unless success end |
#to_s ⇒ Object
111 112 113 |
# File 'lib/flutter/tracker.rb', line 111 def to_s @storage.to_s end |