From 81a49a93e985a495841c54f48ad32c694164e418 Mon Sep 17 00:00:00 2001 From: Lee Jarvis Date: Tue, 3 May 2011 11:51:26 +0100 Subject: [PATCH 01/46] bump slop version with bugfixes --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 7c166536..3c569687 100644 --- a/Rakefile +++ b/Rakefile @@ -22,7 +22,7 @@ def apply_spec_defaults(s) s.test_files = `git ls-files -- test/*`.split("\n") s.add_dependency("ruby_parser",">=2.0.5") s.add_dependency("coderay",">=0.9.7") - s.add_dependency("slop",">=1.5.3") + s.add_dependency("slop",">=1.5.5") s.add_dependency("method_source",">=0.4.0") s.add_development_dependency("bacon",">=1.1.0") end From a58fec04905cd408c2ef5e942f538fc41bf1dfe5 Mon Sep 17 00:00:00 2001 From: Lee Jarvis Date: Thu, 5 May 2011 12:15:16 +0100 Subject: [PATCH 02/46] bump coderay version to 0.9.8 --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 3c569687..c1352392 100644 --- a/Rakefile +++ b/Rakefile @@ -21,7 +21,7 @@ def apply_spec_defaults(s) s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- test/*`.split("\n") s.add_dependency("ruby_parser",">=2.0.5") - s.add_dependency("coderay",">=0.9.7") + s.add_dependency("coderay",">=0.9.8") s.add_dependency("slop",">=1.5.5") s.add_dependency("method_source",">=0.4.0") s.add_development_dependency("bacon",">=1.1.0") From 32ad27a847c659e22d14ef51e910d7a34048d678 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 15:14:49 +1200 Subject: [PATCH 03/46] added tests for updated CommandContext#run method --- test/test_pry.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/test_pry.rb b/test/test_pry.rb index ecffa5a3..179ec5fa 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -617,6 +617,49 @@ describe Pry do str_output.string.should =~ /v command/ end + it 'should run a regex command from within a command' do + klass = Pry::CommandSet.new do + command /v(.*)?/ do |arg| + output.puts "v #{arg}" + end + + command "run_v" do + run "vbaby" + end + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("run_v"), str_output) do + Pry.new(:commands => klass).rep + end + + str_output.string.should =~ /v baby/ + end + + it 'should run a command from within a command with arguments' do + klass = Pry::CommandSet.new do + command /v(\w+)/ do |arg1, arg2| + output.puts "v #{arg1} #{arg2}" + end + + command "run_v_explicit_parameter" do + run "vbaby", "param" + end + + command "run_v_embedded_parameter" do + run "vbaby param" + end + end + + ["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd| + str_output = StringIO.new + redirect_pry_io(InputTester.new(cmd), str_output) do + Pry.new(:commands => klass).rep + end + str_output.string.should =~ /v baby param/ + 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 From 32bfa27b5a2637628f3d4136e0d4856acded8fc3 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 15:21:48 +1200 Subject: [PATCH 04/46] Revert "Made Pry able to cd into procs" This reverts commit 206c79588c8ce94b39b8be7c7a0573a13ce78154. --- lib/pry/core_extensions.rb | 4 ++-- test/test_pry.rb | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/pry/core_extensions.rb b/lib/pry/core_extensions.rb index 1bd294e8..7e1ef63c 100644 --- a/lib/pry/core_extensions.rb +++ b/lib/pry/core_extensions.rb @@ -30,13 +30,13 @@ class Object begin instance_eval %{ def __binding_impl__ - Kernel.binding + binding end } rescue TypeError self.class.class_eval %{ def __binding_impl__ - Kernel.binding + binding end } end diff --git a/test/test_pry.rb b/test/test_pry.rb index 179ec5fa..9413f4c7 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -297,11 +297,6 @@ describe Pry do Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call) end - - it 'should return a binding with the right self for procs' do - proc = Proc.new {} - Pry.binding_for(proc).eval("self").should.equal? proc - end end From bbb375deb452675bfa38c1d8cb543b5188cb6087 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 15:54:42 +1200 Subject: [PATCH 05/46] changed 'rake pry' to invoke executable instead of starting pry session in Rakefile --- Rakefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index bf50ad5a..59b480ff 100644 --- a/Rakefile +++ b/Rakefile @@ -34,8 +34,7 @@ end desc "run pry" task :pry do - require 'pry' - binding.pry + load 'bin/pry' end desc "show pry version" From 458540811ae101479a74d3523723f2708f010b0b Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 15:56:38 +1200 Subject: [PATCH 06/46] changed formatting for uninstalled command message (added bold) --- lib/pry/command_set.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 7e7a2c95..d52dd829 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -112,7 +112,7 @@ class Pry gems_not_installed = gems_needed.select { |g| !gem_installed?(g) } options[:stub_info] = proc do - output.puts "\nThe command '#{name}' is unavailable because it requires the following gems to be installed: #{(gems_not_installed.join(", "))}" + output.puts "\nThe command '#{name}' is #{Helpers::Text.bold("unavailable")} because it requires the following gems to be installed: #{(gems_not_installed.join(", "))}" output.puts "-" output.puts "Type `install #{name}` to install the required gems and activate this command." end From ef6eeb06b47900e88f233e132caa34a0ec35522a Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 15:57:06 +1200 Subject: [PATCH 07/46] removed all instances of old opts[:arg_string] --- lib/pry/default_commands/basic.rb | 2 +- lib/pry/extended_commands/experimental.rb | 2 +- lib/pry/extended_commands/user_command_api.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pry/default_commands/basic.rb b/lib/pry/default_commands/basic.rb index 124a75d1..df195529 100644 --- a/lib/pry/default_commands/basic.rb +++ b/lib/pry/default_commands/basic.rb @@ -23,7 +23,7 @@ class Pry command "import", "Import a command set" do |command_set_name| next output.puts "Provide a command set name" if command_set.nil? - set = target.eval(opts[:arg_string]) + set = target.eval(arg_string) Pry.active_instance.commands.import set end diff --git a/lib/pry/extended_commands/experimental.rb b/lib/pry/extended_commands/experimental.rb index aabe0bc2..12641618 100644 --- a/lib/pry/extended_commands/experimental.rb +++ b/lib/pry/extended_commands/experimental.rb @@ -14,7 +14,7 @@ class Pry end command "play-string", "Play a string as input" do - Pry.active_instance.input = StringIO.new(opts[:arg_string]) + Pry.active_instance.input = StringIO.new(arg_string) end command "play-method", "Play a method source as input" do |*args| diff --git a/lib/pry/extended_commands/user_command_api.rb b/lib/pry/extended_commands/user_command_api.rb index 9f32a5c8..ca24adee 100644 --- a/lib/pry/extended_commands/user_command_api.rb +++ b/lib/pry/extended_commands/user_command_api.rb @@ -6,10 +6,10 @@ class Pry command "define-command", "To honor Mon-Ouie" do |arg| next output.puts("Provide an arg!") if arg.nil? - prime_string = "command #{opts[:arg_string]}\n" + prime_string = "command #{arg_string}\n" command_string = Pry.active_instance.r(target, prime_string) - opts[:eval_string].replace <<-HERE + eval_string.replace <<-HERE _pry_.commands.instance_eval do #{command_string} end From a065fca70111e186c7648a21fed3b758e0dfeea0 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 16:46:44 +1200 Subject: [PATCH 08/46] fixed spelling mistakes in comments --- lib/pry/command_set.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index d52dd829..fb3a3851 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -5,7 +5,7 @@ class Pry end end - # This class used to create sets of commands. Commands can be impoted from + # This class is used to create sets of commands. Commands can be imported from # different sets, aliased, removed, etc. class CommandSet class Command < Struct.new(:name, :description, :options, :block) From 6999d7f1edb349d1551459a304816f219189b569 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 30 May 2011 16:47:24 +1200 Subject: [PATCH 09/46] added tests for help and show-command commands, and by proxy testing :listing functionality and regex commands --- test/test_default_commands.rb | 105 ++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/test/test_default_commands.rb b/test/test_default_commands.rb index 7530b6f9..1ac369ff 100644 --- a/test/test_default_commands.rb +++ b/test/test_default_commands.rb @@ -166,6 +166,8 @@ describe "Pry::Commands" do $str_output = nil end + # dynamically defined method source retrieval is only supported in + # 1.9 - where Method#source_location is native if RUBY_VERSION =~ /1.9/ it 'should output a method\'s source for a method defined inside pry' do str_output = StringIO.new @@ -292,4 +294,107 @@ describe "Pry::Commands" do $obj.should == :mon_ouie end end + + # show-command only works in implementations that support Proc#source_location + if Proc.method_defined?(:source_location) + describe "show-command" do + it 'should show source for an ordinary command' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command "foo" do + :body_of_foo + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command foo"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo/ + end + + it 'should show source for a command with spaces in its name' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command "foo bar" do + :body_of_foo_bar + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo_bar/ + end + + it 'should show source for a command by listing name' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command /foo(.*)/, "", :listing => "bar" do + :body_of_foo_regex + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command bar"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo_regex/ + end + end + end + + describe "help" do + it 'should display help for a specific command' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("help ls", "exit-all"), str_output) do + pry + end + str_output.string.each_line.count.should == 1 + str_output.string.should =~ /ls --help/ + end + + it 'should display help for a regex command with a "listing"' do + set = Pry::CommandSet.new do + command /bar(.*)/, "Test listing", :listing => "foo" do + end + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("help foo"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.each_line.count.should == 1 + str_output.string.should =~ /Test listing/ + end + + it 'should display help for a command with a spaces in its name' do + set = Pry::CommandSet.new do + command "command with spaces", "description of a command with spaces" do + end + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("help \"command with spaces\""), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.each_line.count.should == 1 + str_output.string.should =~ /description of a command with spaces/ + end + + it 'should display help for all commands with a description' do + set = Pry::CommandSet.new do + command /bar(.*)/, "Test listing", :listing => "foo" do; end + command "b", "description for b", :listing => "foo" do; end + command "c" do;end + command "d", "" do;end + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("help"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /Test listing/ + str_output.string.should =~ /description for b/ + str_output.string.should =~ /No description/ + end + end end From 329983354ccbfde17da54eabd6da86988352a2e1 Mon Sep 17 00:00:00 2001 From: Rob Gleeson Date: Mon, 30 May 2011 11:56:50 +0100 Subject: [PATCH 10/46] CommandSet is Enumerable. --- lib/pry/command_set.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index fb3a3851..11cc95b3 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -31,6 +31,7 @@ class Pry end end + include Enumerable include Pry::Helpers::BaseHelpers attr_reader :commands @@ -121,6 +122,16 @@ class Pry commands[name] = Command.new(name, description, options, block) end + def each &block + if block_given? + @commands.each do |name, struct| + yield(name, struct) + end + else + @commands.to_enum + end + end + # Removes some commands from the set # @param [Array] names name of the commands to remove def delete(*names) From 657ae09c6a27e243a66fc84680f8324563b97927 Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 31 May 2011 00:06:55 +1200 Subject: [PATCH 11/46] added CommandSet#list_commands, convenience method for repl exploration of command sets --- lib/pry/command_set.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 11cc95b3..65101c5a 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -216,6 +216,11 @@ class Pry end + # @return [Array] The list of commands provided by the command set. + def list_commands + commands.keys + end + private def define_default_commands From 774e19c394ea71e13108bb1a1ba01ae01a06981e Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 31 May 2011 00:07:15 +1200 Subject: [PATCH 12/46] experimental command 'play' --- lib/pry/extended_commands/experimental.rb | 47 +++++++++++------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/pry/extended_commands/experimental.rb b/lib/pry/extended_commands/experimental.rb index 12641618..7abc0082 100644 --- a/lib/pry/extended_commands/experimental.rb +++ b/lib/pry/extended_commands/experimental.rb @@ -13,39 +13,36 @@ class Pry meth.reload end - command "play-string", "Play a string as input" do - Pry.active_instance.input = StringIO.new(arg_string) - end - - command "play-method", "Play a method source as input" do |*args| - target = target() - opts = Slop.parse!(args) do |opt| + command "play", "Play a string as input" do |*args| + Slop.parse!(args) do |opt| opt.banner "Usage: play-method [--replay START..END] [--clear] [--grep PATTERN] [--help]\n" opt.on :l, :lines, 'The line (or range of lines) to replay.', true, :as => Range + opt.on :m, :method, 'Play a method.', true do |meth_name| + if (meth = get_method_object(meth_name, target, {})).nil? + output.puts "Invalid method name: #{meth_name}." + next + end + code, code_type = code_and_code_type_for(meth) + next if !code + + range = opt.l? ? opt[:l] : (0..-1) + + Pry.active_instance.input = StringIO.new(code[range]) + end + + opt.on :f, "file", 'The line (or range of lines) to replay.', true do |file_name| + text = File.read File.expand_path(file_name) + range = opt.l? ? opt[:l] : (0..-1) + + Pry.active_instance.input = StringIO.new(text[range]) + end + opt.on :h, :help, "This message." do output.puts opt end end - - next if opts.help? - - meth_name = args.shift - if (meth = get_method_object(meth_name, target, {})).nil? - output.puts "Invalid method name: #{meth_name}. Type `play-method --help` for help" - next - end - - code, code_type = code_and_code_type_for(meth) - next if !code - - slice = opts[:l] ? opts[:l] : (0..-1) - - sliced_code = code.each_line.to_a[slice].join("\n") - - Pry.active_instance.input = StringIO.new(sliced_code) end - end end end From b6615179744d98e21b137e338ff96f4f21f3035a Mon Sep 17 00:00:00 2001 From: Rob Gleeson Date: Mon, 30 May 2011 19:09:52 +0100 Subject: [PATCH 13/46] Simplify Pry::CommandSet#each. --- lib/pry/command_set.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 65101c5a..3b185382 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -123,13 +123,7 @@ class Pry end def each &block - if block_given? - @commands.each do |name, struct| - yield(name, struct) - end - else - @commands.to_enum - end + @commands.each(&block) end # Removes some commands from the set From b5847f752a487d5c1ebc8fa381b5a050596e5539 Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 31 May 2011 19:16:04 +1200 Subject: [PATCH 14/46] tiny refactor to repl_prologue in pry_instance.rb --- lib/pry/pry_instance.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 2c0cb977..3f9bc3fe 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -103,8 +103,8 @@ class Pry Pry.active_instance = self # Make sure special locals exist - target.eval("_pry_ = ::Pry.active_instance") - target.eval("_ = ::Pry.last_result") + set_active_instance(target) + set_last_result(Pry.last_result, target) self.session_target = target end From 6a60955ec67bc3880b9337613f8414ef27b795d5 Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 31 May 2011 19:16:52 +1200 Subject: [PATCH 15/46] removed deprecated has_rdoc= call --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 59b480ff..4d226bfa 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,6 @@ def apply_spec_defaults(s) s.email = 'jrmair@gmail.com' s.description = s.summary s.homepage = "http://banisterfiend.wordpress.com" - s.has_rdoc = 'yard' s.executables = ["pry"] s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- test/*`.split("\n") From 9abb4db3e2bd06c8e9ec0adc04357f8fbd9d9a5b Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 31 May 2011 20:45:42 +1200 Subject: [PATCH 16/46] removed unnecessary pry_command? method from command_processor.rb. And removed #clear singleton method on val and eval_string, converted to #replace --- lib/pry/command_processor.rb | 22 ++++------------------ lib/pry/default_commands/input.rb | 2 +- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/lib/pry/command_processor.rb b/lib/pry/command_processor.rb index 73bdec12..697c9077 100644 --- a/lib/pry/command_processor.rb +++ b/lib/pry/command_processor.rb @@ -16,14 +16,6 @@ class Pry # @param [String] val The string passed in from the Pry prompt. # @return [Boolean] Whether the string is a valid command. def valid_command?(val) - pry_command?(val) - end - - - # Is the string a valid pry command? - # @param [String] val The string passed in from the Pry prompt. - # @return [Boolean] Whether the string is a valid Pry command. - def pry_command?(val) !!(command_matched(val)[0]) end @@ -48,7 +40,6 @@ class Pry target.eval(dumped_str) end - # Determine whether a Pry command was matched and return command data # and argument string. # This method should not need to be invoked directly. @@ -72,18 +63,13 @@ class Pry # multi-line input. # @param [Binding] target The receiver of the commands. def process_commands(val, eval_string, target) - def val.clear() replace("") end - def eval_string.clear() replace("") end - - # no command was matched, so return to caller - return if !pry_command?(val) - command, captures, pos = command_matched(val) + # no command was matched, so return to caller + return if !command + val.replace interpolate_string(val, target) if command.options[:interpolate] - arg_string = val[pos..-1].strip - args = arg_string ? Shellwords.shellwords(arg_string) : [] options = { @@ -121,7 +107,7 @@ class Pry ret = commands.run_command(context, command, *args) # Tick, tock, im getting rid of this shit soon. - options[:val].clear + options[:val].replace("") ret end diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index b4896cdf..12a67174 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -5,7 +5,7 @@ class Pry command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do output.puts "Input buffer cleared!" - eval_string.clear + eval_string.replace("") end command "show-input", "Show the current eval_string" do From 502a8764fe6da814015b29a4db6b6c8d54e94d30 Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 31 May 2011 13:33:19 +0200 Subject: [PATCH 17/46] Refactored Pry::Helpers::BaseHelpers#gem_installed? to use Gem::Specification.find_all_by_name rather than the deprecated Gem.source_index Refactored gem-list to use Gem::Specification.each rather than the deprecated Gem.source_index Changed gem-cd to use Gem::Specification.each rather than the deprecated Gem.source_index --- lib/pry/commands.rb | 10 +++++----- lib/pry/helpers/base_helpers.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index c683bc3d..5250c8ff 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -238,8 +238,8 @@ e.g: gist -d my_method command "gem-cd", "Change working directory to specified gem's directory." do |gem_name| require 'rubygems' - gem_spec = Gem.source_index.find_name(gem_name).first - next output.puts("Gem `#{gem_name}` not found.") if !gem_spec + gem_spec = Gem::Specification.find_all_by_name(gem_name).first # find_by_name raises Gem::LoadError which is irksome + next output.puts("Gem `#{gem_name}` not found.") unless gem_spec Dir.chdir(File.expand_path(gem_spec.full_gem_path)) end @@ -330,13 +330,13 @@ e.g: gist -d my_method command "gem-list", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |arg| - gems = Gem.source_index.gems.values.group_by(&:name) if arg query = Regexp.new(arg, Regexp::IGNORECASE) - gems = gems.select { |gemname, specs| gemname =~ query } + else + query = // end - gems.each do |gemname, specs| + Gem::Specification.select{|spec| spec.name =~ query }.group_by(&:name).each do |gemname, specs| versions = specs.map(&:version).sort.reverse.map(&:to_s) versions = ["#{versions.first}"] + versions[1..-1].map{|v| "#{v}" } diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index 8d5f5dfe..048ad3e5 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -6,7 +6,7 @@ class Pry def gem_installed?(gem_name) require 'rubygems' - !!Gem.source_index.find_name(gem_name).first + !Gem::Specification.find_all_by_name(gem_name).empty? end def command_dependencies_met?(options) From 89f9e3c712d62f4f3259cf34a0a12c88854b60d7 Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 31 May 2011 13:49:17 +0200 Subject: [PATCH 18/46] Adding backwards compat checks to ant-deprecation refactor (works with rubygems 1.8.x and 1.6.x) --- lib/pry/commands.rb | 11 +++++++++-- lib/pry/helpers/base_helpers.rb | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 5250c8ff..fd6e24e0 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -238,7 +238,8 @@ e.g: gist -d my_method command "gem-cd", "Change working directory to specified gem's directory." do |gem_name| require 'rubygems' - gem_spec = Gem::Specification.find_all_by_name(gem_name).first # find_by_name raises Gem::LoadError which is irksome + gem_spec = Gem::Specification.respond_to?(:each) ? Gem::Specification.find_all_by_name(gem_name).first : Gem.source_index.find_name(gem_name).first # find_by_name raises Gem::LoadError which is irksome + next output.puts("Gem `#{gem_name}` not found.") unless gem_spec Dir.chdir(File.expand_path(gem_spec.full_gem_path)) end @@ -335,8 +336,14 @@ e.g: gist -d my_method else query = // end + + if Gem::Specification.respond_to?(:each) + gems = Gem::Specification.select{|spec| spec.name =~ query }.group_by(&:name) + else + gems = Gem.source_index.gems.values.group_by(&:name).select { |gemname, specs| gemname =~ query } + end - Gem::Specification.select{|spec| spec.name =~ query }.group_by(&:name).each do |gemname, specs| + gems.each do |gemname, specs| versions = specs.map(&:version).sort.reverse.map(&:to_s) versions = ["#{versions.first}"] + versions[1..-1].map{|v| "#{v}" } diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index 048ad3e5..f00a9641 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -6,7 +6,7 @@ class Pry def gem_installed?(gem_name) require 'rubygems' - !Gem::Specification.find_all_by_name(gem_name).empty? + Gem::Specification.respond_to?(:find_all_by_name) ? !Gem::Specification.find_all_by_name(gem_name).empty? : Gem.source_index.find_name(gem_name).first end def command_dependencies_met?(options) From 164ff2bf6a2a5a84b513bdc21fc719c34d1702dc Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 31 May 2011 15:46:26 +0200 Subject: [PATCH 19/46] Adding rake ruby:gemspec to dump a .gemspec file so I can bundle the gem from github Adding generated gemspec file --- Rakefile | 7 +++++++ pry-0.8.3.gemspec | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 pry-0.8.3.gemspec diff --git a/Rakefile b/Rakefile index c1352392..1f66eb2f 100644 --- a/Rakefile +++ b/Rakefile @@ -52,6 +52,13 @@ namespace :ruby do pkg.need_zip = false pkg.need_tar = false end + + desc "Generate gemspec file" + task :gemspec do + File.open("#{spec.name}-#{spec.version}.gemspec", "w") do |f| + f << spec.to_ruby + end + end end [:mingw32, :mswin32].each do |v| diff --git a/pry-0.8.3.gemspec b/pry-0.8.3.gemspec new file mode 100644 index 00000000..090ab750 --- /dev/null +++ b/pry-0.8.3.gemspec @@ -0,0 +1,44 @@ +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{pry} + s.version = "0.8.3" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["John Mair (banisterfiend)"] + s.date = %q{2011-05-31} + s.default_executable = %q{pry} + s.description = %q{attach an irb-like session to any object at runtime} + s.email = %q{jrmair@gmail.com} + s.executables = ["pry"] + s.files = [".document", ".gemtest", ".gitignore", ".yardopts", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "lib/pry.rb", "lib/pry/command_context.rb", "lib/pry/command_processor.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/helpers.rb", "lib/pry/helpers/base_helpers.rb", "lib/pry/helpers/command_helpers.rb", "lib/pry/hooks.rb", "lib/pry/print.rb", "lib/pry/prompts.rb", "lib/pry/pry_class.rb", "lib/pry/pry_instance.rb", "lib/pry/version.rb", "test/test.rb", "test/test_helper.rb", "test/testrc", "wiki/Customizing-pry.md", "wiki/Home.md"] + s.homepage = %q{http://banisterfiend.wordpress.com} + s.require_paths = ["lib"] + s.rubygems_version = %q{1.6.2} + s.summary = %q{attach an irb-like session to any object at runtime} + s.test_files = ["test/test.rb", "test/test_helper.rb", "test/testrc"] + + if s.respond_to? :specification_version then + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 2.0.5"]) + s.add_runtime_dependency(%q, [">= 0.9.8"]) + s.add_runtime_dependency(%q, [">= 1.5.5"]) + s.add_runtime_dependency(%q, [">= 0.4.0"]) + s.add_development_dependency(%q, [">= 1.1.0"]) + else + s.add_dependency(%q, [">= 2.0.5"]) + s.add_dependency(%q, [">= 0.9.8"]) + s.add_dependency(%q, [">= 1.5.5"]) + s.add_dependency(%q, [">= 0.4.0"]) + s.add_dependency(%q, [">= 1.1.0"]) + end + else + s.add_dependency(%q, [">= 2.0.5"]) + s.add_dependency(%q, [">= 0.9.8"]) + s.add_dependency(%q, [">= 1.5.5"]) + s.add_dependency(%q, [">= 0.4.0"]) + s.add_dependency(%q, [">= 1.1.0"]) + end +end From b8e710771572940b441abfbcc3d154bc8491a89c Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 1 Jun 2011 03:11:57 +1200 Subject: [PATCH 20/46] ensure all plugins are disabled for tests --- test/helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/helper.rb b/test/helper.rb index 634ae842..237e5ec8 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -18,6 +18,7 @@ class << Pry Pry.color = false Pry.pager = false Pry.config.should_load_rc = false + Pry.config.should_load_plugins = false Pry.config.history.load = false Pry.config.history.save = false end From 1f6130cdbb5b9aeb1ab97f6fb62a05c88d8f186a Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 1 Jun 2011 03:12:29 +1200 Subject: [PATCH 21/46] Pry#refresh method to update Pry instance settings from Pry class --- lib/pry/pry_instance.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 3f9bc3fe..8a0ca416 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -19,12 +19,21 @@ class Pry # @param [Hash] options The optional configuration parameters. # @option options [#readline] :input The object to use for input. # @option options [#puts] :output The object to use for output. - # @option options [Pry::CommandBase] :commands The object to use for commands. (see commands.rb) - # @option options [Hash] :hooks The defined hook Procs (see hooks.rb) - # @option options [Array] :default_prompt The array of Procs to use for the prompts. (see prompts.rb) + # @option options [Pry::CommandBase] :commands The object to use for commands. + # @option options [Hash] :hooks The defined hook Procs + # @option options [Array] :prompt The array of Procs to use for the prompts. # @option options [Proc] :print The Proc to use for the 'print' # component of the REPL. (see print.rb) def initialize(options={}) + refresh(options) + @command_processor = CommandProcessor.new(self) + end + + # Refresh the Pry instance settings from the Pry class. + # Allows options to be specified to override settings from Pry class. + # @param [Hash] options The options to override Pry class settings + # for this instance. + def refresh(options={}) defaults = {} attributes = [ :input, :output, :commands, :print, @@ -36,11 +45,10 @@ class Pry defaults[attribute] = Pry.send attribute end - defaults.merge!(options).each_key do |key| - send "#{key}=", defaults[key] + defaults.merge!(options).each do |key, value| + send "#{key}=", value end - - @command_processor = CommandProcessor.new(self) + true end # The current prompt. From 2fb4742cb34ac98125b97bc5122e9d28ed15b3ab Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 1 Jun 2011 14:39:08 +1200 Subject: [PATCH 22/46] updated pry logo --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 0ec57f44..7d6621d1 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ -![Alt text](http://dl.dropbox.com/u/26521875/pry_logo_shade.png) +![Alt text](http://dl.dropbox.com/u/15761219/pry_horizontal_red.png) (C) John Mair (banisterfiend) 2011 From 7fe09c806dbd9b7d2d6f220c77b21e79f43e4c05 Mon Sep 17 00:00:00 2001 From: David Palm Date: Wed, 1 Jun 2011 08:29:48 +0200 Subject: [PATCH 23/46] whitespace --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index fb3f9b05..e658f4f6 100644 --- a/Rakefile +++ b/Rakefile @@ -56,7 +56,7 @@ namespace :ruby do task :gemspec do File.open("#{spec.name}-#{spec.version}.gemspec", "w") do |f| f << spec.to_ruby -end + end end end From bafff3dc7df0c70825189ffa35c05c7c74a0dfcf Mon Sep 17 00:00:00 2001 From: David Palm Date: Wed, 1 Jun 2011 08:47:14 +0200 Subject: [PATCH 24/46] rubygems 1.8.x compatibility fixes applied to dev branch --- lib/pry/default_commands/gems.rb | 10 +++++++--- lib/pry/plugins.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pry/default_commands/gems.rb b/lib/pry/default_commands/gems.rb index 62f016a7..3f2d4421 100644 --- a/lib/pry/default_commands/gems.rb +++ b/lib/pry/default_commands/gems.rb @@ -19,14 +19,18 @@ class Pry end command "gem-cd", "Change working directory to specified gem's directory.", :argument_required => true do |gem| - spec = Gem.source_index.find_name(gem).sort { |a,b| Gem::Version.new(b.version) <=> Gem::Version.new(a.version) }.first + specs = Gem::Specification.respond_to?(:each) ? Gem::Specification.find_all_by_name(gem) : Gem.source_index.find_name(gem) + spec = specs.sort { |a,b| Gem::Version.new(b.version) <=> Gem::Version.new(a.version) }.first spec ? Dir.chdir(spec.full_gem_path) : output.puts("Gem `#{gem}` not found.") end - command "gem-list", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |pattern| pattern = Regexp.new pattern.to_s, Regexp::IGNORECASE - gems = Gem.source_index.find_name(pattern).group_by(&:name) + gems = if Gem::Specification.respond_to?(:each) + Gem::Specification.select{|spec| spec.name =~ pattern }.group_by(&:name) + else + Gem.source_index.gems.values.group_by(&:name).select { |gemname, specs| gemname =~ pattern } + end gems.each do |gem, specs| specs.sort! do |a,b| diff --git a/lib/pry/plugins.rb b/lib/pry/plugins.rb index 70b0fa94..b8c4f4b6 100644 --- a/lib/pry/plugins.rb +++ b/lib/pry/plugins.rb @@ -44,7 +44,7 @@ class Pry # Find all installed Pry plugins and store them in an internal array. def locate_plugins Gem.refresh - Gem.source_index.find_name('').each do |gem| + (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem| next if gem.name !~ PRY_PLUGIN_PREFIX plugin_name = gem.name.split('-', 2).last @plugins << Plugin.new(plugin_name, gem.name, true) if !gem_located?(gem.name) From e314db48a8434179e4172067d18fcbaf87edacdd Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 1 Jun 2011 21:12:29 +1200 Subject: [PATCH 25/46] remove outdated gemspec --- pry-0.8.3.gemspec | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 pry-0.8.3.gemspec diff --git a/pry-0.8.3.gemspec b/pry-0.8.3.gemspec deleted file mode 100644 index 090ab750..00000000 --- a/pry-0.8.3.gemspec +++ /dev/null @@ -1,44 +0,0 @@ -# -*- encoding: utf-8 -*- - -Gem::Specification.new do |s| - s.name = %q{pry} - s.version = "0.8.3" - - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["John Mair (banisterfiend)"] - s.date = %q{2011-05-31} - s.default_executable = %q{pry} - s.description = %q{attach an irb-like session to any object at runtime} - s.email = %q{jrmair@gmail.com} - s.executables = ["pry"] - s.files = [".document", ".gemtest", ".gitignore", ".yardopts", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "lib/pry.rb", "lib/pry/command_context.rb", "lib/pry/command_processor.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/helpers.rb", "lib/pry/helpers/base_helpers.rb", "lib/pry/helpers/command_helpers.rb", "lib/pry/hooks.rb", "lib/pry/print.rb", "lib/pry/prompts.rb", "lib/pry/pry_class.rb", "lib/pry/pry_instance.rb", "lib/pry/version.rb", "test/test.rb", "test/test_helper.rb", "test/testrc", "wiki/Customizing-pry.md", "wiki/Home.md"] - s.homepage = %q{http://banisterfiend.wordpress.com} - s.require_paths = ["lib"] - s.rubygems_version = %q{1.6.2} - s.summary = %q{attach an irb-like session to any object at runtime} - s.test_files = ["test/test.rb", "test/test_helper.rb", "test/testrc"] - - if s.respond_to? :specification_version then - s.specification_version = 3 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 2.0.5"]) - s.add_runtime_dependency(%q, [">= 0.9.8"]) - s.add_runtime_dependency(%q, [">= 1.5.5"]) - s.add_runtime_dependency(%q, [">= 0.4.0"]) - s.add_development_dependency(%q, [">= 1.1.0"]) - else - s.add_dependency(%q, [">= 2.0.5"]) - s.add_dependency(%q, [">= 0.9.8"]) - s.add_dependency(%q, [">= 1.5.5"]) - s.add_dependency(%q, [">= 0.4.0"]) - s.add_dependency(%q, [">= 1.1.0"]) - end - else - s.add_dependency(%q, [">= 2.0.5"]) - s.add_dependency(%q, [">= 0.9.8"]) - s.add_dependency(%q, [">= 1.5.5"]) - s.add_dependency(%q, [">= 0.4.0"]) - s.add_dependency(%q, [">= 1.1.0"]) - end -end From f091b4fa9bf3441eb76667d413b176d8e5ab0b69 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 2 Jun 2011 04:21:55 +1200 Subject: [PATCH 26/46] can display core source on rbx (when installed with rvm) --- lib/pry/helpers/command_helpers.rb | 37 ++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index d42dc3fa..0b325ff9 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -48,6 +48,36 @@ class Pry end end + ########### RBX HELPERS ############# + def rbx_core?(meth) + defined?(RUBY_ENGINE) && + RUBY_ENGINE =~ /rbx/ && + meth.source_location && + meth.source_location.first.start_with?("kernel") + end + + def rvm_ruby?(path) + !!(path =~ /\.rvm/) + end + + def rbx_core_code_for(meth) + if rvm_ruby?(Rubinius::BIN_PATH) + rvm_rbx_core_code_for(meth) + else + # NOT implemented + end + end + + def rvm_rbx_core_code_for(meth) + ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last + source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name) + file_name = File.join(source_path, meth.source_location.first) + start_line = meth.source_location.last + MethodSource.source_helper([file_name, start_line]) + end + + ######### END RBX HELPERS ############### + def code_and_code_type_for(meth) case code_type = code_type_for(meth) when nil @@ -57,12 +87,15 @@ class Pry code = strip_comments_from_c_code(code) when :ruby if meth.source_location.first == Pry.eval_path - start_line = meth.source_location.last p = Pry.new(:input => StringIO.new(Pry.line_buffer[start_line..-1].join)).r(target) code = strip_leading_whitespace(p) else - code = strip_leading_whitespace(meth.source) + if rbx_core?(meth) + code = strip_leading_whitespace(rbx_core_code_for(meth)) + else + code = strip_leading_whitespace(meth.source) + end end set_file_and_dir_locals(meth.source_location.first) end From a8f152ecacb06b0c3255ca7ff6eacfef9f5920ad Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 2 Jun 2011 04:23:17 +1200 Subject: [PATCH 27/46] fixed a failing test for rbx (actually a failing test in general, but only spotted thanks to rbx) --- test/test_default_commands.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_default_commands.rb b/test/test_default_commands.rb index 1ac369ff..dc92230b 100644 --- a/test/test_default_commands.rb +++ b/test/test_default_commands.rb @@ -225,14 +225,16 @@ describe "Pry::Commands" do $str_output = StringIO.new o = Object.new + + # sample comment def o.sample redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do binding.pry - end + end end o.sample - $str_output.string.should =~ /sample doc/ + $str_output.string.should =~ /sample comment/ $str_output = nil end end From eb9238ab2be10090c98d843c007f1377679a94a7 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 2 Jun 2011 04:24:15 +1200 Subject: [PATCH 28/46] fixed . error message (dest local not found). Interpolation still not working yet --- lib/pry/default_commands/shell.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pry/default_commands/shell.rb b/lib/pry/default_commands/shell.rb index cd01056a..f04d1fbf 100644 --- a/lib/pry/default_commands/shell.rb +++ b/lib/pry/default_commands/shell.rb @@ -5,8 +5,9 @@ class Pry command /\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => "." do |cmd| if cmd =~ /^cd\s+(.+)/i + dest = $1 begin - Dir.chdir File.expand_path($1) + Dir.chdir File.expand_path(dest) rescue Errno::ENOENT output.puts "No such directory: #{dest}" end @@ -72,8 +73,6 @@ class Pry render_output(opts.flood?, opts.l? ? normalized_start_line + 1 : false, contents) contents end - - end end From 94a1f993e6d18bb64f6a5fec8cb232c3e8ba30b6 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 2 Jun 2011 21:41:41 +1200 Subject: [PATCH 29/46] Replaced Pry.config.should_load_plugins with Pry.config.plugins.enabled. Also added Pry.config.plugins.strict_loading config option; also updated test helper to reflect changes --- lib/pry/config.rb | 7 +++++++ lib/pry/pry_class.rb | 7 +++++-- test/helper.rb | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/pry/config.rb b/lib/pry/config.rb index bcd9370d..acb61c8b 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -81,6 +81,13 @@ class Pry # saved to hist.file at session end. # @return [OpenStruct] attr_accessor :history + + # Config option for plugins: + # sub-options include: + # `plugins.enabled` (Boolean) to toggle the loading of plugins on and off wholesale. (defaults to true) + # `plugins.strict_loading` (Boolean) which toggles whether referring to a non-existent plugin should raise an exception (defaults to `false`) + # @return [OpenStruct] + attr_accessor :plugins end end diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index a836e005..5a2fe3d1 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -96,7 +96,7 @@ class Pry # we only want them loaded once per entire Pry lifetime, not # multiple times per each new session (i.e in debugging) load_rc if Pry.config.should_load_rc - load_plugins if Pry.config.should_load_plugins + load_plugins if Pry.config.plugins.enabled load_history if Pry.config.history.load @initial_session = false @@ -190,7 +190,10 @@ class Pry config.pager = true config.editor = default_editor_for_platform config.should_load_rc = true - config.should_load_plugins = true + + config.plugins ||= OpenStruct.new + config.plugins.enabled = true + config.plugins.strict_loading = true config.history ||= OpenStruct.new config.history.save = true diff --git a/test/helper.rb b/test/helper.rb index 237e5ec8..9aae3980 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -18,7 +18,7 @@ class << Pry Pry.color = false Pry.pager = false Pry.config.should_load_rc = false - Pry.config.should_load_plugins = false + Pry.config.plugins.enabled = false Pry.config.history.load = false Pry.config.history.save = false end From 688863021241f34441afc89ec33910ef62f40872 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 2 Jun 2011 21:45:53 +1200 Subject: [PATCH 30/46] plugin activation/disabling errors can be turned off using Pry.config.plugins.strict_loading = false --- lib/pry/plugins.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pry/plugins.rb b/lib/pry/plugins.rb index b8c4f4b6..942dd1d6 100644 --- a/lib/pry/plugins.rb +++ b/lib/pry/plugins.rb @@ -1,10 +1,10 @@ class Pry class PluginManager - PRY_PLUGIN_PREFIX = /^pry-/ - PluginNotFound = Class.new(LoadError) + MessageSink = Object.new.tap { |o| def o.method_missing(*args) end } + class Plugin attr_accessor :name, :gem_name, :enabled, :active @@ -55,7 +55,7 @@ class Pry # @return [Hash] A hash with all plugin names (minus the 'pry-') as # keys and Plugin objects as values. def plugins - h = {} + h = Pry.config.plugins.strict_loading ? {} : Hash.new { MessageSink } @plugins.each do |plugin| h[plugin.name] = plugin end From 61bb4d9a17a23c51d92029b9554089ec8baba406 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 2 Jun 2011 23:37:28 +1200 Subject: [PATCH 31/46] added std rbx folder search and doc search for rbx core methods --- lib/pry/helpers/command_helpers.rb | 42 +++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 0b325ff9..e3313f4a 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -61,19 +61,46 @@ class Pry end def rbx_core_code_for(meth) + rbx_core_code_or_doc_for(meth, :code) + end + + def rbx_core_doc_for(meth) + rbx_core_code_or_doc_for(meth, :doc) + end + + def rbx_core_code_or_doc_for(meth, code_or_doc) if rvm_ruby?(Rubinius::BIN_PATH) - rvm_rbx_core_code_for(meth) + rvm_rbx_core_code_or_doc_for(meth, code_or_doc) else - # NOT implemented + std_rbx_core_code_or_doc_for(meth, code_or_doc) end end - def rvm_rbx_core_code_for(meth) + def std_rbx_core_code_or_doc_for(meth, code_or_doc) + file_name = File.join(Rubinius::BIN_PATH, "..", meth.source_location.first) + raise "Cannot find rbx core source" if !File.exists?(file_name) + start_line meth.source_location.last + + case code_or_doc + when :code + MethodSource.source_helper([file_name, start_line]) + when :doc + MethodSource.comment_helper([file_name, start_line]) + end + end + + def rvm_rbx_core_code_or_doc_for(meth, code_or_doc) ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name) file_name = File.join(source_path, meth.source_location.first) start_line = meth.source_location.last - MethodSource.source_helper([file_name, start_line]) + + case code_or_doc + when :code + MethodSource.source_helper([file_name, start_line]) + when :doc + MethodSource.comment_helper([file_name, start_line]) + end end ######### END RBX HELPERS ############### @@ -110,8 +137,11 @@ class Pry when :c doc = Pry::MethodInfo.info_for(meth).docstring when :ruby - doc = meth.comment - doc = strip_leading_hash_and_whitespace_from_ruby_comments(doc) + if rbx_core?(meth) + doc = strip_leading_hash_and_whitespace_from_ruby_comments(rbx_core_doc_for(meth)) + else + doc = strip_leading_hash_and_whitespace_from_ruby_comments(meth.comment) + end set_file_and_dir_locals(meth.source_location.first) end From 1a9738ff11f02fad328923a3254d725be184d362 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 03:22:59 +1200 Subject: [PATCH 32/46] refactored example initialization code (still need to update examples for new API) --- examples/example_basic.rb | 6 ++---- examples/example_command_override.rb | 7 ++----- examples/example_commands.rb | 5 +---- examples/example_hooks.rb | 7 ++----- examples/example_image_edit.rb | 12 ++++-------- examples/example_input.rb | 5 +---- examples/example_input2.rb | 5 +---- examples/example_output.rb | 5 +---- examples/example_print.rb | 7 ++----- examples/example_prompt.rb | 7 ++----- examples/helper.rb | 6 ++++++ 11 files changed, 24 insertions(+), 48 deletions(-) create mode 100644 examples/helper.rb diff --git a/examples/example_basic.rb b/examples/example_basic.rb index 8f893be6..ed3d4d52 100644 --- a/examples/example_basic.rb +++ b/examples/example_basic.rb @@ -1,7 +1,4 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) # define a local. a = "a local variable" @@ -14,4 +11,5 @@ end # Start pry session at top-level. # The local variable `a` and the `hello` method will # be accessible. +puts __LINE__ binding.pry diff --git a/examples/example_command_override.rb b/examples/example_command_override.rb index 889eaeee..237b1d61 100644 --- a/examples/example_command_override.rb +++ b/examples/example_command_override.rb @@ -1,7 +1,4 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) # Inherit standard command set, but tweak them by importing some and # overriding others. @@ -18,7 +15,7 @@ class MyCommands < Pry::CommandBase # analogy to Ruby's native alias_method idiom for decorating a method alias_command "old_status", "status", "" - + # Invoke one command from within another using `run` command "status", "Modified status." do |x| output.puts "About to show status, are you ready?" diff --git a/examples/example_commands.rb b/examples/example_commands.rb index ad57e021..8e945db1 100644 --- a/examples/example_commands.rb +++ b/examples/example_commands.rb @@ -1,7 +1,4 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) class MathCommands < Pry::CommandBase command "greet", "Greet a person, e.g: greet john" do |name| diff --git a/examples/example_hooks.rb b/examples/example_hooks.rb index 132b1ea1..e2a66b70 100644 --- a/examples/example_hooks.rb +++ b/examples/example_hooks.rb @@ -1,12 +1,9 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) my_hooks = { :before_session => proc { |out, target| out.puts "Opening #{target.eval('self')}." }, :after_session => proc { |out, target| out.puts "Closing #{target.eval('self')}." } } - + # Start a Pry session using the hooks hash defined in my_hooks Pry.start(TOPLEVEL_BINDING, :hooks => my_hooks) diff --git a/examples/example_image_edit.rb b/examples/example_image_edit.rb index 1eefa5e4..5f200c85 100644 --- a/examples/example_image_edit.rb +++ b/examples/example_image_edit.rb @@ -1,7 +1,7 @@ # Note: this requires you to have Gosu and TexPlay installed. # `gem install gosu` # `gem install texplay` -# +# # Extra instructions for installing Gosu on Linux can be found here: # http://code.google.com/p/gosu/wiki/GettingStartedOnLinux # @@ -10,11 +10,7 @@ # # Have fun! :) -direc = File.dirname(__FILE__) - -require 'rubygems' -require "texplay" -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) WIDTH = 640 HEIGHT = 480 @@ -42,12 +38,12 @@ class WinClass < Gosu::Window @img.rect 0, 0, @img.width - 1, @img.height - 1 @binding = Pry.binding_for(@img) - + @pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT) end def draw - @img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5) + @img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5) end def update diff --git a/examples/example_input.rb b/examples/example_input.rb index dd7c8d4e..dfa2239a 100644 --- a/examples/example_input.rb +++ b/examples/example_input.rb @@ -1,7 +1,4 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) # Create a StringIO that contains the input data str_input = StringIO.new("puts 'hello world!'\nputs \"I am in \#{self}\"\nexit") diff --git a/examples/example_input2.rb b/examples/example_input2.rb index bd4979d5..13a9364b 100644 --- a/examples/example_input2.rb +++ b/examples/example_input2.rb @@ -1,7 +1,4 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) # Create a StringIO that contains the input data for all the Pry objects cmds = <<-CMDS diff --git a/examples/example_output.rb b/examples/example_output.rb index e54dad77..6711a7b0 100644 --- a/examples/example_output.rb +++ b/examples/example_output.rb @@ -1,7 +1,4 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) # Create a StringIO to contain the output data str_output = StringIO.new diff --git a/examples/example_print.rb b/examples/example_print.rb index 0b55a31a..330982ea 100644 --- a/examples/example_print.rb +++ b/examples/example_print.rb @@ -1,9 +1,6 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) my_print = proc { |out, value| out.puts "Output is: #{value.inspect}" } - + # Start a Pry session using the print object defined in my_print Pry.start(TOPLEVEL_BINDING, :print => my_print) diff --git a/examples/example_prompt.rb b/examples/example_prompt.rb index 44b68092..f11c5ef7 100644 --- a/examples/example_prompt.rb +++ b/examples/example_prompt.rb @@ -1,12 +1,9 @@ -direc = File.dirname(__FILE__) - -require 'rubygems' -require "#{direc}/../lib/pry" +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) # Remember, first prompt in array is the main prompt, second is the wait # prompt (used for multiline input when more input is required) my_prompt = [ proc { |obj, *| "inside #{obj}> " }, proc { |obj, *| "inside #{obj}* "} ] - + # Start a Pry session using the prompt defined in my_prompt Pry.start(TOPLEVEL_BINDING, :prompt => my_prompt) diff --git a/examples/helper.rb b/examples/helper.rb new file mode 100644 index 00000000..ce37f493 --- /dev/null +++ b/examples/helper.rb @@ -0,0 +1,6 @@ +require 'rubygems' +unless Object.const_defined? 'Pry' + $:.unshift File.expand_path '../../lib', __FILE__ + require 'pry' +end + From 597f1cc68c0f31dc9d7d6be5fbefcef65e95ee81 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 03:26:49 +1200 Subject: [PATCH 33/46] reorganized command tests into test_default_commands/ folder with separate test files for each command set --- test/default_commands/test_context.rb | 64 ++++ test/default_commands/test_documentation.rb | 31 ++ test/default_commands/test_input.rb | 135 +++++++ test/default_commands/test_introspection.rb | 146 ++++++++ test/test_default_commands.rb | 343 ------------------ test/test_default_commands/test_context.rb | 64 ++++ .../test_documentation.rb | 31 ++ test/test_default_commands/test_input.rb | 135 +++++++ .../test_introspection.rb | 146 ++++++++ 9 files changed, 752 insertions(+), 343 deletions(-) create mode 100644 test/default_commands/test_context.rb create mode 100644 test/default_commands/test_documentation.rb create mode 100644 test/default_commands/test_input.rb create mode 100644 test/default_commands/test_introspection.rb create mode 100644 test/test_default_commands/test_context.rb create mode 100644 test/test_default_commands/test_documentation.rb create mode 100644 test/test_default_commands/test_input.rb create mode 100644 test/test_default_commands/test_introspection.rb diff --git a/test/default_commands/test_context.rb b/test/default_commands/test_context.rb new file mode 100644 index 00000000..93c5f237 --- /dev/null +++ b/test/default_commands/test_context.rb @@ -0,0 +1,64 @@ +require 'helper' + +describe "Pry::DefaultCommands::Context" do + describe "cd" do + after do + $obj = nil + end + + it 'should cd into simple input' do + b = Pry.binding_for(Object.new) + b.eval("x = :mon_ouie") + + redirect_pry_io(InputTester.new("cd x", "$obj = self", "exit-all"), StringIO.new) do + b.pry + end + + $obj.should == :mon_ouie + end + + it 'should break out of session with cd ..' do + b = Pry.binding_for(:outer) + b.eval("x = :inner") + + redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd ..", "$outer = self", "exit-all"), StringIO.new) do + b.pry + end + $inner.should == :inner + $outer.should == :outer + end + + it 'should break out to outer-most session with cd /' do + b = Pry.binding_for(:outer) + b.eval("x = :inner") + + redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd /", "$outer = self", "exit-all"), StringIO.new) do + b.pry + end + $inner.should == :inner + $five.should == 5 + $outer.should == :outer + end + + it 'should start a session on TOPLEVEL_BINDING with cd ::' do + b = Pry.binding_for(:outer) + + redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do + 5.pry + end + $obj.should == TOPLEVEL_BINDING.eval('self') + end + + it 'should cd into complex input (with spaces)' do + o = Object.new + def o.hello(x, y, z) + :mon_ouie + end + + redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "$obj = self", "exit-all"), StringIO.new) do + o.pry + end + $obj.should == :mon_ouie + end + end +end diff --git a/test/default_commands/test_documentation.rb b/test/default_commands/test_documentation.rb new file mode 100644 index 00000000..235c29b9 --- /dev/null +++ b/test/default_commands/test_documentation.rb @@ -0,0 +1,31 @@ +require 'helper' + +describe "Pry::DefaultCommands::Documentation" do + describe "show-doc" do + it 'should output a method\'s documentation' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /sample doc/ + end + + it 'should output a method\'s documentation if inside method without needing to use method name' do + $str_output = StringIO.new + + o = Object.new + + # sample comment + def o.sample + redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do + binding.pry + end + end + o.sample + + $str_output.string.should =~ /sample comment/ + $str_output = nil + end + end +end diff --git a/test/default_commands/test_input.rb b/test/default_commands/test_input.rb new file mode 100644 index 00000000..6831563e --- /dev/null +++ b/test/default_commands/test_input.rb @@ -0,0 +1,135 @@ +require 'helper' + +describe "Pry::DefaultCommands::Input" do + + describe "amend-line-N" do + it 'should correctly amend the last line of input when no line number specified ' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/ + end + + it 'should correctly amend the specified line of input when line number given ' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line-0 def goodbye", "show-input", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/ + end + end + + describe "hist" do + push_first_hist_line = lambda do |hist, line| + hist.push line + end + + before do + Readline::HISTORY.shift until Readline::HISTORY.empty? + @hist = Readline::HISTORY + end + + it 'should display the correct history' do + push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") + @hist.push "hello" + @hist.push "world" + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /hello\n.*world/ + end + + it 'should replay history correctly (single item)' do + push_first_hist_line.call(@hist, ":hello") + @hist.push ":blah" + @hist.push ":bucket" + @hist.push ":ostrich" + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /ostrich/ + end + + it 'should replay a range of history correctly (range of items)' do + push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") + @hist.push ":hello" + @hist.push ":carl" + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /:hello\n.*:carl/ + end + + it 'should grep for correct lines in history' do + push_first_hist_line.call(@hist, "apple") + @hist.push "abby" + @hist.push "box" + @hist.push "button" + @hist.push "pepper" + @hist.push "orange" + @hist.push "grape" + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/ + end + + it 'should return last N lines in history with --tail switch' do + push_first_hist_line.call(@hist, "0") + ("a".."z").each do |v| + @hist.push v + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do + pry + end + + str_output.string.each_line.count.should == 3 + str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/ + end + + # strangeness in this test is due to bug in Readline::HISTORY not + # always registering first line of input + it 'should return first N lines in history with --head switch' do + push_first_hist_line.call(@hist, "0") + ("a".."z").each do |v| + @hist.push v + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do + pry + end + + str_output.string.each_line.count.should == 4 + str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/ + end + + # strangeness in this test is due to bug in Readline::HISTORY not + # always registering first line of input + it 'should show lines between lines A and B with the --show switch' do + push_first_hist_line.call(@hist, "0") + ("a".."z").each do |v| + @hist.push v + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do + pry + end + + str_output.string.each_line.count.should == 4 + str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/ + end + end + + +end diff --git a/test/default_commands/test_introspection.rb b/test/default_commands/test_introspection.rb new file mode 100644 index 00000000..0ccc3e1f --- /dev/null +++ b/test/default_commands/test_introspection.rb @@ -0,0 +1,146 @@ +require 'helper' + +describe "Pry::DefaultCommands::Introspection" do + describe "show-method" do + it 'should output a method\'s source' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-method sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /def sample/ + end + + it 'should output a method\'s source with line numbers' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /\d+: def sample/ + end + + it 'should output a method\'s source if inside method without needing to use method name' do + $str_output = StringIO.new + + o = Object.new + def o.sample + redirect_pry_io(InputTester.new("show-method", "exit-all"), $str_output) do + binding.pry + end + end + o.sample + + $str_output.string.should =~ /def o.sample/ + $str_output = nil + end + + it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do + $str_output = StringIO.new + + o = Object.new + def o.sample + redirect_pry_io(InputTester.new("show-method -l", "exit-all"), $str_output) do + binding.pry + end + end + o.sample + + $str_output.string.should =~ /\d+: def o.sample/ + $str_output = nil + end + + # dynamically defined method source retrieval is only supported in + # 1.9 - where Method#source_location is native + if RUBY_VERSION =~ /1.9/ + it 'should output a method\'s source for a method defined inside pry' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /def dyna_method/ + Object.remove_method :dyna_method + end + + it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /def dyna_method/ + Object.remove_method :dyna_method + end + + it 'should output an instance method\'s source for a method defined inside pry' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-method A#yo"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /def yo/ + Object.remove_const :A + end + + it 'should output an instance method\'s source for a method defined inside pry using define_method' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "end", "show-method A#yup"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /define_method\(:yup\)/ + Object.remove_const :A + end + end + end + + # show-command only works in implementations that support Proc#source_location + if Proc.method_defined?(:source_location) + describe "show-command" do + it 'should show source for an ordinary command' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command "foo" do + :body_of_foo + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command foo"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo/ + end + + it 'should show source for a command with spaces in its name' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command "foo bar" do + :body_of_foo_bar + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo_bar/ + end + + it 'should show source for a command by listing name' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command /foo(.*)/, "", :listing => "bar" do + :body_of_foo_regex + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command bar"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo_regex/ + end + end + end + + +end diff --git a/test/test_default_commands.rb b/test/test_default_commands.rb index dc92230b..1321b84d 100644 --- a/test/test_default_commands.rb +++ b/test/test_default_commands.rb @@ -1,349 +1,6 @@ require 'helper' describe "Pry::Commands" do - - after do - $obj = nil - end - - describe "hist" do - push_first_hist_line = lambda do |hist, line| - hist.push line - end - - before do - Readline::HISTORY.shift until Readline::HISTORY.empty? - @hist = Readline::HISTORY - end - - it 'should display the correct history' do - push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") - @hist.push "hello" - @hist.push "world" - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /hello\n.*world/ - end - - it 'should replay history correctly (single item)' do - push_first_hist_line.call(@hist, ":hello") - @hist.push ":blah" - @hist.push ":bucket" - @hist.push ":ostrich" - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /ostrich/ - end - - it 'should replay a range of history correctly (range of items)' do - push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") - @hist.push ":hello" - @hist.push ":carl" - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /:hello\n.*:carl/ - end - - it 'should grep for correct lines in history' do - push_first_hist_line.call(@hist, "apple") - @hist.push "abby" - @hist.push "box" - @hist.push "button" - @hist.push "pepper" - @hist.push "orange" - @hist.push "grape" - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/ - end - - it 'should return last N lines in history with --tail switch' do - push_first_hist_line.call(@hist, "0") - ("a".."z").each do |v| - @hist.push v - end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do - pry - end - - str_output.string.each_line.count.should == 3 - str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/ - end - - # strangeness in this test is due to bug in Readline::HISTORY not - # always registering first line of input - it 'should return first N lines in history with --head switch' do - push_first_hist_line.call(@hist, "0") - ("a".."z").each do |v| - @hist.push v - end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do - pry - end - - str_output.string.each_line.count.should == 4 - str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/ - end - - # strangeness in this test is due to bug in Readline::HISTORY not - # always registering first line of input - it 'should show lines between lines A and B with the --show switch' do - push_first_hist_line.call(@hist, "0") - ("a".."z").each do |v| - @hist.push v - end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do - pry - end - - str_output.string.each_line.count.should == 4 - str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/ - end - end - - describe "show-method" do - it 'should output a method\'s source' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-method sample_method", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /def sample/ - end - - it 'should output a method\'s source with line numbers' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /\d+: def sample/ - end - - it 'should output a method\'s source if inside method without needing to use method name' do - $str_output = StringIO.new - - o = Object.new - def o.sample - redirect_pry_io(InputTester.new("show-method", "exit-all"), $str_output) do - binding.pry - end - end - o.sample - - $str_output.string.should =~ /def o.sample/ - $str_output = nil - end - - it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do - $str_output = StringIO.new - - o = Object.new - def o.sample - redirect_pry_io(InputTester.new("show-method -l", "exit-all"), $str_output) do - binding.pry - end - end - o.sample - - $str_output.string.should =~ /\d+: def o.sample/ - $str_output = nil - end - - # dynamically defined method source retrieval is only supported in - # 1.9 - where Method#source_location is native - if RUBY_VERSION =~ /1.9/ - it 'should output a method\'s source for a method defined inside pry' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /def dyna_method/ - Object.remove_method :dyna_method - end - - it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /def dyna_method/ - Object.remove_method :dyna_method - end - - it 'should output an instance method\'s source for a method defined inside pry' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-method A#yo"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /def yo/ - Object.remove_const :A - end - - it 'should output an instance method\'s source for a method defined inside pry using define_method' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "end", "show-method A#yup"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /define_method\(:yup\)/ - Object.remove_const :A - end - end - end - - describe "show-doc" do - it 'should output a method\'s documentation' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /sample doc/ - end - - it 'should output a method\'s documentation if inside method without needing to use method name' do - $str_output = StringIO.new - - o = Object.new - - # sample comment - def o.sample - redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do - binding.pry - end - end - o.sample - - $str_output.string.should =~ /sample comment/ - $str_output = nil - end - end - - - describe "cd" do - it 'should cd into simple input' do - b = Pry.binding_for(Object.new) - b.eval("x = :mon_ouie") - - redirect_pry_io(InputTester.new("cd x", "$obj = self", "exit-all"), StringIO.new) do - b.pry - end - - $obj.should == :mon_ouie - end - - it 'should break out of session with cd ..' do - b = Pry.binding_for(:outer) - b.eval("x = :inner") - - redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd ..", "$outer = self", "exit-all"), StringIO.new) do - b.pry - end - $inner.should == :inner - $outer.should == :outer - end - - it 'should break out to outer-most session with cd /' do - b = Pry.binding_for(:outer) - b.eval("x = :inner") - - redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd /", "$outer = self", "exit-all"), StringIO.new) do - b.pry - end - $inner.should == :inner - $five.should == 5 - $outer.should == :outer - end - - it 'should start a session on TOPLEVEL_BINDING with cd ::' do - b = Pry.binding_for(:outer) - - redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do - 5.pry - end - $obj.should == TOPLEVEL_BINDING.eval('self') - end - - it 'should cd into complex input (with spaces)' do - o = Object.new - def o.hello(x, y, z) - :mon_ouie - end - - redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "$obj = self", "exit-all"), StringIO.new) do - o.pry - end - $obj.should == :mon_ouie - end - end - - # show-command only works in implementations that support Proc#source_location - if Proc.method_defined?(:source_location) - describe "show-command" do - it 'should show source for an ordinary command' do - set = Pry::CommandSet.new do - import_from Pry::Commands, "show-command" - command "foo" do - :body_of_foo - end - end - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-command foo"), str_output) do - Pry.new(:commands => set).rep - end - str_output.string.should =~ /:body_of_foo/ - end - - it 'should show source for a command with spaces in its name' do - set = Pry::CommandSet.new do - import_from Pry::Commands, "show-command" - command "foo bar" do - :body_of_foo_bar - end - end - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do - Pry.new(:commands => set).rep - end - str_output.string.should =~ /:body_of_foo_bar/ - end - - it 'should show source for a command by listing name' do - set = Pry::CommandSet.new do - import_from Pry::Commands, "show-command" - command /foo(.*)/, "", :listing => "bar" do - :body_of_foo_regex - end - end - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-command bar"), str_output) do - Pry.new(:commands => set).rep - end - str_output.string.should =~ /:body_of_foo_regex/ - end - end - end - describe "help" do it 'should display help for a specific command' do str_output = StringIO.new diff --git a/test/test_default_commands/test_context.rb b/test/test_default_commands/test_context.rb new file mode 100644 index 00000000..93c5f237 --- /dev/null +++ b/test/test_default_commands/test_context.rb @@ -0,0 +1,64 @@ +require 'helper' + +describe "Pry::DefaultCommands::Context" do + describe "cd" do + after do + $obj = nil + end + + it 'should cd into simple input' do + b = Pry.binding_for(Object.new) + b.eval("x = :mon_ouie") + + redirect_pry_io(InputTester.new("cd x", "$obj = self", "exit-all"), StringIO.new) do + b.pry + end + + $obj.should == :mon_ouie + end + + it 'should break out of session with cd ..' do + b = Pry.binding_for(:outer) + b.eval("x = :inner") + + redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd ..", "$outer = self", "exit-all"), StringIO.new) do + b.pry + end + $inner.should == :inner + $outer.should == :outer + end + + it 'should break out to outer-most session with cd /' do + b = Pry.binding_for(:outer) + b.eval("x = :inner") + + redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd /", "$outer = self", "exit-all"), StringIO.new) do + b.pry + end + $inner.should == :inner + $five.should == 5 + $outer.should == :outer + end + + it 'should start a session on TOPLEVEL_BINDING with cd ::' do + b = Pry.binding_for(:outer) + + redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do + 5.pry + end + $obj.should == TOPLEVEL_BINDING.eval('self') + end + + it 'should cd into complex input (with spaces)' do + o = Object.new + def o.hello(x, y, z) + :mon_ouie + end + + redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "$obj = self", "exit-all"), StringIO.new) do + o.pry + end + $obj.should == :mon_ouie + end + end +end diff --git a/test/test_default_commands/test_documentation.rb b/test/test_default_commands/test_documentation.rb new file mode 100644 index 00000000..235c29b9 --- /dev/null +++ b/test/test_default_commands/test_documentation.rb @@ -0,0 +1,31 @@ +require 'helper' + +describe "Pry::DefaultCommands::Documentation" do + describe "show-doc" do + it 'should output a method\'s documentation' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /sample doc/ + end + + it 'should output a method\'s documentation if inside method without needing to use method name' do + $str_output = StringIO.new + + o = Object.new + + # sample comment + def o.sample + redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do + binding.pry + end + end + o.sample + + $str_output.string.should =~ /sample comment/ + $str_output = nil + end + end +end diff --git a/test/test_default_commands/test_input.rb b/test/test_default_commands/test_input.rb new file mode 100644 index 00000000..6831563e --- /dev/null +++ b/test/test_default_commands/test_input.rb @@ -0,0 +1,135 @@ +require 'helper' + +describe "Pry::DefaultCommands::Input" do + + describe "amend-line-N" do + it 'should correctly amend the last line of input when no line number specified ' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/ + end + + it 'should correctly amend the specified line of input when line number given ' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line-0 def goodbye", "show-input", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/ + end + end + + describe "hist" do + push_first_hist_line = lambda do |hist, line| + hist.push line + end + + before do + Readline::HISTORY.shift until Readline::HISTORY.empty? + @hist = Readline::HISTORY + end + + it 'should display the correct history' do + push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") + @hist.push "hello" + @hist.push "world" + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /hello\n.*world/ + end + + it 'should replay history correctly (single item)' do + push_first_hist_line.call(@hist, ":hello") + @hist.push ":blah" + @hist.push ":bucket" + @hist.push ":ostrich" + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /ostrich/ + end + + it 'should replay a range of history correctly (range of items)' do + push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") + @hist.push ":hello" + @hist.push ":carl" + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /:hello\n.*:carl/ + end + + it 'should grep for correct lines in history' do + push_first_hist_line.call(@hist, "apple") + @hist.push "abby" + @hist.push "box" + @hist.push "button" + @hist.push "pepper" + @hist.push "orange" + @hist.push "grape" + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/ + end + + it 'should return last N lines in history with --tail switch' do + push_first_hist_line.call(@hist, "0") + ("a".."z").each do |v| + @hist.push v + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do + pry + end + + str_output.string.each_line.count.should == 3 + str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/ + end + + # strangeness in this test is due to bug in Readline::HISTORY not + # always registering first line of input + it 'should return first N lines in history with --head switch' do + push_first_hist_line.call(@hist, "0") + ("a".."z").each do |v| + @hist.push v + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do + pry + end + + str_output.string.each_line.count.should == 4 + str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/ + end + + # strangeness in this test is due to bug in Readline::HISTORY not + # always registering first line of input + it 'should show lines between lines A and B with the --show switch' do + push_first_hist_line.call(@hist, "0") + ("a".."z").each do |v| + @hist.push v + end + + str_output = StringIO.new + redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do + pry + end + + str_output.string.each_line.count.should == 4 + str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/ + end + end + + +end diff --git a/test/test_default_commands/test_introspection.rb b/test/test_default_commands/test_introspection.rb new file mode 100644 index 00000000..0ccc3e1f --- /dev/null +++ b/test/test_default_commands/test_introspection.rb @@ -0,0 +1,146 @@ +require 'helper' + +describe "Pry::DefaultCommands::Introspection" do + describe "show-method" do + it 'should output a method\'s source' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-method sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /def sample/ + end + + it 'should output a method\'s source with line numbers' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /\d+: def sample/ + end + + it 'should output a method\'s source if inside method without needing to use method name' do + $str_output = StringIO.new + + o = Object.new + def o.sample + redirect_pry_io(InputTester.new("show-method", "exit-all"), $str_output) do + binding.pry + end + end + o.sample + + $str_output.string.should =~ /def o.sample/ + $str_output = nil + end + + it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do + $str_output = StringIO.new + + o = Object.new + def o.sample + redirect_pry_io(InputTester.new("show-method -l", "exit-all"), $str_output) do + binding.pry + end + end + o.sample + + $str_output.string.should =~ /\d+: def o.sample/ + $str_output = nil + end + + # dynamically defined method source retrieval is only supported in + # 1.9 - where Method#source_location is native + if RUBY_VERSION =~ /1.9/ + it 'should output a method\'s source for a method defined inside pry' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /def dyna_method/ + Object.remove_method :dyna_method + end + + it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /def dyna_method/ + Object.remove_method :dyna_method + end + + it 'should output an instance method\'s source for a method defined inside pry' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-method A#yo"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /def yo/ + Object.remove_const :A + end + + it 'should output an instance method\'s source for a method defined inside pry using define_method' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "end", "show-method A#yup"), str_output) do + TOPLEVEL_BINDING.pry + end + + str_output.string.should =~ /define_method\(:yup\)/ + Object.remove_const :A + end + end + end + + # show-command only works in implementations that support Proc#source_location + if Proc.method_defined?(:source_location) + describe "show-command" do + it 'should show source for an ordinary command' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command "foo" do + :body_of_foo + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command foo"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo/ + end + + it 'should show source for a command with spaces in its name' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command "foo bar" do + :body_of_foo_bar + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo_bar/ + end + + it 'should show source for a command by listing name' do + set = Pry::CommandSet.new do + import_from Pry::Commands, "show-command" + command /foo(.*)/, "", :listing => "bar" do + :body_of_foo_regex + end + end + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-command bar"), str_output) do + Pry.new(:commands => set).rep + end + str_output.string.should =~ /:body_of_foo_regex/ + end + end + end + + +end From 0cf048e2a65e8e3ba8bfa1ec98f35746d72519a9 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 03:28:27 +1200 Subject: [PATCH 34/46] added failing test for regex command interpolatino --- lib/pry/command_processor.rb | 13 +- test/default_commands/test_context.rb | 64 --------- test/default_commands/test_documentation.rb | 31 ----- test/default_commands/test_input.rb | 135 ------------------ test/default_commands/test_introspection.rb | 146 -------------------- test/test_pry.rb | 18 +++ 6 files changed, 28 insertions(+), 379 deletions(-) delete mode 100644 test/default_commands/test_context.rb delete mode 100644 test/default_commands/test_documentation.rb delete mode 100644 test/default_commands/test_input.rb delete mode 100644 test/default_commands/test_introspection.rb diff --git a/lib/pry/command_processor.rb b/lib/pry/command_processor.rb index 697c9077..cbc0e585 100644 --- a/lib/pry/command_processor.rb +++ b/lib/pry/command_processor.rb @@ -63,12 +63,19 @@ class Pry # multi-line input. # @param [Binding] target The receiver of the commands. def process_commands(val, eval_string, target) - command, captures, pos = command_matched(val) # no command was matched, so return to caller - return if !command + return if !valid_command?(val) + command, captures, pos = command_matched(val) + + + # perform ruby interpolation for commands + if command.options[:interpolate] + val.replace interpolate_string(val, target) + # command, captures, pos = command_matched(val) +# captures = captures.map { |v| interpolate_string(v, target) if v } + end - val.replace interpolate_string(val, target) if command.options[:interpolate] arg_string = val[pos..-1].strip args = arg_string ? Shellwords.shellwords(arg_string) : [] diff --git a/test/default_commands/test_context.rb b/test/default_commands/test_context.rb deleted file mode 100644 index 93c5f237..00000000 --- a/test/default_commands/test_context.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'helper' - -describe "Pry::DefaultCommands::Context" do - describe "cd" do - after do - $obj = nil - end - - it 'should cd into simple input' do - b = Pry.binding_for(Object.new) - b.eval("x = :mon_ouie") - - redirect_pry_io(InputTester.new("cd x", "$obj = self", "exit-all"), StringIO.new) do - b.pry - end - - $obj.should == :mon_ouie - end - - it 'should break out of session with cd ..' do - b = Pry.binding_for(:outer) - b.eval("x = :inner") - - redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd ..", "$outer = self", "exit-all"), StringIO.new) do - b.pry - end - $inner.should == :inner - $outer.should == :outer - end - - it 'should break out to outer-most session with cd /' do - b = Pry.binding_for(:outer) - b.eval("x = :inner") - - redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd /", "$outer = self", "exit-all"), StringIO.new) do - b.pry - end - $inner.should == :inner - $five.should == 5 - $outer.should == :outer - end - - it 'should start a session on TOPLEVEL_BINDING with cd ::' do - b = Pry.binding_for(:outer) - - redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do - 5.pry - end - $obj.should == TOPLEVEL_BINDING.eval('self') - end - - it 'should cd into complex input (with spaces)' do - o = Object.new - def o.hello(x, y, z) - :mon_ouie - end - - redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "$obj = self", "exit-all"), StringIO.new) do - o.pry - end - $obj.should == :mon_ouie - end - end -end diff --git a/test/default_commands/test_documentation.rb b/test/default_commands/test_documentation.rb deleted file mode 100644 index 235c29b9..00000000 --- a/test/default_commands/test_documentation.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'helper' - -describe "Pry::DefaultCommands::Documentation" do - describe "show-doc" do - it 'should output a method\'s documentation' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /sample doc/ - end - - it 'should output a method\'s documentation if inside method without needing to use method name' do - $str_output = StringIO.new - - o = Object.new - - # sample comment - def o.sample - redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do - binding.pry - end - end - o.sample - - $str_output.string.should =~ /sample comment/ - $str_output = nil - end - end -end diff --git a/test/default_commands/test_input.rb b/test/default_commands/test_input.rb deleted file mode 100644 index 6831563e..00000000 --- a/test/default_commands/test_input.rb +++ /dev/null @@ -1,135 +0,0 @@ -require 'helper' - -describe "Pry::DefaultCommands::Input" do - - describe "amend-line-N" do - it 'should correctly amend the last line of input when no line number specified ' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/ - end - - it 'should correctly amend the specified line of input when line number given ' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line-0 def goodbye", "show-input", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/ - end - end - - describe "hist" do - push_first_hist_line = lambda do |hist, line| - hist.push line - end - - before do - Readline::HISTORY.shift until Readline::HISTORY.empty? - @hist = Readline::HISTORY - end - - it 'should display the correct history' do - push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") - @hist.push "hello" - @hist.push "world" - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /hello\n.*world/ - end - - it 'should replay history correctly (single item)' do - push_first_hist_line.call(@hist, ":hello") - @hist.push ":blah" - @hist.push ":bucket" - @hist.push ":ostrich" - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /ostrich/ - end - - it 'should replay a range of history correctly (range of items)' do - push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'") - @hist.push ":hello" - @hist.push ":carl" - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /:hello\n.*:carl/ - end - - it 'should grep for correct lines in history' do - push_first_hist_line.call(@hist, "apple") - @hist.push "abby" - @hist.push "box" - @hist.push "button" - @hist.push "pepper" - @hist.push "orange" - @hist.push "grape" - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/ - end - - it 'should return last N lines in history with --tail switch' do - push_first_hist_line.call(@hist, "0") - ("a".."z").each do |v| - @hist.push v - end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do - pry - end - - str_output.string.each_line.count.should == 3 - str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/ - end - - # strangeness in this test is due to bug in Readline::HISTORY not - # always registering first line of input - it 'should return first N lines in history with --head switch' do - push_first_hist_line.call(@hist, "0") - ("a".."z").each do |v| - @hist.push v - end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do - pry - end - - str_output.string.each_line.count.should == 4 - str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/ - end - - # strangeness in this test is due to bug in Readline::HISTORY not - # always registering first line of input - it 'should show lines between lines A and B with the --show switch' do - push_first_hist_line.call(@hist, "0") - ("a".."z").each do |v| - @hist.push v - end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do - pry - end - - str_output.string.each_line.count.should == 4 - str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/ - end - end - - -end diff --git a/test/default_commands/test_introspection.rb b/test/default_commands/test_introspection.rb deleted file mode 100644 index 0ccc3e1f..00000000 --- a/test/default_commands/test_introspection.rb +++ /dev/null @@ -1,146 +0,0 @@ -require 'helper' - -describe "Pry::DefaultCommands::Introspection" do - describe "show-method" do - it 'should output a method\'s source' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-method sample_method", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /def sample/ - end - - it 'should output a method\'s source with line numbers' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do - pry - end - - str_output.string.should =~ /\d+: def sample/ - end - - it 'should output a method\'s source if inside method without needing to use method name' do - $str_output = StringIO.new - - o = Object.new - def o.sample - redirect_pry_io(InputTester.new("show-method", "exit-all"), $str_output) do - binding.pry - end - end - o.sample - - $str_output.string.should =~ /def o.sample/ - $str_output = nil - end - - it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do - $str_output = StringIO.new - - o = Object.new - def o.sample - redirect_pry_io(InputTester.new("show-method -l", "exit-all"), $str_output) do - binding.pry - end - end - o.sample - - $str_output.string.should =~ /\d+: def o.sample/ - $str_output = nil - end - - # dynamically defined method source retrieval is only supported in - # 1.9 - where Method#source_location is native - if RUBY_VERSION =~ /1.9/ - it 'should output a method\'s source for a method defined inside pry' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /def dyna_method/ - Object.remove_method :dyna_method - end - - it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /def dyna_method/ - Object.remove_method :dyna_method - end - - it 'should output an instance method\'s source for a method defined inside pry' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-method A#yo"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /def yo/ - Object.remove_const :A - end - - it 'should output an instance method\'s source for a method defined inside pry using define_method' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "end", "show-method A#yup"), str_output) do - TOPLEVEL_BINDING.pry - end - - str_output.string.should =~ /define_method\(:yup\)/ - Object.remove_const :A - end - end - end - - # show-command only works in implementations that support Proc#source_location - if Proc.method_defined?(:source_location) - describe "show-command" do - it 'should show source for an ordinary command' do - set = Pry::CommandSet.new do - import_from Pry::Commands, "show-command" - command "foo" do - :body_of_foo - end - end - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-command foo"), str_output) do - Pry.new(:commands => set).rep - end - str_output.string.should =~ /:body_of_foo/ - end - - it 'should show source for a command with spaces in its name' do - set = Pry::CommandSet.new do - import_from Pry::Commands, "show-command" - command "foo bar" do - :body_of_foo_bar - end - end - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do - Pry.new(:commands => set).rep - end - str_output.string.should =~ /:body_of_foo_bar/ - end - - it 'should show source for a command by listing name' do - set = Pry::CommandSet.new do - import_from Pry::Commands, "show-command" - command /foo(.*)/, "", :listing => "bar" do - :body_of_foo_regex - end - end - str_output = StringIO.new - redirect_pry_io(InputTester.new("show-command bar"), str_output) do - Pry.new(:commands => set).rep - end - str_output.string.should =~ /:body_of_foo_regex/ - end - end - end - - -end diff --git a/test/test_pry.rb b/test/test_pry.rb index 9413f4c7..b3a9b1d2 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -479,6 +479,24 @@ describe Pry do str_output.string.should =~ /hello 1 baby/ end + it 'should create a regex command and interpolate the captures' do + set = Pry::CommandSet.new do + command /hello (.*)/, "" do |c1| + output.puts "hello #{c1}" + end + end + + str_output = StringIO.new + $obj = "bing" + redirect_pry_io(InputTester.new('hello #{$obj}'), str_output) do + Pry.new(:commands => set).rep + end + +# binding.pry + str_output.string.should =~ /hello bing/ + $obj = nil + end + it 'if a regex capture is missing it should be nil' do set = Pry::CommandSet.new do command /hello(.)?/, "" do |c1, a1| From e9a1222b59d194981c9bc96f78cb1db77bf0686f Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 03:31:32 +1200 Subject: [PATCH 35/46] support for rubinius core source and doc browsing in both rvm installs and git installs --- lib/pry/helpers/command_helpers.rb | 53 ++++++++++++++++-------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index e3313f4a..4a7cd107 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -69,38 +69,43 @@ class Pry end def rbx_core_code_or_doc_for(meth, code_or_doc) - if rvm_ruby?(Rubinius::BIN_PATH) - rvm_rbx_core_code_or_doc_for(meth, code_or_doc) - else - std_rbx_core_code_or_doc_for(meth, code_or_doc) + path_line = rbx_core_path_line_for(meth) + + case code_or_doc + when :code + MethodSource.source_helper(path_line) + when :doc + MethodSource.comment_helper(path_line) end end - def std_rbx_core_code_or_doc_for(meth, code_or_doc) + def rbx_core_path_line_for(meth) + if rvm_ruby?(Rubinius::BIN_PATH) + rvm_rbx_core_path_line_for(meth) + else + std_rbx_core_path_line_for(meth) + end + end + + def std_rbx_core_path_line_for(meth) file_name = File.join(Rubinius::BIN_PATH, "..", meth.source_location.first) raise "Cannot find rbx core source" if !File.exists?(file_name) - start_line meth.source_location.last - case code_or_doc - when :code - MethodSource.source_helper([file_name, start_line]) - when :doc - MethodSource.comment_helper([file_name, start_line]) - end - end - - def rvm_rbx_core_code_or_doc_for(meth, code_or_doc) - ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last - source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name) - file_name = File.join(source_path, meth.source_location.first) start_line = meth.source_location.last - case code_or_doc - when :code - MethodSource.source_helper([file_name, start_line]) - when :doc - MethodSource.comment_helper([file_name, start_line]) - end + [file_name, start_line] + end + + def rvm_rbx_core_path_line_for(meth) + ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last + source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name) + + file_name = File.join(source_path, meth.source_location.first) + raise "Cannot find rbx core source" if !File.exists?(file_name) + + start_line = meth.source_location.last + + [file_name, start_line] end ######### END RBX HELPERS ############### From 81d44b06740a1a7f3ff0415202a65a9e44ed6330 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 21:50:50 +1200 Subject: [PATCH 36/46] allow edit-method to edit rbx core methods using the full path; also added path_line_for helper to wrap source_location and so support rbx core methods too --- lib/pry/default_commands/introspection.rb | 7 ++++++- lib/pry/helpers/command_helpers.rb | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 42147ea4..14fc51fd 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -136,7 +136,12 @@ class Pry # editor is invoked here else - file, line = meth.source_location + if rbx_core?(meth) + file, line = rbx_core_path_line_for(meth) + else + file, line = meth.source_location + end + set_file_and_dir_locals(file) if Pry.editor.respond_to?(:call) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 4a7cd107..990eb610 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -129,7 +129,7 @@ class Pry code = strip_leading_whitespace(meth.source) end end - set_file_and_dir_locals(meth.source_location.first) + set_file_and_dir_locals(path_line_for(meth).first) end [code, code_type] @@ -147,7 +147,7 @@ class Pry else doc = strip_leading_hash_and_whitespace_from_ruby_comments(meth.comment) end - set_file_and_dir_locals(meth.source_location.first) + set_file_and_dir_locals(path_line_for(meth).first) end [doc, code_type] @@ -187,11 +187,19 @@ class Pry end end + def path_line_for(meth) + if rbx_core?(meth) + rbx_core_path_line_for(meth) + else + meth.source_location + end + end + def make_header(meth, code_type, content) num_lines = "Number of lines: #{Pry::Helpers::Text.bold(content.each_line.count.to_s)}" case code_type when :ruby - file, line = meth.source_location + file, line = path_line_for(meth) "\n#{Pry::Helpers::Text.bold('From:')} #{file} @ line #{line}:\n#{num_lines}\n\n" else file = Pry::MethodInfo.info_for(meth).file From 5c9dbe82b35804c71f8ad25c7bf57a291dd26226 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 21:51:41 +1200 Subject: [PATCH 37/46] removed obsolete try_to_load_pry_doc helper --- lib/pry/helpers/command_helpers.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 990eb610..283348de 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -5,15 +5,6 @@ class Pry module_function - def try_to_load_pry_doc - - # YARD crashes on rbx, so do not require it - if !Object.const_defined?(:RUBY_ENGINE) || RUBY_ENGINE !~ /rbx/ - require "pry-doc" - end - rescue LoadError - end - def meth_name_from_binding(b) meth_name = b.eval('__method__') if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name) From cef1d2f6c6e51c0cee2bc5bba27d6bda415abb0b Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 21:55:06 +1200 Subject: [PATCH 38/46] just substituted 'text' for 'doc' in render_output() helper method for clarity --- lib/pry/helpers/command_helpers.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 283348de..dea56fcf 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -15,15 +15,15 @@ class Pry end # if start_line is not false then add line numbers starting with start_line - def render_output(should_flood, start_line, doc) + def render_output(should_flood, start_line, text) if start_line - doc = Pry::Helpers::Text.with_line_numbers doc, start_line + text = Pry::Helpers::Text.with_line_numbers text, start_line end if should_flood - output.puts doc + output.puts text else - stagger_output(doc) + stagger_output(text) end end From 9a245adb04d9dcfb0d0475931e187b38f9bcf099 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 3 Jun 2011 21:55:23 +1200 Subject: [PATCH 39/46] added tests for show-input and \! commands --- test/test_default_commands/test_input.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/test_default_commands/test_input.rb b/test/test_default_commands/test_input.rb index 6831563e..3a20162b 100644 --- a/test/test_default_commands/test_input.rb +++ b/test/test_default_commands/test_input.rb @@ -20,6 +20,28 @@ describe "Pry::DefaultCommands::Input" do end end + describe "show-input" do + it 'should correctly show the current lines in the input buffer' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def hello", "puts :bing", "show-input", "exit-all"), str_output) do + pry + end + str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing/ + end + end + + describe "!" do + it 'should correctly clear the input buffer ' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("def hello", "puts :bing", "!", "show-input", "exit-all"), str_output) do + pry + end + stripped_output = str_output.string.strip! + stripped_output.each_line.count.should == 1 + stripped_output.should =~ /Input buffer cleared!/ + end + end + describe "hist" do push_first_hist_line = lambda do |hist, line| hist.push line From 166e6e8f0bdb96669a89e10b3455776735b896a2 Mon Sep 17 00:00:00 2001 From: John Mair Date: Sat, 4 Jun 2011 01:08:42 +1200 Subject: [PATCH 40/46] added --no-plugins command line option to executable, removed unnecessary whitespace from introspectin.rb --- bin/pry | 5 ++++- lib/pry/default_commands/introspection.rb | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/pry b/bin/pry index 4cfd464b..0a0d4b7e 100644 --- a/bin/pry +++ b/bin/pry @@ -22,7 +22,7 @@ See: `https://github.com/banister` for more information. on :e, :exec, "A line of code to execute in context before the session starts", true on :f, "Suppress loading of ~/.pryrc" on "no-color", "Disable syntax highlighting for session" - + on "no-plugins", "Suppress loading of plugins." on "simple-prompt", "Enable simple prompt mode" do Pry.prompt = Pry::SIMPLE_PROMPT end @@ -53,6 +53,9 @@ Pry.cli = true # load ~/.pryrc, if not suppressed with -f option Pry.config.should_load_rc = !opts.f? +# suppress plugins if given --no-plugins optino +Pry.config.plugins.enabled = false if opts["no-plugins"] + # create the actual context context = Pry.binding_for(eval(opts[:context])) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 14fc51fd..118d1e1c 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -159,7 +159,6 @@ class Pry end end - helpers do def start_line_for_editor(line_number) From ffb9670b7ffb5ff0ce213c60a70ab146645f7454 Mon Sep 17 00:00:00 2001 From: John Mair Date: Sat, 4 Jun 2011 03:09:24 +1200 Subject: [PATCH 41/46] replaced implementation tests in edit-method with path_line_for --- lib/pry/default_commands/introspection.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 118d1e1c..cd528813 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -136,12 +136,7 @@ class Pry # editor is invoked here else - if rbx_core?(meth) - file, line = rbx_core_path_line_for(meth) - else - file, line = meth.source_location - end - + file, line = path_line_for(meth) set_file_and_dir_locals(file) if Pry.editor.respond_to?(:call) From 570ff75cdd2f9a064a0d6c7eec7f92d273ce1264 Mon Sep 17 00:00:00 2001 From: John Mair Date: Sun, 5 Jun 2011 03:59:05 +1200 Subject: [PATCH 42/46] added --no-pager to binary options, and refactored options --- bin/pry | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/bin/pry b/bin/pry index 0a0d4b7e..e1100070 100644 --- a/bin/pry +++ b/bin/pry @@ -20,9 +20,25 @@ See: `https://github.com/banister` for more information. } on :e, :exec, "A line of code to execute in context before the session starts", true - on :f, "Suppress loading of ~/.pryrc" - on "no-color", "Disable syntax highlighting for session" - on "no-plugins", "Suppress loading of plugins." + + on "no-pager", "Disable pager for long output" do + Pry.pager = false + end + + on "no-color", "Disable syntax highlighting for session" do + Pry.color = false + end + + on :f, "Suppress loading of ~/.pryrc" do + # load ~/.pryrc, if not suppressed with -f option + Pry.config.should_load_rc = false + end + + on "no-plugins", "Suppress loading of plugins." do + # suppress plugins if given --no-plugins optino + Pry.config.plugins.enabled = false + end + on "simple-prompt", "Enable simple prompt mode" do Pry.prompt = Pry::SIMPLE_PROMPT end @@ -50,12 +66,6 @@ end # invoked via cli Pry.cli = true -# load ~/.pryrc, if not suppressed with -f option -Pry.config.should_load_rc = !opts.f? - -# suppress plugins if given --no-plugins optino -Pry.config.plugins.enabled = false if opts["no-plugins"] - # create the actual context context = Pry.binding_for(eval(opts[:context])) From 6d4e30f4a7a74f3cbdad0724fcb8e11c58434f6d Mon Sep 17 00:00:00 2001 From: John Mair Date: Sun, 5 Jun 2011 04:01:12 +1200 Subject: [PATCH 43/46] switched shortoptions for --no-jump and --no-reload for edit-method, -n now means --no-reload --- lib/pry/default_commands/introspection.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index cd528813..00a14243 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -109,8 +109,8 @@ class Pry opt.on :M, "instance-methods", "Operate on instance methods." opt.on :m, :methods, "Operate on methods." - opt.on "no-reload", "Do not automatically reload the method's file after editting." - opt.on :n, "no-jump", "Do not fast forward editor to first line of method." + opt.on :n, "no-reload", "Do not automatically reload the method's file after editting." + opt.on "no-jump", "Do not fast forward editor to first line of method." opt.on :c, :context, "Select object context to run under.", true do |context| target = Pry.binding_for(target.eval(context)) end @@ -143,13 +143,13 @@ class Pry editor_invocation = Pry.editor.call(file, line) else # only use start line if -n option is not used - start_line_syntax = opts.n? ? "" : start_line_for_editor(line) + start_line_syntax = opts["no-jump"] ? "" : start_line_for_editor(line) editor_invocation = "#{Pry.editor} #{start_line_syntax} #{file}" end run ".#{editor_invocation}" silence_warnings do - load file if !opts["no-reload"] + load file if !opts.n? end end end From 71ccee62c87a3122f234488f4a698910767b38ef Mon Sep 17 00:00:00 2001 From: John Mair Date: Sun, 5 Jun 2011 04:01:36 +1200 Subject: [PATCH 44/46] bump version to 0.9.0pre2 --- lib/pry/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pry/version.rb b/lib/pry/version.rb index 248290a6..6bfb58fe 100644 --- a/lib/pry/version.rb +++ b/lib/pry/version.rb @@ -1,3 +1,3 @@ class Pry - VERSION = "0.9.0pre1" + VERSION = "0.9.0pre2" end From 3b1cac2efd0d96c4df198b87320ba1f39be3ba38 Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 6 Jun 2011 03:30:36 +1200 Subject: [PATCH 45/46] fixed regex command string interpolation --- lib/pry/command_processor.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/pry/command_processor.rb b/lib/pry/command_processor.rb index cbc0e585..69fdd8f0 100644 --- a/lib/pry/command_processor.rb +++ b/lib/pry/command_processor.rb @@ -67,16 +67,15 @@ class Pry # no command was matched, so return to caller return if !valid_command?(val) command, captures, pos = command_matched(val) - + arg_string = val[pos..-1].strip # perform ruby interpolation for commands if command.options[:interpolate] val.replace interpolate_string(val, target) - # command, captures, pos = command_matched(val) -# captures = captures.map { |v| interpolate_string(v, target) if v } + arg_string.replace interpolate_string(arg_string, target) + captures = captures.map { |v| interpolate_string(v, target) if v } end - arg_string = val[pos..-1].strip args = arg_string ? Shellwords.shellwords(arg_string) : [] options = { From 12956b20b9e3f8c839544febe221d1ca3b69c2ea Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 6 Jun 2011 03:31:36 +1200 Subject: [PATCH 46/46] added tests for regex command interpolation behaviour. All test in test suite should now pass. --- test/test_pry.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/test_pry.rb b/test/test_pry.rb index b3a9b1d2..5c102cfa 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -492,11 +492,33 @@ describe Pry do Pry.new(:commands => set).rep end -# binding.pry str_output.string.should =~ /hello bing/ $obj = nil end + it 'should create a regex command and arg_string should be interpolated' do + set = Pry::CommandSet.new do + command /hello(\w+)/, "" do |c1, a1, a2, a3| + output.puts "hello #{c1} #{a1} #{a2} #{a3}" + end + end + + str_output = StringIO.new + $a1 = "bing" + $a2 = "bong" + $a3 = "bang" + redirect_pry_io(InputTester.new('hellojohn #{$a1} #{$a2} #{$a3}'), str_output) do + Pry.new(:commands => set).rep + end + + str_output.string.should =~ /hello john bing bong bang/ + + $a1 = nil + $a2 = nil + $a3 = nil + end + + it 'if a regex capture is missing it should be nil' do set = Pry::CommandSet.new do command /hello(.)?/, "" do |c1, a1|