Class: Fastlane::Actions::RetrieveXctestNamesAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.available_optionsObject



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 101

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :xctestrun,
      description: 'The xctestrun file path',
      verify_block: proc do |path|
        UI.user_error!("Cannot find the xctestrun file '#{path}'") unless File.exist?(path)
      end
    )
  ]
end

.descriptionObject



97
98
99
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 97

def self.description
  'Retrieves test names from xctestrun file'
end

.run(params) ⇒ Object



7
8
9
10
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 7

def self.run(params)
  UI.verbose("Getting tests from xctestrun file at '#{params[:xctestrun]}'")
  xctestrun_tests(params[:xctestrun])
end

.subtract_skipped_tests_from_test_identifiers(test_identifiers, skipped_test_identifiers) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 63

def self.subtract_skipped_tests_from_test_identifiers(test_identifiers, skipped_test_identifiers)
  skipped_tests_identifiers = []
  skipped_testsuites = []
  skipped_test_identifiers.each do |skipped_test|
    if skipped_test.split('/').size > 1
      skipped_tests_identifiers << skipped_test
    else
      skipped_testsuites << skipped_test
    end
  end
  skipped_testsuites.each do |skipped_testsuite|
    derived_skipped_tests = test_identifiers.select do |test_identifier|
      test_identifier.start_with?(skipped_testsuite)
    end
    skipped_tests_identifiers.concat(derived_skipped_tests)
  end

  UI.verbose("Removing skipped tests: #{skipped_tests_identifiers.join("\n\t")}")
  test_identifiers.reject { |test_identifier| skipped_tests_identifiers.include?(test_identifier) }
end

.supported?(_platform) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 113

def self.supported?(_platform)
  [:ios].include?(platform)
end

.xctest_bundle_path(xctestrun_rootpath, xctestrun_config) ⇒ Object



84
85
86
87
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 84

def self.xctest_bundle_path(xctestrun_rootpath, xctestrun_config)
  xctest_host_path = xctestrun_config['TestHostPath'].sub('__TESTROOT__', xctestrun_rootpath)
  xctestrun_config['TestBundlePath'].sub('__TESTHOST__', xctest_host_path).sub('__TESTROOT__', xctestrun_rootpath)
end

.xctestrun_metadataObject



89
90
91
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 89

def self.
  '__xctestrun_metadata__'
end

.xctestrun_tests(xctestrun_path) ⇒ Object



12
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/stream_actions/actions/retrieve_xctest_names.rb', line 12

def self.xctestrun_tests(xctestrun_path)
  xctestrun = Plist.parse_xml(xctestrun_path)
  xctestrun_rootpath = File.dirname(xctestrun_path)
  xctestrun_version = xctestrun.fetch() { {} }.fetch('FormatVersion') { 1 }

  test_targets = []
  if xctestrun_version == 1
    xctestrun.each do |testable_name, test_target_config|
      next if testable_name == 

      test_target_config['TestableName'] = testable_name
      test_targets << test_target_config
    end
  else
    test_configurations = xctestrun['TestConfigurations']
    test_configurations.each do |configuration|
      configuration['TestTargets'].each do |test_target|
        test_target['TestableName'] = test_target['BlueprintName']
        test_targets << test_target
      end
    end
  end

  tests = {}
  test_targets.each do |xctestrun_config|
    testable_name = xctestrun_config['TestableName']
    xctest_path = xctest_bundle_path(xctestrun_rootpath, xctestrun_config)
    test_identifiers = []
    if xctestrun_config.key?('OnlyTestIdentifiers')
      test_identifiers = xctestrun_config['OnlyTestIdentifiers']
      UI.verbose("Identifiers after adding onlytest tests: #{test_identifiers.join("\n\t")}")
    else
      test_identifiers = XCTestList.tests(xctest_path)
      UI.verbose("Found the following tests: #{test_identifiers.join("\n\t")}")
    end
    if xctestrun_config.key?('SkipTestIdentifiers')
      test_identifiers = subtract_skipped_tests_from_test_identifiers(
        test_identifiers,
        xctestrun_config['SkipTestIdentifiers']
      )
      UI.verbose("Identifiers after removing skipped tests: #{test_identifiers.join("\n\t")}")
    end
    if test_identifiers.empty?
      UI.error("No tests found in '#{xctest_path}'!")
      UI.important("Check `ENABLE_TESTABILITY` build setting in `#{testable_name}` test target.")
    end
    tests[testable_name] = test_identifiers.map { |test_identifier| "#{testable_name}/#{test_identifier}" }
  end
  tests
end