From 244e45ad61f054e807eb1eb17f8300cb85460969 Mon Sep 17 00:00:00 2001 From: Chris Stevenson Date: Mon, 23 Jul 2012 23:18:20 -0700 Subject: [PATCH 1/4] Add support for unit testing Detect failing unit tests and report them as errors in the build. Show a detailed warning and fail the build if the RunPlatformUnitTests script error is detected. See here: http://www.stewgleadow.com/blog/2012/02/09/running-ocunit-and-kiwi-tests-on-the-command-line/ --- lib/xcode_build/translations.rb | 1 + lib/xcode_build/translations/unit_testing.rb | 37 ++++++++++++++ .../unit_testing_translations_spec.rb | 50 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 lib/xcode_build/translations/unit_testing.rb create mode 100644 spec/translations/unit_testing_translations_spec.rb 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..f60d2f0 --- /dev/null +++ b/lib/xcode_build/translations/unit_testing.rb @@ -0,0 +1,37 @@ +module XcodeBuild + module Translations + module UnitTesting + +RUN_UNIT_TESTS_ERROR = < [{ + :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..adf8d94 --- /dev/null +++ b/spec/translations/unit_testing_translations_spec.rb @@ -0,0 +1,50 @@ +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 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.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 + + end +end \ No newline at end of file From 51fa8a99908ad178ac4e1dd75ce0d48058718fc9 Mon Sep 17 00:00:00 2001 From: Chris Stevenson Date: Tue, 24 Jul 2012 10:36:49 -0700 Subject: [PATCH 2/4] Add build error for the "Termination since there is no workspace." error. In this scenario the build reports as passed even though no tests have been run. This is due to a build configuration error. Make sure the error is reported and the build fails. --- lib/xcode_build/translations/unit_testing.rb | 18 +++++++++++++ .../unit_testing_translations_spec.rb | 27 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/xcode_build/translations/unit_testing.rb b/lib/xcode_build/translations/unit_testing.rb index f60d2f0..31ddaa5 100644 --- a/lib/xcode_build/translations/unit_testing.rb +++ b/lib/xcode_build/translations/unit_testing.rb @@ -8,12 +8,21 @@ module UnitTesting 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 = < [{ + :file => file, + :line => line.to_i, + :char => char.to_i, + :message => message + }]) + end + end register_translation :unit_testing, UnitTesting diff --git a/spec/translations/unit_testing_translations_spec.rb b/spec/translations/unit_testing_translations_spec.rb index adf8d94..c1927df 100644 --- a/spec/translations/unit_testing_translations_spec.rb +++ b/spec/translations/unit_testing_translations_spec.rb @@ -19,7 +19,7 @@ translation.stub(:building?).and_return(true) end - it "notifies build failed if the RunUnitTests script has not been fixed" do + 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 @@ -46,5 +46,30 @@ 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 end end \ No newline at end of file From 526ab04be767ae7f7ad28af191f5a3bfbac27332 Mon Sep 17 00:00:00 2001 From: Chris Stevenson Date: Thu, 2 Aug 2012 17:08:04 -0700 Subject: [PATCH 3/4] Hacked in a test progress piece. We need a bit more than this but it is a start. --- .../formatters/progress_formatter.rb | 12 +++++++++- lib/xcode_build/translations/unit_testing.rb | 13 +++++++++-- .../unit_testing_translations_spec.rb | 23 +++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) 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/translations/unit_testing.rb b/lib/xcode_build/translations/unit_testing.rb index 31ddaa5..2afe8f4 100644 --- a/lib/xcode_build/translations/unit_testing.rb +++ b/lib/xcode_build/translations/unit_testing.rb @@ -23,8 +23,17 @@ def attempt_to_translate(line) 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\.$/ - @in_tests = true + 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 diff --git a/spec/translations/unit_testing_translations_spec.rb b/spec/translations/unit_testing_translations_spec.rb index c1927df..96dd695 100644 --- a/spec/translations/unit_testing_translations_spec.rb +++ b/spec/translations/unit_testing_translations_spec.rb @@ -33,6 +33,9 @@ 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 @@ -71,5 +74,25 @@ 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 From d29ebeb5fc4c11f97b42a09126304485c5af492d Mon Sep 17 00:00:00 2001 From: David Robles Date: Fri, 6 Sep 2013 09:36:40 -0700 Subject: [PATCH 4/4] Add archive path. --- lib/xcode_build/tasks/build_task.rb | 2 ++ 1 file changed, 2 insertions(+) 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}"