From cb222198ce0a3cf3e8ad338339072dd8385d8592 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 15 Mar 2012 16:07:43 -0400 Subject: [PATCH] more error handling work and cleanup, more stable now --- lib/flowerbox.rb | 9 ++++++++- lib/flowerbox/reporter/console_base.rb | 1 + lib/flowerbox/result/failure_message.rb | 20 +++++++++++++++++--- lib/flowerbox/result/file_info.rb | 10 +++------- lib/flowerbox/run/test.rb | 2 ++ lib/flowerbox/runner/base.rb | 6 ++++-- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/flowerbox.rb b/lib/flowerbox.rb index b83ec6a..fdc870a 100644 --- a/lib/flowerbox.rb +++ b/lib/flowerbox.rb @@ -116,7 +116,14 @@ module Flowerbox end def cleanup! - browsers.values.each(&:close) + browsers.values.each do |browser| + begin + browser.close + rescue Errno::ECONNREFUSED => e + puts "Browser already closed." + end + end + @browsers = {} end end diff --git a/lib/flowerbox/reporter/console_base.rb b/lib/flowerbox/reporter/console_base.rb index 02c4cf2..7d1fdbe 100644 --- a/lib/flowerbox/reporter/console_base.rb +++ b/lib/flowerbox/reporter/console_base.rb @@ -20,6 +20,7 @@ module Flowerbox::Reporter puts result.name.join(" - ").foreground(:red) result.failures.each do |failure| puts " " + failure.message.foreground(:red) + " [" + failure.runners.join(',') + "] " + path_for(failure) + puts failure.stack.join("\n").foreground(:red) if failure.exception? end end diff --git a/lib/flowerbox/result/failure_message.rb b/lib/flowerbox/result/failure_message.rb index 56d1bdc..80b19bc 100644 --- a/lib/flowerbox/result/failure_message.rb +++ b/lib/flowerbox/result/failure_message.rb @@ -13,7 +13,13 @@ module Flowerbox::Result end def file - first_local_stack[%r{\(([^:]+\:\d+)}, 1] + file = first_local_stack + + if file['__F__'] + file[%r{^.*__F__/([^:]+:\d+)}, 1] + else + file[%r{\(([^:]+\:\d+)}, 1] + end end def runner @@ -24,10 +30,18 @@ module Flowerbox::Result @runners ||= [ runner ] end + def stack + @data['stack'] + end + def first_local_stack - @data['stack'][1..-1].find do |line| + @first_local_stack ||= stack[1..-1].find do |line| !system_files.any? { |file| line[%r{\(#{file}}] } - end || @data['stack'][1] || '' + end || stack[1] || '' + end + + def exception? + stack[0][%r{^.+Error: }] end end end diff --git a/lib/flowerbox/result/file_info.rb b/lib/flowerbox/result/file_info.rb index 1859d99..d41aafd 100644 --- a/lib/flowerbox/result/file_info.rb +++ b/lib/flowerbox/result/file_info.rb @@ -1,10 +1,6 @@ module Flowerbox::Result::FileInfo def translated_file - @translated_file ||= if actual_file_base = filename[%r{\.tmp/sprockets(.*)}, 1] - Dir[actual_file_base + "*"].first - else - filename - end + @translated_file ||= filename end def file_translated? @@ -12,7 +8,7 @@ module Flowerbox::Result::FileInfo end def filename - file.to_s.split(":").first + file.to_s.split(":").first || 'unknown' end def line_number @@ -20,7 +16,7 @@ module Flowerbox::Result::FileInfo @line_number = file.to_s.split(":")[1] @line_number = "~#{@line_number}" if file_translated? - @line_number + @line_number ||= "0" end alias :line :line_number diff --git a/lib/flowerbox/run/test.rb b/lib/flowerbox/run/test.rb index 12c9c43..779b552 100644 --- a/lib/flowerbox/run/test.rb +++ b/lib/flowerbox/run/test.rb @@ -23,6 +23,8 @@ module Flowerbox::Run runner_envs.each(&:cleanup) result_set.exitstatus + rescue Flowerbox::Runner::Base::RunnerDiedError + 255 end end end diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index 00626b7..08e2f3f 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -7,6 +7,8 @@ module Flowerbox MAX_COUNT = 50 + class RunnerDiedError < StandardError ; end + def initialize @results = ResultSet.new end @@ -18,9 +20,9 @@ module Flowerbox end if !finished? + puts "Something died hard. Here are the tests that did get run before Flowerbox died.".foreground(:red) puts tests.flatten.join("\n").foreground(:red) - cleanup - exit 1 + raise RunnerDiedError.new end end