Fix Ctrl-D in nested pry's

I'm not convinced this is the correct fix, but it seems to mostly
preserve existing behaviour.
This commit is contained in:
Conrad Irwin 2012-12-28 10:00:33 -08:00
parent bf3024bc73
commit a28b2b087c
2 changed files with 21 additions and 12 deletions

View File

@ -258,7 +258,10 @@ class Pry
exception = catch(:raise_up) do
exit_value = catch(:breakout) do
handle_line(line)
return true
# We use 'return !@stopped' here instead of 'return true' so that if
# handle_line has stopped this pry instance (e.g. by opening _pry_.repl and
# then popping all the bindings) we still exit immediately.
return !@stopped
end
exception = false
end

View File

@ -36,17 +36,23 @@ describe Pry::DEFAULT_CONTROL_D_HANDLER do
end
it "breaks out of the parent session" do
pry_tester(:outer).simulate_repl do |o|
o.context = :inner
o.simulate_repl { |i|
i.eval('_pry_.current_context.eval("self")').should == :inner
i.eval('_pry_.binding_stack.size').should == 2
i.eval('_pry_.eval(nil)')
i.eval('_pry_.binding_stack.size').should == 1
i.eval('_pry_.current_context.eval("self")').should == :outer
i.eval 'throw :breakout'
}
o.eval 'exit-all'
ReplTester.start do
input 'Pry::REPL.new(_pry_, :target => 10).start'
output ''
prompt(/10.*> $/)
input 'self'
output '=> 10'
input nil # Ctrl-D
output ''
input 'self'
output '=> main'
input nil # Ctrl-D
output '=> nil' # Exit value of nested REPL.
assert_exited
end
end
end