Added more meaningful output when a test dies before it can be run
This commit is contained in:
parent
db33cc8e56
commit
fbd1e9f6e2
|
@ -79,6 +79,14 @@ module Hydra #:nodoc:
|
||||||
end
|
end
|
||||||
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
|
# Run all the Test::Unit Suites in a ruby file
|
||||||
def run_test_unit_file(file)
|
def run_test_unit_file(file)
|
||||||
begin
|
begin
|
||||||
|
@ -88,7 +96,7 @@ module Hydra #:nodoc:
|
||||||
return ex.to_s
|
return ex.to_s
|
||||||
rescue Exception => ex
|
rescue Exception => ex
|
||||||
trace "Error requiring #{file} [#{ex.to_s}]"
|
trace "Error requiring #{file} [#{ex.to_s}]"
|
||||||
return ex.to_s
|
return format_ex_in_file(file, ex)
|
||||||
end
|
end
|
||||||
output = []
|
output = []
|
||||||
@result = Test::Unit::TestResult.new
|
@result = Test::Unit::TestResult.new
|
||||||
|
@ -100,7 +108,7 @@ module Hydra #:nodoc:
|
||||||
begin
|
begin
|
||||||
klasses.each{|klass| klass.suite.run(@result){|status, name| ;}}
|
klasses.each{|klass| klass.suite.run(@result){|status, name| ;}}
|
||||||
rescue => ex
|
rescue => ex
|
||||||
output << ex.to_s
|
output << format_ex_in_file(file, ex)
|
||||||
end
|
end
|
||||||
|
|
||||||
return output.join("\n")
|
return output.join("\n")
|
||||||
|
|
|
@ -23,13 +23,28 @@ class MasterTest < Test::Unit::TestCase
|
||||||
# this test simulates what happens when we have 2 tests with the same
|
# this test simulates what happens when we have 2 tests with the same
|
||||||
# class name but with different parent classes. This can happen when
|
# class name but with different parent classes. This can happen when
|
||||||
# we have a functional and an integration test class with the same name.
|
# 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')
|
sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb')
|
||||||
Hydra::Master.new(
|
Hydra::Master.new(
|
||||||
# we want the actual test to run last to make sure the runner can still run tests
|
# 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],
|
: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 File.exists?(target_file)
|
||||||
assert_equal "HYDRA", File.read(target_file)
|
assert_equal "HYDRA", File.read(target_file)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue