Class: TestCenter::Helper::TestCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/helper/test_collector.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TestCollector

Returns a new instance of TestCollector.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 8

def initialize(options)
  unless options[:xctestrun] || options[:derived_data_path]
    options[:derived_data_path] = default_derived_data_path(options)
  end
  @xctestrun_path = options[:xctestrun] || derived_testrun_path(options[:derived_data_path], options[:scheme])
  unless @xctestrun_path && File.exist?(@xctestrun_path)
    FastlaneCore::UI.user_error!("Error: cannot find xctestrun file '#{@xctestrun_path}'")
  end
  @only_testing = options[:only_testing]
  @skip_testing = options[:skip_testing]
end

Instance Method Details

#default_derived_data_path(options) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 20

def default_derived_data_path(options)
  Scan.project = FastlaneCore::Project.new(
    options.select { |k, v| %i[workspace project].include?(k) }
  )
  project_derived_data_path = Scan.project.build_settings(key: "BUILT_PRODUCTS_DIR")
  File.expand_path("../../..", project_derived_data_path)
end

#derived_testrun_path(derived_data_path, scheme) ⇒ Object



28
29
30
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 28

def derived_testrun_path(derived_data_path, scheme)
  Dir.glob("#{derived_data_path}/Build/Products/#{scheme}*.xctestrun").first
end

#only_testing_to_testables_testsObject



43
44
45
46
47
48
49
50
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 43

def only_testing_to_testables_tests
  tests = Hash.new { |h, k| h[k] = [] }
  @only_testing.sort.each do |test_identifier|
    testable = test_identifier.split('/', 2)[0]
    tests[testable] << test_identifier
  end
  tests
end

#testablesObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 32

def testables
  unless @testables
    if @only_testing
      @testables ||= only_testing_to_testables_tests.keys
    else
      @testables ||= Plist.parse_xml(@xctestrun_path).keys
    end
  end
  @testables
end

#testables_testsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 52

def testables_tests
  unless @testables_tests
    if @only_testing
      @testables_tests = only_testing_to_testables_tests
    else
      config = FastlaneCore::Configuration.create(::Fastlane::Actions::TestsFromXctestrunAction.available_options, xctestrun: @xctestrun_path)
      @testables_tests = ::Fastlane::Actions::TestsFromXctestrunAction.run(config)
      if @skip_testing
        skipped_testable_tests = Hash.new { |h, k| h[k] = [] }
        @skip_testing.sort.each do |skipped_test_identifier|
          testable = skipped_test_identifier.split('/', 2)[0]
          skipped_testable_tests[testable] << skipped_test_identifier
        end
        @testables_tests.each_key do |testable|
          @testables_tests[testable] -= skipped_testable_tests[testable]
        end
      end
    end
  end
  @testables_tests
end