From 81c013081546b89f89c40b831258ff5f4046f9bb Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 8 Mar 2012 15:38:12 +1300 Subject: [PATCH] fixed bug where Command#run "cd .." would error * error was due to an extra space being appended to string, which messed up `cd` command parsing * fixed by applying a simple #rstrip; updated tests --- lib/pry/command.rb | 2 +- test/test_command_integration.rb | 83 +++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/lib/pry/command.rb b/lib/pry/command.rb index b8b96b81..bce46a1d 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -180,7 +180,7 @@ class Pry # @example # run "amend-line", "5", 'puts "hello world"' def run(command_string, *args) - complete_string = "#{command_string} #{args.join(" ")}" + complete_string = "#{command_string} #{args.join(" ")}".rstrip command_set.process_line(complete_string, context) end diff --git a/test/test_command_integration.rb b/test/test_command_integration.rb index 60d714f6..8417ba8b 100644 --- a/test/test_command_integration.rb +++ b/test/test_command_integration.rb @@ -199,7 +199,7 @@ describe "commands" do str_output = StringIO.new Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep (str_output.string =~ /:kept_hello/).should == nil - str_output.string !~ /=>/ +str_output.string !~ /=>/ end it 'should define a command that keeps its return value even when nil' do @@ -211,7 +211,7 @@ describe "commands" do str_output = StringIO.new Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep str_output.string.should =~ /nil/ - str_output.string.should =~ /=>/ + str_output.string.should =~ /=>/ end it 'should define a command that keeps its return value but does not return when value is void' do @@ -317,6 +317,83 @@ describe "commands" do klass.commands["help"].description.should == "blah" end + +describe "Pry::Command#run" do +it 'should allow running of commands with following whitespace' do + $_scratch = Object.new + o = Object.new + + set = Pry::CommandSet.new do + import Pry::Commands + command "test-run" do + run "cd / " + end + end + redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch", + "@nesting1 = _pry_.binding_stack.size", + "test-run", + "@obj = self", + "@nesting2 = _pry_.binding_stack.size", + "exit-all")) do + Pry.start(o, :commands => set) + end + + $_scratch.instance_variable_get(:@nesting1).should == 8 + o.instance_variable_get(:@obj).should == o + o.instance_variable_get(:@nesting2).should == 1 + $_scratch = nil +end + +it 'should allow running of cd command when contained in a single string' do + $_scratch = Object.new + o = Object.new + + set = Pry::CommandSet.new do + import Pry::Commands + command "test-run" do + run "cd /" + end + end + redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch", + "@nesting1 = _pry_.binding_stack.size", + "test-run", + "@obj = self", + "@nesting2 = _pry_.binding_stack.size", + "exit-all")) do + Pry.start(o, :commands => set) + end + + $_scratch.instance_variable_get(:@nesting1).should == 8 + o.instance_variable_get(:@obj).should == o + o.instance_variable_get(:@nesting2).should == 1 + $_scratch = nil +end + +it 'should allow running of cd command when split into array' do + $_scratch = Object.new + o = Object.new + + set = Pry::CommandSet.new do + import Pry::Commands + command "test-run" do + run "cd", "/" + end + end + redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch", + "@nesting1 = _pry_.binding_stack.size", + "test-run", + "@obj = self", + "@nesting2 = _pry_.binding_stack.size", + "exit-all")) do + Pry.start(o, :commands => set) + end + + $_scratch.instance_variable_get(:@nesting1).should == 8 + o.instance_variable_get(:@obj).should == o + o.instance_variable_get(:@nesting2).should == 1 + $_scratch = nil +end + it 'should run a command from within a command' do klass = Pry::CommandSet.new do command "v" do @@ -376,6 +453,8 @@ describe "commands" do end end +end + it 'should enable an inherited method to access opts and output and target, due to instance_exec' do klass = Pry::CommandSet.new do command "v" do