Class: TestCenter::Helper::TestCollector
- Inherits:
-
Object
- Object
- TestCenter::Helper::TestCollector
- Defined in:
- lib/fastlane/plugin/test_center/helper/test_collector.rb
Instance Attribute Summary collapse
-
#xctestrun_path ⇒ Object
readonly
Returns the value of attribute xctestrun_path.
Instance Method Summary collapse
- #default_derived_data_path(options) ⇒ Object
- #derived_testrun_path(derived_data_path, scheme) ⇒ Object
- #expand_testsuites_to_tests ⇒ Object
-
#initialize(options) ⇒ TestCollector
constructor
A new instance of TestCollector.
- #only_testing_to_testables_tests ⇒ Object
- #test_batches ⇒ Object
- #testables ⇒ Object
- #testables_tests ⇒ Object
- #xctestrun_known_tests ⇒ Object
Constructor Details
#initialize(options) ⇒ TestCollector
Returns a new instance of TestCollector.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 10 def initialize() unless [:xctestrun] || [:derived_data_path] [:derived_data_path] = default_derived_data_path() end @xctestrun_path = [:xctestrun] || derived_testrun_path([:derived_data_path], [:scheme]) unless @xctestrun_path && File.exist?(@xctestrun_path) FastlaneCore::UI.user_error!("Error: cannot find xctestrun file '#{@xctestrun_path}'") end @only_testing = [:only_testing] if @only_testing.kind_of?(String) @only_testing = @only_testing.split(',') end @skip_testing = [:skip_testing] @invocation_based_tests = [:invocation_based_tests] @batch_count = [:batch_count] if @batch_count == 1 && [:parallel_testrun_count] > 1 @batch_count = [:parallel_testrun_count] end end |
Instance Attribute Details
#xctestrun_path ⇒ Object (readonly)
Returns the value of attribute xctestrun_path.
8 9 10 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 8 def xctestrun_path @xctestrun_path end |
Instance Method Details
#default_derived_data_path(options) ⇒ Object
30 31 32 33 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 30 def default_derived_data_path() project_derived_data_path = Scan.project.build_settings(key: "BUILT_PRODUCTS_DIR") File.("../../..", project_derived_data_path) end |
#derived_testrun_path(derived_data_path, scheme) ⇒ Object
35 36 37 38 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 35 def derived_testrun_path(derived_data_path, scheme) xctestrun_files = Dir.glob("#{derived_data_path}/Build/Products/*.xctestrun") xctestrun_files.sort { |f1, f2| File.mtime(f1) <=> File.mtime(f2) }.last end |
#expand_testsuites_to_tests ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 73 def return if @invocation_based_tests known_tests = [] @testables_tests.each do |testable, tests| tests.each_with_index do |test, index| if test.count('/') < 2 known_tests += xctestrun_known_tests[testable] test_components = test.split('/') testsuite = test_components.size == 1 ? test_components[0] : test_components[1] @testables_tests[testable][index] = known_tests.select { |known_test| known_test.include?(testsuite) } end end @testables_tests[testable].flatten! end end |
#only_testing_to_testables_tests ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 53 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 |
#test_batches ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 113 def test_batches if @batches.nil? @batches = [] testables.each do |testable| testable_tests = testables_tests[testable] next if testable_tests.empty? if @batch_count > 1 slice_count = [(testable_tests.length / @batch_count.to_f).ceil, 1].max testable_tests.each_slice(slice_count).to_a.each do |tests_batch| @batches << tests_batch end else @batches << testable_tests end end end @batches end |
#testables ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 40 def testables unless @testables if @only_testing @testables ||= only_testing_to_testables_tests.keys else @testables ||= Plist.parse_xml(@xctestrun_path).keys.reject do |key| key == '__xctestrun_metadata__' end end end @testables end |
#testables_tests ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 90 def testables_tests unless @testables_tests if @only_testing @testables_tests = only_testing_to_testables_tests else @testables_tests = xctestrun_known_tests 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 |
#xctestrun_known_tests ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fastlane/plugin/test_center/helper/test_collector.rb', line 62 def xctestrun_known_tests config = FastlaneCore::Configuration.create( ::Fastlane::Actions::TestsFromXctestrunAction., { xctestrun: @xctestrun_path, invocation_based_tests: @invocation_based_tests } ) ::Fastlane::Actions::TestsFromXctestrunAction.run(config) end |