ruby-changes:55861
From: Nobuyoshi <ko1@a...>
Date: Mon, 27 May 2019 11:08:53 +0900 (JST)
Subject: [ruby-changes:55861] Nobuyoshi Nakada: 0aa9b003de (trunk): context.rb: hide wrapping lines
https://git.ruby-lang.org/ruby.git/commit/?id=0aa9b003de From 0aa9b003de353e690f31ba59ca0a2db1df51b8bf Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 27 May 2019 11:05:51 +0900 Subject: 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. diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 571df2c..b7b2230 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -397,7 +397,8 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/context.rb#L397 def evaluate(line, line_no, exception: nil) # :nodoc: @line_no = line_no 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) end set_last_value(@workspace.evaluate(self, line, irb_path, line_no)) diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index 96e6fbf..8b245d1 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -52,6 +52,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L52 } assert_equal('foo', e.message) 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 def test_eval_input -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/