diff --git a/lib/xcode_build/formatters/progress_formatter.rb b/lib/xcode_build/formatters/progress_formatter.rb index cc3afb6..0e7e696 100644 --- a/lib/xcode_build/formatters/progress_formatter.rb +++ b/lib/xcode_build/formatters/progress_formatter.rb @@ -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 diff --git a/lib/xcode_build/tasks/build_task.rb b/lib/xcode_build/tasks/build_task.rb index af92aab..2a645f6 100644 --- a/lib/xcode_build/tasks/build_task.rb +++ b/lib/xcode_build/tasks/build_task.rb @@ -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 @@ -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}" diff --git a/lib/xcode_build/translations.rb b/lib/xcode_build/translations.rb index 4a00543..5ec5901 100644 --- a/lib/xcode_build/translations.rb +++ b/lib/xcode_build/translations.rb @@ -18,3 +18,4 @@ def registered_translation(key) require "xcode_build/translations/building" require "xcode_build/translations/cleaning" +require "xcode_build/translations/unit_testing" diff --git a/lib/xcode_build/translations/unit_testing.rb b/lib/xcode_build/translations/unit_testing.rb new file mode 100644 index 0000000..2afe8f4 --- /dev/null +++ b/lib/xcode_build/translations/unit_testing.rb @@ -0,0 +1,64 @@ +module XcodeBuild + module Translations + module UnitTesting + +RUN_UNIT_TESTS_ERROR = < [{ + # :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 \ No newline at end of file diff --git a/spec/translations/unit_testing_translations_spec.rb b/spec/translations/unit_testing_translations_spec.rb new file mode 100644 index 0000000..96dd695 --- /dev/null +++ b/spec/translations/unit_testing_translations_spec.rb @@ -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 \ No newline at end of file