Permalink
Browse files

Remove old ocunit report parser

  • Loading branch information...
1 parent 400e2c6 commit 20f2a0d7e407a9e6b82b4b5ae6071436d3640d68 @rayh committed Apr 16, 2012
Showing with 2 additions and 334 deletions.
  1. +2 −0 Rakefile
  2. +0 −178 lib/xcode/test/ocunit_report_parser.rb
  3. +0 −156 spec/test_report_spec.rb
View
@@ -4,10 +4,12 @@ require "yard/rake/yardoc_task"
task :default => [:specs, :build]
+desc "Run specs"
task :specs do
system "rspec --color --format d --tag ~integration"
end
+desc "Run integration tests"
task :integration do
system "rspec --color --format d --tag integration"
end
@@ -1,178 +0,0 @@
-require 'time'
-require 'fileutils'
-require 'xcode/test/suite_result'
-require 'xcode/test/test_result'
-
-module Xcode
- module Test
-
- module Formatters
- end
-
- class OCUnitReportParser
-
- attr_reader :reports, :end_time, :start_timel
- attr_accessor :debug, :formatters
-
- def initialize
- @debug = false
- @exit_code = 0
- @reports = []
- @formatters = []
- @failed = false
- @start_time = nil
- @end_time = nil
- @unexpected = false
-
- add_formatter :junit, 'test-reports'
- add_formatter :stdout
- end
-
- def unexpected?
- @unexpected
- end
-
- def succeed?
- !self.failed?
- end
-
- def failed?
- @failed or @unexpected
- end
-
- def finished?
- !@end_time.nil?
- end
-
- def duration
- return 0 if @start_time.nil?
- return Time.now - @start_time if @end_time.nil?
- @end_time - @start_time
- end
-
- def add_formatter(format, *args)
- require "xcode/test/formatters/#{format.to_s}_formatter"
- formatter = Formatters.const_get("#{format.to_s.capitalize}Formatter").new(*args)
- @formatters << formatter
- end
-
- def flush
- return if finished?
-
- # if there is a current, unfinished test - fail it
- unless current_test.nil? or current_test.passed?
- fail_current_test(0)
- @failed = true
- end
-
- # if there is a current suite which isnt finished - finish it
- unless current_suite.nil? or current_suite.finished?
- @failed = true # It may not have failed, but we want to indicate an unexpected end
- current_suite.finish
- notify_formatters(:after_suite, current_suite)
- end
-
- # finish all tests
- @end_time = Time.now
- notify_formatters(:after, self)
- end
-
- def <<(piped_row)
- puts piped_row if @debug
-
- case piped_row.force_encoding("UTF-8")
-
- when /Test Suite '(\S+)'.*started at\s+(.*)/
- name = $1
- time = Time.parse($2)
- if name=~/\//
- # all tests begin
- @start_time = Time.now
- notify_formatters(:before, self)
- else
- @reports << SuiteResult.new(name, time)
- notify_formatters(:before_suite, current_suite)
- end
-
- when /Test Suite '(\S+)'.*finished at\s+(.*)./
- time = Time.parse($2)
- name = $1
- if name=~/\//
- # all tests ended
- @end_time = Time.now
- notify_formatters(:after, self)
- else
- @reports.last.finish(time)
- notify_formatters(:after_suite, current_suite)
- end
-
- when /Test Case '-\[\S+\s+(\S+)\]' started./
- test = TestResult.new($1, current_suite)
- @reports.last.tests << test
- notify_formatters(:before_test, test)
-
- when /Test Case '-\[\S+\s+(\S+)\]' passed \((.*) seconds\)/
- @reports.last.tests.last.passed($2.to_f)
- notify_formatters(:after_test, current_test)
-
- when /(.*): error: -\[(\S+) (\S+)\] : (.*)/
- current_test.add_error($4,$1)
- @failed = true
- # notify_formatters(:after_test, @reports.last.tests.last)
-
- when /Test Case '-\[\S+ (\S+)\]' failed \((\S+) seconds\)/
- fail_current_test($2.to_f)
- @failed = true
-
- # when /failed with exit code (\d+)/,
- when /BUILD FAILED/
- flush
-
- when /Segmentation fault/
- @unexpected=true
-
- when /Run test case (\w+)/
- # ignore
- when /Run test suite (\w+)/
- # ignore
- when /Executed (\d+) test, with (\d+) failures \((\d+) unexpected\) in (\S+) \((\S+)\) seconds/
- # ignore
- else
- append_line_to_current_test piped_row
- end # case
-
- end # <<
-
- private
-
- def notify_formatters(event, obj=nil)
- @formatters.each do |f|
- f.send event, obj if f.respond_to? event
- end
- end
-
- def current_suite
- @reports.last
- end
-
- def current_test
- @reports.last.tests.last unless current_suite.nil?
- end
-
- def fail_current_test(duration=0)
- return if current_test.nil?
-
- current_test.failed(duration)
- notify_formatters(:after_test, current_test)
- end
-
- def append_line_to_current_test(line)
- return if current_suite.nil? or !current_suite.end_time.nil?
- return if current_test.nil?
- current_test << line
- end
-
-
- end # OCUnitReportParser
- end # Test
-end # Xcode
View
@@ -1,156 +0,0 @@
-require 'rspec'
-require 'xcoder'
-
-describe Xcode::Test::OCUnitReportParser do
-
- def example_report
- t = Xcode::Test::OCUnitReportParser.new
- yield(t) if block_given?
-
- t << "Run test suite AnExampleTestSuite"
- t << "Test Suite 'AnExampleTestSuite' started at 2012-02-10 00:37:04 +0000"
-
- t << "Run test case anExampleTest1"
- t << "Test Case '-[AnExampleTestSuite anExampleTest1]' started."
- t << "Test Case '-[AnExampleTestSuite anExampleTest1]' passed (0.003 seconds)."
-
- t << "Run test case anExampleTest2"
- t << "Test Case '-[AnExampleTestSuite anExampleTest2]' started."
- t << "Test Case '-[AnExampleTestSuite anExampleTest2]' passed (0.003 seconds)."
-
- t << "Test Suite 'AnExampleTestSuite' finished at 2012-02-10 00:37:04 +0000."
- t << "Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds"
-
- t
- end
-
- def example_failing_report
- t = Xcode::Test::OCUnitReportParser.new
- t << "Run test suite AnExampleTestSuite"
- t << "Test Suite 'AnExampleTestSuite' started at 2012-02-10 00:37:04 +0000"
- t << "Test Case '-[AnExampleTestSuite aFailingTest]' started."
- yield(t) if block_given?
- t << "Test Case '-[AnExampleTestSuite aFailingTest]' failed (2 seconds)."
- t << "Test Suite 'AnExampleTestSuite' finished at 2012-02-10 00:37:04 +0000."
- t << "Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds"
- t
- end
-
- it "should capture output for a test case" do
- t = example_failing_report do |parser|
- parser << '2012-02-17 15:03:06.521 otest[24979:7803] line1'
- parser << '2012-02-17 15:03:06.521 otest[24979:7803] line2'
- parser << '2012-02-17 15:03:06.521 otest[24979:7803] line3'
- parser << '2012-02-17 15:03:06.521 otest[24979:7803] line4'
- parser << '/Some/Path/To/Test.m:1234: error: -[AnExampleTestSuite aFailingTest] : This is an error message'
- end
-
- failure = t.reports.first.tests[0]
- failure.passed?.should==false
- failure.errors.count.should==1
- failure.errors[0][:data].count.should==4
- failure.errors[0][:data][0].should=~/line1/
- failure.errors[0][:data][1].should=~/line2/
- failure.errors[0][:data][2].should=~/line3/
- failure.errors[0][:data][3].should=~/line4/
- end
-
- it "should capture errors reported during a test" do
- t = example_failing_report do |parser|
- parser << '/Some/Path/To/Test.m:1234: error: -[AnExampleTestSuite aFailingTest] : This is an error message'
- end
-
- failure = t.reports.first.tests[0]
- failure.passed?.should==false
- failure.errors.count.should==1
- failure.errors[0][:message].should=='This is an error message'
- failure.errors[0][:location].should=='/Some/Path/To/Test.m:1234'
- end
-
- it "should create a test case" do
- t = example_report
- t.reports.count.should==1
- t.reports.first.name.should=="AnExampleTestSuite"
- t.reports.first.start_time.should==Time.parse("2012-02-10 00:37:04 +0000")
- t.reports.first.end_time.should==Time.parse("2012-02-10 00:37:04 +0000")
- end
-
- it "should detect a passing report" do
- t = example_report
- t.failed?.should==false
- end
-
- it "should detect a failing report" do
- t = example_failing_report
- t.failed?.should==true
- end
-
- it "should record a failure" do
- t = example_failing_report
- t.reports.first.total_failed_tests.should==1
- end
-
- it "should create a test case with some tests" do
- t = example_report
-
- t.reports.count.should==1
- t.reports.first.tests.count.should==2
- t.reports.first.tests[0].name.should=='anExampleTest1'
- t.reports.first.tests[0].time.should==0.003
- t.reports.first.tests[0].passed?.should==true
-
- t.reports.first.tests[1].name.should=='anExampleTest2'
- t.reports.first.tests[1].time.should==0.003
- t.reports.first.tests[1].passed?.should==true
- end
-
- it "should capture failed build" do
- t = Xcode::Test::OCUnitReportParser.new
- t << "Run test suite AnExampleTestSuite"
- t << "Test Suite 'AnExampleTestSuite' started at 2012-02-10 00:37:04 +0000"
- t << "Run test case anExampleTest1"
- t << "Test Case '-[AnExampleTestSuite anExampleTest1]' started."
- t << "/Path/To/Project/Tests/YPKeywordSuggestHandlerTest.m:45: error: -[AnExampleTestSuite anExampleTest1] : 'An example test spec' [FAILED], mock received unexpected message -setSuspended: 1 "
- t << "/Developer/Tools/RunPlatformUnitTests.include: line 415: 32225 Bus error: 10 \"${THIN_TEST_RIG}\" \"${OTHER_TEST_FLAGS}\" \"${TEST_BUNDLE_PATH}\""
- t << "/Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/Developer/usr/bin/otest' exited abnormally with code 138 (it may have crashed)."
-
- t.flush
- t.failed?.should==true
- t.finished?.should==true
- failure = t.reports.first.tests[0]
- failure.passed?.should==false
- failure.data.count.should==2
- failure.data[0].should=~/32225 Bus error: 10/
- failure.data[1].should=~/Test rig/
- end
-
- it "should not fail due to Unicode characters" do
- expect do
- parser = Xcode::Test::OCUnitReportParser.new
- string = "2012-04-09 16:56:32.682 otest[81203:7803] E restkit.object_mapping:RKObjectMappingOperation.m:248 Validation failed while mapping attribute at key path boolString to value FAIL. Error: The operation couldn\xE2\x80\x99t be completed. (org.restkit.RestKit.ErrorDomain error 1003.)"
- string.force_encoding("US-ASCII")
- parser << string
- end.not_to raise_error
- end
-
- context "Junit output" do
-
- it "should write out reports in junit format" do
- report_dir = "#{File.dirname(__FILE__)}/test-reports"
- FileUtils.rm_rf report_dir
-
- t = example_report do |t|
- t.formatters = []
- t.add_formatter :junit, report_dir
- end
-
- files = Dir["#{report_dir}/*.xml"]
- files.count.should==1
- files.first.should=~/TEST-AnExampleTestSuite.xml$/
-
- # FIXME: parse the report
- end
-
- end
-
-end

0 comments on commit 20f2a0d

Please sign in to comment.