ruby-changes:51202
From: nobu <ko1@a...>
Date: Sat, 12 May 2018 18:13:51 +0900 (JST)
Subject: [ruby-changes:51202] nobu:r63409 (trunk): irb.rb: update `_`
nobu 2018-05-12 18:13:45 +0900 (Sat, 12 May 2018) New Revision: 63409 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63409 Log: irb.rb: update `_` * lib/irb.rb (IRB::Irb#eval_input): update `_` after exception. [ruby-core:86989] [Bug #14749] Modified files: trunk/lib/irb.rb trunk/test/irb/test_context.rb Index: test/irb/test_context.rb =================================================================== --- test/irb/test_context.rb (revision 63408) +++ test/irb/test_context.rb (revision 63409) @@ -22,6 +22,10 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L22 def eof? @line_no >= @list.size end + + def encoding + Encoding.default_external + end end def setup @@ -49,5 +53,24 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_context.rb#L53 assert_equal('foo', e.message) assert_same(e, @context.evaluate('$!', 1, exception: e)) end + + def test_eval_input + input = TestInputMethod.new([ + "raise 'Foo'\n", + "_\n", + "0\n", + "_\n", + ]) + irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) + out, err = capture_io do + irb.eval_input + end + assert_empty err + assert_pattern_list([:*, /RuntimeError \(.*Foo.*\).*\n/, + :*, /#<RuntimeError: Foo>\n/, + :*, /0$/, + :*, /0$/, + /\s*/], out) + end end end Index: lib/irb.rb =================================================================== --- lib/irb.rb (revision 63408) +++ lib/irb.rb (revision 63409) @@ -439,7 +439,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L439 # Evaluates input for this session. def eval_input - last_error = nil + exc = nil @scanner.set_prompt do |ltype, indent, continue, line_no| @@ -490,18 +490,17 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L490 signal_status(:IN_EVAL) do begin line.untaint - @context.evaluate(line, line_no, exception: last_error) + @context.evaluate(line, line_no, exception: exc) output_value if @context.echo? - exc = nil rescue Interrupt => exc rescue SystemExit, SignalException raise rescue Exception => exc + else + exc = nil + next end - if exc - last_error = exc - handle_exception(exc) - end + handle_exception(exc) end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/