Skip to content
Browse files

Fix `exit` after previous syntax error in `exit` command.

Before this commit, the binding stack was cleared before evaluating
the user-given value for the `exit` command. If a syntax error happened
when `eval`ing it, the program would still be running with no elements
in the binding stack, causing next calls of `exit` to fail.
  • Loading branch information...
1 parent 6f03f92 commit 1dc68c9de99192a5e2ef3620c831b10ea3229b72 Renato Mascarenhas committed Apr 25, 2012
Showing with 10 additions and 1 deletion.
  1. +4 −1 lib/pry/default_commands/navigating_pry.rb
  2. +6 −0 test/test_default_commands/test_context.rb
View
5 lib/pry/default_commands/navigating_pry.rb
@@ -41,11 +41,14 @@ module DefaultCommands
end
command "exit-all", "End the current Pry session (popping all bindings) and returning to caller. Accepts optional return value. Aliases: !!@" do
+ # calculate user-given value
+ exit_value = target.eval(arg_string)
+
# clear the binding stack
_pry_.binding_stack.clear
# break out of the repl loop
- throw(:breakout, target.eval(arg_string))
+ throw(:breakout, exit_value)
end
alias_command "!!@", "exit-all"
View
6 test/test_default_commands/test_context.rb
@@ -77,6 +77,12 @@ def method; "moo"; end
it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit, and return user-given value' do
Pry.start(0, :input => StringIO.new("exit :john")).should == :john
end
+
+ it 'should break out the repl loop of Pry instance even after an exception in user-given value' do
+ redirect_pry_io(InputTester.new("exit = 42", "exit"), StringIO.new) do
+ ins = Pry.new.tap { |v| v.repl(0).should == nil }
+ end
+ end
end
describe "jump-to" do

0 comments on commit 1dc68c9

Please sign in to comment.
Something went wrong with that request. Please try again.