diff options
-rw-r--r-- | lib/irb.rb | 2 | ||||
-rw-r--r-- | lib/irb/ruby-lex.rb | 2 | ||||
-rw-r--r-- | test/irb/test_cmd.rb | 54 |
3 files changed, 56 insertions, 2 deletions
diff --git a/lib/irb.rb b/lib/irb.rb index 3f7f169c69..7f99974f28 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -525,7 +525,7 @@ module IRB 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 7b365a39cf..938e9d42a6 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -233,7 +233,7 @@ class RubyLex @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 b2246dfff5..9febcc8671 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -275,5 +275,59 @@ module TestIRB 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 |