Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for parsing (OCUnit) unit tests #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/xcode_build/formatters/progress_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ def build_started(build)
def build_step_finished(step)
report_step_finished(step)
end


def test_step_started(step)
$stderr.puts "Hello World!!"
puts
puts(step.message)
end

def test_step(step)
puts(step.message)
end

def build_finished(build)
report_finished(build)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/xcode_build/tasks/build_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BuildTask < ::Rake::TaskLib
attr_accessor :invoke_from_within
attr_accessor :reporter_klass
attr_accessor :xcodebuild_log_path
attr_accessor :archive_path

def initialize(namespace = :xcode, &block)
@namespace = namespace
Expand Down Expand Up @@ -63,6 +64,7 @@ def build_opts
opts << "-arch #{arch}" if arch
opts << "-sdk #{sdk}" if sdk
opts << "-xcconfig #{xcconfig}" if xcconfig
opts << "-archivePath #{archive_path}" if archive_path

@build_settings.each do |setting, value|
opts << "#{setting}=#{value}"
Expand Down
1 change: 1 addition & 0 deletions lib/xcode_build/translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ def registered_translation(key)

require "xcode_build/translations/building"
require "xcode_build/translations/cleaning"
require "xcode_build/translations/unit_testing"
64 changes: 64 additions & 0 deletions lib/xcode_build/translations/unit_testing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module XcodeBuild
module Translations
module UnitTesting

RUN_UNIT_TESTS_ERROR = <<EXPLANATION
xcodebuild-rb note: This message is caused by a limitation in
Apple's Xcode RunUnitScripts shell script. In order to run unit
tests from the command line you need to edit this script as
described here:
http://www.stewgleadow.com/blog/2012/02/09/running-ocunit-and-kiwi-tests-on-the-command-line/
EXPLANATION

TERMINATING_SINCE_THERE_IS_NO_WORKSPACE_EXPLANATION = <<EXPLANATION
xcodebuild-rb note: Make sure that you have a workspace set.
You might also need to explicitly specify the SDK.
EXPLANATION

def attempt_to_translate(line)
case line
when /^(.*)\:(.*)\: warning\: (Skipping tests; .*)$/
notify_build_error($1, $2, 0, "#{$3}\n#{RUN_UNIT_TESTS_ERROR}")
when /^(.*) (Unknown Device Type.*)$/
notify_build_warning(nil, 0, 0, $2)
when /^(Terminating since .*)$/
notify_build_error(nil, 0, 0, "#{$1}\n#{TERMINATING_SINCE_THERE_IS_NO_WORKSPACE_EXPLANATION}")
when /^Test Case .*started\.$/
puts
puts line
#notify_delegate(:test_step_started, :args => [{
# :message => line
# }])
when /^Test Case .*$/
puts line
#notify_delegate(:test_step, :args => [{
# :message => line
# }])
when /(.*)\:(\d+)\: error\: (.*)/
notify_build_error($1, $2, 0, $3)
end
end

def notify_build_error(file, line, char, message)
notify_delegate(:build_error_detected, :args => [{
:file => file,
:line => line.to_i,
:char => char.to_i,
:message => message
}])
end

def notify_build_warning(file, line, char, message)
notify_delegate(:build_warning_detected, :args => [{
:file => file,
:line => line.to_i,
:char => char.to_i,
:message => message
}])
end

end

register_translation :unit_testing, UnitTesting
end
end
98 changes: 98 additions & 0 deletions spec/translations/unit_testing_translations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
require 'spec_helper'

describe XcodeBuild::Translations::UnitTesting do
let(:delegate) { mock('delegate', :respond_to? => true) }
let(:translator) { XcodeBuild::OutputTranslator.new(delegate, :ignore_global_translations => true) }
let(:translation) { translator.translations[0] }

before do
translator.use_translation XcodeBuild::Translations::UnitTesting

delegate_should_respond_to(:beginning_translation_of_line)
delegate.stub(:beginning_translation_of_line).and_return(true)

translator.should have(1).translations
end

context "once a build start has been detected" do
before do
translation.stub(:building?).and_return(true)
end

it "notifies build failed and explanation if the RunUnitTests script has not been fixed" do
delegate.should_receive(:build_error_detected) do |hash|
hash[:file].should == "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/Tools/RunPlatformUnitTests"
hash[:line].should == 95
hash[:char].should == 0
hash[:message].should =~ /Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests \(TEST_HOST set\)\./
hash[:message].should =~ /xcodebuild-rb note\:/
end
translator << "\n\n\n"
translator << "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/Tools/RunPlatformUnitTests:95: warning: Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."
end

it "notifies build error if a test fails" do

delegate.stub(:test_step_started)
delegate.stub(:test_step)

delegate.should_receive(:build_error_detected) do |hash|
hash[:file].should == "/Users/chris/Projects/blah/blah/BlahTests/BlahTests.m"
hash[:line].should == 31
hash[:char].should == 0
hash[:message].should == "-[BlahTests testExample] : Expected <2>, but was <1>"
end

translator << "\n\n\n"
translator << "Test Case '-[BlahTests testExample]' started."
translator << "/Users/chris/Projects/blah/blah/BlahTests/BlahTests.m:31: error: -[BlahTests testExample] : Expected <2>, but was <1>"
translator << "Test Case '-[BlahTests testExample]' failed (0.000 seconds)."
end

it "notifies build warning for 'Unknown Device Type.'" do

delegate.should_receive(:build_warning_detected) do |hash|
hash[:file].should be_nil
hash[:line].should == 0
hash[:char].should == 0
hash[:message].should =~ /Unknown Device Type/
end
translator << "\n\n\n"
translator << "2012-07-23 15:46:33.589 Blah[23806:11603] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size"
end

it "notifies build error and explanation for 'Terminating since there is no workspace.'" do

delegate.should_receive(:build_error_detected) do |hash|
hash[:file].should be_nil
hash[:line].should == 0
hash[:char].should == 0
hash[:message].should =~ /Terminating since there is no workspace/
hash[:message].should =~ /xcodebuild-rb note\:/
end

translator << "\n\n\n"
translator << "Terminating since there is no workspace."
end

it "shows test case started messages" do

delegate.should_receive(:test_step_started) do |hash|
hash[:message].should == "Test Case '-[BlahTests testExample]' started."
end

translator << "\n\n\n"
translator << "Test Case '-[BlahTests testExample]' started."
end

it "shows test case messages" do

delegate.should_receive(:test_step) do |hash|
hash[:message].should == "Test Case '-[BlahTests testExample]' failed for some reason."
end

translator << "\n\n\n"
translator << "Test Case '-[BlahTests testExample]' failed for some reason."
end
end
end