lib/test/unit/testcase.rb in test-unit-3.1.5 vs lib/test/unit/testcase.rb in test-unit-3.1.6

- old
+ new

@@ -18,10 +18,11 @@ require 'test/unit/priority' require 'test/unit/data' require 'test/unit/testsuite' require 'test/unit/test-suite-creator' require 'test/unit/assertion-failed-error' +require 'test/unit/auto-runner-loader' require 'test/unit/util/backtracefilter' require 'test/unit/util/output' require 'test/unit/util/method-owner-finder' module Test @@ -102,11 +103,10 @@ DESCENDANTS = [] # :nodoc: AVAILABLE_ORDERS = [:alphabetic, :random, :defined] # :nodoc: class << self def inherited(sub_class) # :nodoc: - require "test/unit" DESCENDANTS << sub_class super end @@added_method_names = {} @@ -118,20 +118,26 @@ attribute(:redefined, {:backtrace => caller}, {}, stringified_name) end source_location = find_attribute(stringified_name, :source_location) if source_location path, line = source_location + elsif respond_to?(:caller_locations, true) + location = caller_locations(1, 1)[0] + path = location.absolute_path || location.path + line = location.lineno else + # TODO: Remove me when Ruby 1.9 support is dropped path, line, = caller[0].split(/:(\d+)/, 2) line = line.to_i if line end method_locations << { :method_name => stringified_name, :path => File.expand_path(path), :line => line, } added_method_names[stringified_name] = true + AutoRunnerLoader.check(self, stringified_name) end def added_method_names # :nodoc: (@@added_method_names[self] ||= {}).keys end @@ -279,10 +285,13 @@ end define_method(method_name, &block) else targets = test_description_or_targets attribute(:test, true, {}, *targets) + targets.each do |target| + AutoRunnerLoader.check(self, target) + end end end # Describes a test. # @@ -451,17 +460,34 @@ begin @_result = result @internal_data.test_started yield(STARTED, name) yield(STARTED_OBJECT, self) + processed_exception_in_setup = false begin - run_setup - run_test - run_cleanup - add_pass + catch do |tag| + run_setup do + begin + run_test + run_cleanup + add_pass + rescue Exception + @internal_data.interrupted + unless handle_exception($!) + processed_exception_in_setup = true + raise + end + throw(tag) + end + end + end rescue Exception - @internal_data.interrupted - raise unless handle_exception($!) + if processed_exception_in_setup + raise + else + @internal_data.interrupted + raise unless handle_exception($!) + end ensure begin run_teardown rescue Exception raise unless handle_exception($!)