Skip to content

Commit

Permalink
use RubyLex::TerminateLineInput appropriately [Bug #17564]
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
no6v committed Jan 22, 2021
1 parent ec2947a commit bdefaa7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def eval_input
printf "Use \"exit\" to leave %s\n", @context.ap_name
end
else
print "\n"
print "\n" if @context.prompting?
end
end
l
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/ruby-lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def each_top_level_statement
@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

Expand Down
54 changes: 54 additions & 0 deletions test/irb/test_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,59 @@ def test_measure_with_custom
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

0 comments on commit bdefaa7

Please sign in to comment.