Class: TTNT::TestSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/ttnt/test_selector.rb

Instance Method Summary collapse

Constructor Details

#initialize(target_sha, base_sha) ⇒ TestSelector

Returns a new instance of TestSelector.



7
8
9
10
11
# File 'lib/ttnt/test_selector.rb', line 7

def initialize(target_sha, base_sha)
  @repo = Rugged::Repository.discover('.')
  @target_obj = @repo.lookup(target_sha)
  @base_obj = @repo.lookup(base_sha)
end

Instance Method Details

#select_testsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ttnt/test_selector.rb', line 13

def select_tests
  tests = Set.new
  mapping = TTNT::TestToCodeMapping.new(@base_obj.oid)
  # TODO: if mapping is not found (ttnt-anchor has not been run)

  diff = @base_obj.diff(@target_obj)
  diff.each_patch do |patch|
    file = patch.delta.old_file[:path]
    patch.each_hunk do |hunk|
      # TODO: think if this selection covers all possibilities
      hunk.each_line do |line|
        case line.line_origin
        when :addition
          # FIXME: new_lineno is suspicious
          #        (what if hunk1 adds 100 lines and hunk2 add 1 line?)
          tests += mapping.get_tests(file: file, lineno: line.new_lineno)
        when :deletion
          tests += mapping.get_tests(file: file, lineno: line.old_lineno)
        else
          # do nothing
        end
      end
    end
  end
  tests.delete(nil)
end