mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
context.rb: hide wrapping lines
* lib/irb/context.rb (IRB::Context#evaluate): separate the code from wrapping lines to propagate the given exception, not to show the wrapping lines when SyntaxError.
This commit is contained in:
parent
9840f52c77
commit
0aa9b003de
2 changed files with 7 additions and 1 deletions
|
@ -397,7 +397,8 @@ module IRB
|
||||||
def evaluate(line, line_no, exception: nil) # :nodoc:
|
def evaluate(line, line_no, exception: nil) # :nodoc:
|
||||||
@line_no = line_no
|
@line_no = line_no
|
||||||
if exception
|
if exception
|
||||||
line = "begin ::Kernel.raise _; rescue _.class; #{line}; end"
|
line_no -= 1
|
||||||
|
line = "begin ::Kernel.raise _; rescue _.class\n#{line}\n""end"
|
||||||
@workspace.local_variable_set(:_, exception)
|
@workspace.local_variable_set(:_, exception)
|
||||||
end
|
end
|
||||||
set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
|
set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
|
||||||
|
|
|
@ -52,6 +52,11 @@ module TestIRB
|
||||||
}
|
}
|
||||||
assert_equal('foo', e.message)
|
assert_equal('foo', e.message)
|
||||||
assert_same(e, @context.evaluate('$!', 1, exception: e))
|
assert_same(e, @context.evaluate('$!', 1, exception: e))
|
||||||
|
e = assert_raise(SyntaxError) {
|
||||||
|
@context.evaluate("1,2,3", 1, exception: e)
|
||||||
|
}
|
||||||
|
assert_match(/\A\(irb\):1:/, e.message)
|
||||||
|
assert_not_match(/rescue _\.class/, e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_eval_input
|
def test_eval_input
|
||||||
|
|
Loading…
Add table
Reference in a new issue