[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
This commit is contained in:
parent
5b05b85d85
commit
e80e5a2f89
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user