class Scan::TestCommandGenerator

Responsible for building the fully working xcodebuild command

Public Class Methods

actions() click to toggle source
# File lib/scan/test_command_generator.rb, line 46
def actions
  config = Scan.config

  actions = []
  actions << :clean if config[:clean]
  actions << :build unless config[:skip_build]
  actions << :test

  actions
end
build_path() click to toggle source

The path to set the Derived Data to

# File lib/scan/test_command_generator.rb, line 112
def build_path
  unless Scan.cache[:build_path]
    day = Time.now.strftime("%F") # e.g. 2015-08-07

    Scan.cache[:build_path] = File.expand_path("~/Library/Developer/Xcode/Archives/#{day}/")
    FileUtils.mkdir_p Scan.cache[:build_path]
  end
  Scan.cache[:build_path]
end
destination() click to toggle source

Generate destination parameters

# File lib/scan/test_command_generator.rb, line 104
def destination
  unless Scan.cache[:destination]
    Scan.cache[:destination] = [*Scan.config[:destination]].map { |dst| "-destination '#{dst}'" }.join(' ')
  end
  Scan.cache[:destination]
end
generate() click to toggle source
# File lib/scan/test_command_generator.rb, line 5
def generate
  parts = prefix
  parts << "env NSUnbufferedIO=YES xcodebuild"
  parts += options
  parts += actions
  parts += suffix
  parts += pipe

  parts
end
options() click to toggle source
# File lib/scan/test_command_generator.rb, line 29
def options
  config = Scan.config

  options = []
  options += project_path_array
  options << "-sdk '#{config[:sdk]}'" if config[:sdk]
  options << destination # generated in `detect_values`
  options << "-derivedDataPath '#{config[:derived_data_path]}'" if config[:derived_data_path]
  options << "-resultBundlePath '#{result_bundle_path}'" if config[:result_bundle]
  options << "-enableCodeCoverage YES" if config[:code_coverage]
  options << "-enableAddressSanitizer YES" if config[:address_sanitizer]
  options << "-xcconfig '#{config[:xcconfig]}'" if config[:xcconfig]
  options << config[:xcargs] if config[:xcargs]

  options
end
pipe() click to toggle source
# File lib/scan/test_command_generator.rb, line 62
def pipe
  # During building we just show the output in the terminal
  # Check out the ReportCollector class for more xcpretty things
  pipe = ["| tee '#{xcodebuild_log_path}'"]

  if Scan.config[:output_style] == 'raw'
    return pipe
  end

  formatter = []
  if Scan.config[:formatter]
    formatter << "-f `#{Scan.config[:formatter]}`"
  elsif ENV.key?("TRAVIS")
    formatter << "-f `xcpretty-travis-formatter`"
    UI.success("Automatically switched to Travis formatter")
  end

  if Helper.colors_disabled?
    formatter << "--no-color"
  end

  if Scan.config[:output_style] == 'basic'
    formatter << "--no-utf"
  end

  if Scan.config[:output_style] == 'rspec'
    formatter << "--test"
  end

  return pipe << ["| xcpretty #{formatter.join(' ')}"]
end
prefix() click to toggle source
# File lib/scan/test_command_generator.rb, line 16
def prefix
  ["set -o pipefail &&"]
end
project_path_array() click to toggle source

Path to the project or workspace as parameter This will also include the scheme (if given) @return [Array] The array with all the components to join

# File lib/scan/test_command_generator.rb, line 23
def project_path_array
  proj = Scan.project.xcodebuild_parameters
  return proj if proj.count > 0
  UI.user_error!("No project/workspace found")
end
result_bundle_path() click to toggle source
# File lib/scan/test_command_generator.rb, line 122
def result_bundle_path
  unless Scan.cache[:result_bundle_path]
    Scan.cache[:result_bundle_path] = File.join(Scan.config[:output_directory], Scan.config[:scheme]) + ".test_result"
  end
  return Scan.cache[:result_bundle_path]
end
suffix() click to toggle source
# File lib/scan/test_command_generator.rb, line 57
def suffix
  suffix = []
  suffix
end
xcodebuild_log_path() click to toggle source

Store the raw file

# File lib/scan/test_command_generator.rb, line 95
def xcodebuild_log_path
  file_name = "#{Scan.project.app_name}-#{Scan.config[:scheme]}.log"
  containing = File.expand_path(Scan.config[:buildlog_path])
  FileUtils.mkdir_p(containing)

  return File.join(containing, file_name)
end