rayh / xcoder

ruby wrapper for Xcode build tools to aid automating builds
MIT License
412 stars 70 forks source link

Add KIF Output Parser #58

Closed blakewatters closed 11 years ago

blakewatters commented 11 years ago

This pull request adds an output parser for the KIF integration testing framework from Square (see https://github.com/square/KIF). There are a few minor changes under the hood that were necessary to enable the parser:

For reference, I am running this via ios-sim with a Rake task:

desc 'Run the GateGuru KIF integration tests suite'
task :integration do
  scheme = Xcode.workspace(:GateGuru).scheme('Integration Tests')

  # Execute the build quietly
  cmd = scheme.builder.xcodebuild
  cmd << "-sdk iphonesimulator"

  output = []
  begin
    puts "Building target..."
    Xcode::Shell.execute(cmd, false) do |line|
      raise line if line =~ /BUILD FAILED/
      output << line
    end
  rescue => e
    puts output.join("\n")
    raise e
  end

  # Run the Integration Tests
  report = Xcode::Test::Report.new
  cmd = Xcode::Shell::Command.new(%q{ios-sim launch "build/Products/Test-iphonesimulator/GateGuru (Integration Tests).app" --retina})

  report.add_formatter :stdout, { :color_output => true }
  report.add_formatter :junit, 'test-reports'

  parser = Xcode::Test::Parsers::KIFParser.new(report)

  begin
    puts "Executing suite via command #{cmd}"
    cmd.execute(false) do |line|
      parser << line
    end
  rescue Xcode::Shell::ExecutionError => e
    # FIXME: Perhaps we should always raise this?
    raise e if report.suites.count==0
  ensure
    parser.flush
  end
end