зеркало из https://github.com/github/ruby.git
[ruby/irb] Handle handle_exception's exception
(https://github.com/ruby/irb/pull/780) https://github.com/ruby/irb/commit/d42138c477
This commit is contained in:
Родитель
ecdb112881
Коммит
11d7c75fb3
|
@ -743,7 +743,14 @@ module IRB
|
|||
message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
|
||||
puts message
|
||||
end
|
||||
print "Maybe IRB bug!\n" if irb_bug
|
||||
puts 'Maybe IRB bug!' if irb_bug
|
||||
rescue Exception => handler_exc
|
||||
begin
|
||||
puts exc.inspect
|
||||
puts "backtraces are hidden because #{handler_exc} was raised when processing them"
|
||||
rescue Exception
|
||||
puts 'Uninspectable exception occurred'
|
||||
end
|
||||
end
|
||||
|
||||
# Evaluates the given block using the given +path+ as the Context#irb_path
|
||||
|
|
|
@ -4,8 +4,8 @@ require "tmpdir"
|
|||
require_relative "helper"
|
||||
|
||||
module TestIRB
|
||||
class RaiseNoBacktraceExceptionTest < TestCase
|
||||
def test_raise_exception
|
||||
class RaiseExceptionTest < TestCase
|
||||
def test_raise_exception_with_nil_backtrace
|
||||
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
|
||||
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, [])
|
||||
e = Exception.new("foo")
|
||||
|
@ -15,6 +15,27 @@ module TestIRB
|
|||
IRB
|
||||
end
|
||||
|
||||
def test_raise_exception_with_message_exception
|
||||
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
|
||||
expected = /#<Exception: foo>\nbacktraces are hidden because bar was raised when processing them/
|
||||
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
|
||||
e = Exception.new("foo")
|
||||
def e.message; raise 'bar'; end
|
||||
raise e
|
||||
IRB
|
||||
end
|
||||
|
||||
def test_raise_exception_with_message_inspect_exception
|
||||
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
|
||||
expected = /Uninspectable exception occurred/
|
||||
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, expected, [])
|
||||
e = Exception.new("foo")
|
||||
def e.message; raise; end
|
||||
def e.inspect; raise; end
|
||||
raise e
|
||||
IRB
|
||||
end
|
||||
|
||||
def test_raise_exception_with_invalid_byte_sequence
|
||||
pend if RUBY_ENGINE == 'truffleruby' || /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
|
Загрузка…
Ссылка в новой задаче