module XCTestRunner::SchemeManager

Constants

BUILD_ACTION_ENTRY_TAG
BUILD_ACTION_TAG
TEMP_SCHEME
TEMP_SCHEME_NAME
TEST_REFERENCE_TAG

Public Instance Methods

add_build_action_entry_to(doc) click to toggle source
# File lib/xctest-runner/scheme-manager.rb, line 57
def add_build_action_entry_to(doc)
  buildable_reference = doc.get_elements(TEST_REFERENCE_TAG).first
  return false unless buildable_reference
  build_action = doc.get_elements(BUILD_ACTION_TAG).first
  return false unless build_action
  entries = build_action.add_element('BuildActionEntries')
  attributes = {
    'buildForTesting' => 'YES',
    'buildForRunning' => 'YES',
    'buildForProfiling' => 'NO',
    'buildForArchiving' => 'NO',
    'buildForAnalyzing' => 'NO',
  }
  entry = entries.add_element('BuildActionEntry', attributes)
  entry.add_element(buildable_reference.name, buildable_reference.attributes)
  true
end
copy_xcscheme_if_need(scheme) click to toggle source
# File lib/xctest-runner/scheme-manager.rb, line 19
def copy_xcscheme_if_need(scheme)
  return nil unless scheme
  scheme_path = scheme_path_for(scheme)
  return nil unless scheme_path
  find_xml_need_to_be_updated(scheme_path) do |doc|
    temp_scheme_path = File.dirname(scheme_path) << "/#{TEMP_SCHEME_NAME}"
    write_xml(doc, temp_scheme_path)
    return temp_scheme_path
  end
  nil
end
find_xml_need_to_be_updated(scheme_path, &block) click to toggle source
# File lib/xctest-runner/scheme-manager.rb, line 41
def find_xml_need_to_be_updated(scheme_path, &block)
  need_to_be_updated = false
  doc = REXML::Document.new(File.open(scheme_path))
  if doc.get_elements(BUILD_ACTION_ENTRY_TAG).empty?
    need_to_be_updated = add_build_action_entry_to(doc)
  else
    doc.elements.each(BUILD_ACTION_ENTRY_TAG) do |element|
      if element.attributes['buildForTesting'] != element.attributes['buildForRunning']
        element.attributes['buildForRunning'] = element.attributes['buildForTesting']
        need_to_be_updated = true
      end
    end
  end
  block.call(doc) if need_to_be_updated
end
remove_scheme(path) click to toggle source
# File lib/xctest-runner/scheme-manager.rb, line 82
def remove_scheme(path)
  File.unlink(path)
end
scheme_path_for(scheme) click to toggle source
# File lib/xctest-runner/scheme-manager.rb, line 31
def scheme_path_for(scheme)
  expect = "/#{scheme}.xcscheme"
  Find.find('.') do |path|
    if path.end_with? expect
      return path
    end
  end
  nil
end
temp_scheme() click to toggle source
# File lib/xctest-runner/scheme-manager.rb, line 15
def temp_scheme
  TEMP_SCHEME
end
write_xml(doc, path) click to toggle source
# File lib/xctest-runner/scheme-manager.rb, line 75
def write_xml(doc, path)
  File.open(path, 'w') do |f|
    f.sync = true
    f.write(doc)
  end
end