/usr/lib/ruby/vendor_ruby/test/unit/exception-handler.rb is in ruby-test-unit 3.2.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | module Test
module Unit
module ExceptionHandler
@@exception_handlers = []
class << self
def exception_handlers
@@exception_handlers
end
def included(base)
base.extend(ClassMethods)
observer = Proc.new do |test_case, _, _, value, method_name|
if value
@@exception_handlers.unshift(method_name)
else
@@exception_handlers.delete(method_name)
end
end
base.register_attribute_observer(:exception_handler, &observer)
end
end
module ClassMethods
def exception_handlers
ExceptionHandler.exception_handlers
end
# @overload exception_handler(method_name)
# Add an exception handler method.
#
# @param method_name [Symbol]
# The method name that handles exception raised in tests.
# @return [void]
#
# @overload exception_handler(&callback)
# Add an exception handler.
#
# @yield [test, exception]
# Gives the test and the exception.
# @yieldparam test [Test::Unit::TestCase]
# The test where the exception is raised.
# @yieldparam exception [Exception]
# The exception that is raised in running the test.
# @yieldreturn [Boolean]
# Whether the handler handles the exception or not.
# The handler must return _true_ if the handler handles
# test exception, _false_ otherwise.
# @return [void]
#
# This is a public API for developers who extend test-unit.
def exception_handler(*method_name_or_handlers, &block)
if block_given?
exception_handlers.unshift(block)
else
method_name_or_handlers.each do |method_name_or_handler|
if method_name_or_handler.respond_to?(:call)
handler = method_name_or_handler
exception_handlers.unshift(handler)
else
method_name = method_name_or_handler
attribute(:exception_handler, true, {}, method_name)
end
end
end
end
def unregister_exception_handler(*method_name_or_handlers)
method_name_or_handlers.each do |method_name_or_handler|
if method_name_or_handler.respond_to?(:call)
handler = method_name_or_handler
exception_handlers.delete(handler)
else
method_name = method_name_or_handler
attribute(:exception_handler, false, {}, method_name)
end
end
end
end
end
end
end
|