Class: WTT::Core::Selector
- Inherits:
-
Object
- Object
- WTT::Core::Selector
- Defined in:
- lib/wtt/core/selector.rb
Overview
Select tests using Git information and a Mapper.
Instance Attribute Summary collapse
-
#mapping ⇒ Object
writeonly
Sets the attribute mapping.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
-
#walker ⇒ Object
writeonly
Sets the attribute walker.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Selector
constructor
A new instance of Selector.
-
#select_tests! ⇒ Set
Select tests using differences in anchored commit and target commit (or current working tree) and TestToCodeMapping.
Constructor Details
#initialize(opts) ⇒ Selector
15 16 17 18 19 20 21 22 |
# File 'lib/wtt/core/selector.rb', line 15 def initialize(opts) @repo = opts[:repo] @metadata = opts[:meta_data] @walker = opts[:walker] @test_files = opts[:test_files] @mapping = opts[:mapping] @target_revision = @repo.lookup(opts[:target_sha]) if opts[:target_sha] end |
Instance Attribute Details
#mapping=(value) ⇒ Object
Sets the attribute mapping
12 13 14 |
# File 'lib/wtt/core/selector.rb', line 12 def mapping=(value) @mapping = value end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
11 12 13 |
# File 'lib/wtt/core/selector.rb', line 11 def tests @tests end |
#walker=(value) ⇒ Object
Sets the attribute walker
12 13 14 |
# File 'lib/wtt/core/selector.rb', line 12 def walker=(value) @walker = value end |
Instance Method Details
#select_tests! ⇒ Set
Select tests using differences in anchored commit and target commit (or current working tree) and TestToCodeMapping.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wtt/core/selector.rb', line 28 def select_tests! # Base should be the commit `anchor` has run on. # NOT the one test-to-code mapping was committed to. @base_obj = anchored_commit # select all tests if anchored commit does not exist return Set.new(@test_files) unless @base_obj change_count = 0 @tests = Set.new diff.each_patch do |patch| change_count += 1 file = patch.delta.old_file[:path] if test_file?(file) @tests << file else select_tests_from_patch(patch) end end @tests.delete(nil) puts "WTT found #{@tests.count} tests for #{change_count} changes." unmapped = 0 mapping.unmapped_tests.each do |test| unmapped += 1 @tests << test end @tests.delete(nil) puts "WTT found #{unmapped} tests with no mapping that will be executed." @tests end |