ruby-changes:65066
From: Nobuhiro <ko1@a...>
Date: Wed, 27 Jan 2021 15:02:17 +0900 (JST)
Subject: [ruby-changes:65066] e80e5a2f89 (master): [ruby/irb] use `RubyLex::TerminateLineInput` appropriately [Bug #17564]
https://git.ruby-lang.org/ruby.git/commit/?id=e80e5a2f89 From e80e5a2f897088bc5284ea61817a910d1d334652 Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI <nov@y...> Date: Sat, 23 Jan 2021 02:45:00 +0900 Subject: [ruby/irb] use `RubyLex::TerminateLineInput` appropriately [Bug #17564] * using the appropriciate exception instead of `break` so that the session can be continue after the `irb_source` and `irb_load` commands * suppress extra new line due to one more `#prompt` call https://github.com/ruby/irb/commit/bdefaa7cfd --- lib/irb.rb | 2 +- lib/irb/ruby-lex.rb | 2 +- test/irb/test_cmd.rb | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/irb.rb b/lib/irb.rb index 3f7f169..7f99974 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -525,7 +525,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L525 printf "Use \"exit\" to leave %s\n", @context.ap_name end else - print "\n" + print "\n" if @context.prompting? end end l diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 7b365a3..938e9d4 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -233,7 +233,7 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L233 @line.force_encoding(@io.encoding) yield @line, @exp_line_no end - break if @io.eof? + raise TerminateLineInput if @io.eof? @line = '' @exp_line_no = @line_no diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index b2246df..9febcc8 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -275,5 +275,59 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L275 assert_empty err assert_match(/\A=> 3\nCUSTOM is added\.\n=> nil\ncustom processing time: .+\n=> 3\n=> nil\n=> 3\n/, out) end + + def test_irb_source + IRB.init_config(nil) + File.write("#{@tmpdir}/a.rb", "a = 'hi'\n") + input = TestInputMethod.new([ + "a = 'bug17564'\n", + "a\n", + "irb_source '#{@tmpdir}/a.rb'\n", + "a\n", + ]) + IRB.conf[:PROMPT_MODE] = :SIMPLE + irb = IRB::Irb.new(IRB::WorkSpace.new, input) + IRB.conf[:MAIN_CONTEXT] = irb.context + out, err = capture_output do + irb.eval_input + end + assert_empty err + assert_pattern_list([ + /=> "bug17564"\n/, + /=> "bug17564"\n/, + />> a = 'hi'\n/, + /=> "hi"\n/, + />> \n/, + /=> nil\n/, + /=> "hi"\n/, + ], out) + end + + def test_irb_load + IRB.init_config(nil) + File.write("#{@tmpdir}/a.rb", "a = 'hi'\n") + input = TestInputMethod.new([ + "a = 'bug17564'\n", + "a\n", + "irb_load '#{@tmpdir}/a.rb'\n", + "a\n", + ]) + IRB.conf[:PROMPT_MODE] = :SIMPLE + irb = IRB::Irb.new(IRB::WorkSpace.new, input) + IRB.conf[:MAIN_CONTEXT] = irb.context + out, err = capture_output do + irb.eval_input + end + assert_empty err + assert_pattern_list([ + /=> "bug17564"\n/, + /=> "bug17564"\n/, + />> a = 'hi'\n/, + /=> "hi"\n/, + />> \n/, + /=> nil\n/, + /=> "bug17564"\n/, + ], out) + end end end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/