From 9df65f3f639be346b8a05a3611bcb090c0d3a2ca Mon Sep 17 00:00:00 2001 From: Kris Kline Date: Tue, 11 Mar 2014 17:33:38 -0500 Subject: [PATCH] Support Getting Input From Text File If recieving xcode output from a file, need to add support for using 'each_line' instead of 'each' for ruby 1.9+. As of ruby 1.9.X, String#each is no longer supported - documentation: http://ruby-doc.org/core-1.9.3/String.html Also added a unit test to highlight the problem and show the fix --- bin/ocunit2junit | 8 +++++++- test/test_basic.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/ocunit2junit b/bin/ocunit2junit index 9f0cca0..f828c3e 100755 --- a/bin/ocunit2junit +++ b/bin/ocunit2junit @@ -46,7 +46,13 @@ class ReportParser private def parse_input - @piped_input.each do |piped_row| + if @piped_input.respond_to?(:each) + line_enumerator = @piped_input.each + elsif @piped_input.respond_to?(:each_line) + line_enumerator = @piped_input.each_line + end + + line_enumerator.each do |piped_row| if piped_row.respond_to?("encode!") temporary_encoding = (RUBY_VERSION == '1.9.2') ? 'UTF-8' : 'UTF-16' piped_row.encode!(temporary_encoding, 'UTF-8', :invalid => :replace, :replace => '') diff --git a/test/test_basic.rb b/test/test_basic.rb index 669deef..9adbd87 100644 --- a/test/test_basic.rb +++ b/test/test_basic.rb @@ -23,6 +23,13 @@ def test_output_to_reports_dir "The TestProject should be parsed in a TEST-TestProjectTests.xml report" end + def test_output_log_to_reports_dir + Helper.pipe_xcodebuild_log_to_ocunit2junit + + assert File.directory?(Helper.test_reports_output_path), + "Test reports driven from a log should be written to a 'test-reports' directory" + end + def test_report_content Helper.pipe_xcodebuild_to_ocunit2junit file = File.new Helper.test_reports_output_path + '/TEST-TestProjectTests.xml' @@ -61,6 +68,15 @@ def self.pipe_xcodebuild_to_ocunit2junit `pushd #{TEST_PATH}; xcodebuild -project #{xcodeproj} -scheme TestProject test | #{ocunit2junit}; popd` end + def self.pipe_xcodebuild_log_to_ocunit2junit + abs_file_path = File.expand_path(File.dirname(__FILE__)) + ocunit2junit = abs_file_path + '/../bin/ocunit2junit' + xcodeproj = abs_file_path + '/TestProject/TestProject.xcodeproj' + outputFile = abs_file_path + 'output.log' + `pushd #{TEST_PATH}; xcodebuild -project #{xcodeproj} -scheme TestProject test > #{outputFile}; cat #{outputFile} | #{ocunit2junit}; popd` + `rm #{outputFile}` + end + end end