Class: Fastlane::Saucectl::Espresso

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/fastlane/plugin/saucectl/helper/espresso.rb

Overview

This class is responsible for creating test execution plans for ios applications and will distribute tests that will be be executed via the cloud provider.

Constant Summary collapse

UI =
FastlaneCore::UI
TEST_FUNCTION_REGEX =
/([a-z]+[A-Z][a-zA-Z]+)[(][)]/.freeze

Constants included from FileUtils

FileUtils::CLASS_NAME_REGEX, FileUtils::FILE_TYPE_REGEX

Instance Method Summary collapse

Methods included from FileUtils

#find, #read_file, #search_retrieve_test_classes, #syscall

Constructor Details

#initialize(config) ⇒ Espresso

Returns a new instance of Espresso.



17
18
19
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 17

def initialize(config)
  @config = config
end

Instance Method Details

#fetch_disabled_tests(path) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 74

def fetch_disabled_tests(path)
  stdout, = find(path, "@Ignore")
  test_cases = []
  stdout.split.each do |line|
    test_cases << line.match(TEST_FUNCTION_REGEX).to_s.gsub(/[()]/, "") if line =~ TEST_FUNCTION_REGEX
  end
  test_cases
end

#strip_empty(test_details) ⇒ Object



59
60
61
62
63
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 59

def strip_empty(test_details)
  tests = []
  test_details.each { |test| tests << test unless test[:tests].size.zero? }
  tests
end

#strip_skipped(path, tests) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 83

def strip_skipped(path, tests)
  enabled_ui_tests = []
  skipped_tests = fetch_disabled_tests(path)
  tests.each do |test|
    enabled_ui_tests << test unless skipped_tests.include?(test)
  end
  enabled_ui_tests
end

#test_dataObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 21

def test_data
  test_details = []
  search_retrieve_test_classes(@config[:path_to_tests]).each do |f|
    next unless File.basename(f) =~ CLASS_NAME_REGEX

    test_details << { package: File.readlines(f).first.chomp.gsub("package ", "").gsub(";", ""),
                      class: File.basename(f).gsub(FILE_TYPE_REGEX, ""),
                      tests: tests_from(f) }
  end

  strip_empty(test_details)
end

#test_distributionObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 34

def test_distribution
  test_distribution_check
  tests_arr = []
  case @config[:test_distribution]
  when "package"
    test_data.each { |type| tests_arr << type[:package] }
  when 'class', 'shard'
    test_data.each { |type| tests_arr << "#{type[:package]}.#{type[:class]}" }
  else
    test_data.each do |type|
      type[:tests].each { |test| tests_arr << "#{type[:package]}.#{type[:class]}##{test}" }
    end
  end
  tests_arr.uniq
end

#test_distribution_checkObject



50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 50

def test_distribution_check
  return @config[:test_distribution] if @config[:test_distribution].kind_of?(Array)

  distribution_types = %w[class testCase package shard]
  unless distribution_types.include?(@config[:test_distribution]) || @config[:test_distribution].nil?
    UI.user_error!("#{@config[:test_distribution]} is not a valid method of test distribution")
  end
end

#tests_from(path) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/fastlane/plugin/saucectl/helper/espresso.rb', line 65

def tests_from(path)
  stdout, = find(path, "@Test")
  test_cases = []
  stdout.split.each do |line|
    test_cases << line.match(TEST_FUNCTION_REGEX).to_s.gsub(/[()]/, "") if line =~ TEST_FUNCTION_REGEX
  end
  strip_skipped(path, test_cases)
end