diff --git a/lib/hydra/runner.rb b/lib/hydra/runner.rb index 682092f..5205e1c 100644 --- a/lib/hydra/runner.rb +++ b/lib/hydra/runner.rb @@ -79,6 +79,14 @@ module Hydra #:nodoc: end end + def format_ex_in_file(file, ex) + "Error in #{file}:\n #{format_exception(ex)}" + end + + def format_exception(ex) + "#{ex.class.name}: #{ex.message}\n #{ex.backtrace.join("\n ")}" + end + # Run all the Test::Unit Suites in a ruby file def run_test_unit_file(file) begin @@ -88,7 +96,7 @@ module Hydra #:nodoc: return ex.to_s rescue Exception => ex trace "Error requiring #{file} [#{ex.to_s}]" - return ex.to_s + return format_ex_in_file(file, ex) end output = [] @result = Test::Unit::TestResult.new @@ -100,7 +108,7 @@ module Hydra #:nodoc: begin klasses.each{|klass| klass.suite.run(@result){|status, name| ;}} rescue => ex - output << ex.to_s + output << format_ex_in_file(file, ex) end return output.join("\n") diff --git a/test/master_test.rb b/test/master_test.rb index 09c6d4d..ca6091a 100644 --- a/test/master_test.rb +++ b/test/master_test.rb @@ -23,13 +23,28 @@ class MasterTest < Test::Unit::TestCase # this test simulates what happens when we have 2 tests with the same # class name but with different parent classes. This can happen when # we have a functional and an integration test class with the same name. - should "run even with a test that is invalidwill not require" do + should "run even with a test that will not require" do + class FileOutputListener < Hydra::Listener::Abstract + attr_accessor :output + def initialize(&block) + self.output = {} + end + + def file_end(file, output) + self.output[file] = output + end + end + + listener = FileOutputListener.new sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb') Hydra::Master.new( # we want the actual test to run last to make sure the runner can still run tests :files => [sync_test, conflicting_test_file, test_file], - :autosort => false + :autosort => false, + :listeners => [listener] ) + assert_match /superclass mismatch for class SyncTest/, listener.output[conflicting_test_file] + assert_match conflicting_test_file, listener.output[conflicting_test_file] assert File.exists?(target_file) assert_equal "HYDRA", File.read(target_file) end