1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Merge branch 'master' into wip-config

Conflicts:
	lib/pry.rb
This commit is contained in:
Robert Gleeson 2014-01-20 08:43:36 +01:00
commit 5177913c91
20 changed files with 1291 additions and 1386 deletions

View file

@ -37,8 +37,9 @@ class Pry
# Read the class name off of the singleton class to provide a default # Read the class name off of the singleton class to provide a default
# inspect. # inspect.
eig = class << obj; self; end singleton = class << obj; self; end
klass = Pry::Method.safe_send(eig, :ancestors).first ancestors = Pry::Method.safe_send(singleton, :ancestors)
klass = ancestors.reject { |k| k == singleton }.first
obj_id = obj.__id__.to_s(16) rescue 0 obj_id = obj.__id__.to_s(16) rescue 0
str = "#<#{klass}:0x#{obj_id}>" str = "#<#{klass}:0x#{obj_id}>"

View file

@ -6,8 +6,6 @@ class Pry
group 'Context' group 'Context'
description 'Recursively search for a method within a Class/Module or the current namespace.' description 'Recursively search for a method within a Class/Module or the current namespace.'
command_options :shellwords => false command_options :shellwords => false
command_options :requires_gem => 'ruby18_source_location' if mri_18?
banner <<-'BANNER' banner <<-'BANNER'
Usage: find-method [-n|-c] METHOD [NAMESPACE] Usage: find-method [-n|-c] METHOD [NAMESPACE]
@ -26,10 +24,6 @@ class Pry
find-method -c 'output.puts' Pry find-method -c 'output.puts' Pry
BANNER BANNER
def setup
require 'ruby18_source_location' if mri_18?
end
def options(opti) def options(opti)
opti.on :n, :name, "Search for a method by name" opti.on :n, :name, "Search for a method by name"
opti.on :c, :content, "Search for a method based on content in Regex form" opti.on :c, :content, "Search for a method based on content in Regex form"

View file

@ -3,11 +3,6 @@ class Pry
extend Pry::Helpers::BaseHelpers extend Pry::Helpers::BaseHelpers
command_options :shellwords => false, :interpolate => false command_options :shellwords => false, :interpolate => false
command_options :requires_gem => "ruby18_source_location" if mri_18?
def setup
require 'ruby18_source_location' if mri_18?
end
def options(opt) def options(opt)
opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count

View file

@ -99,37 +99,33 @@ class Object
end end
end end
if defined?(BasicObject) class BasicObject
class BasicObject # Return a binding object for the receiver.
# Return a binding object for the receiver. #
# # The `self` of the binding is set to the current object, and it contains no
# The `self` of the binding is set to the current object, and it contains no # local variables.
# local variables. #
# # The default definee (http://yugui.jp/articles/846) is set such that new
# The default definee (http://yugui.jp/articles/846) is set such that new # methods defined will be added to the singleton class of the BasicObject.
# methods defined will be added to the singleton class of the BasicObject. #
# # @return [Binding]
# @return [Binding] def __binding__
def __binding__ # BasicObjects don't have respond_to?, so we just define the method
# BasicObjects don't have respond_to?, so we just define the method # every time. As they also don't have `.freeze`, this call won't
# every time. As they also don't have `.freeze`, this call won't # fail as it can for normal Objects.
# fail as it can for normal Objects. (class << self; self; end).class_eval <<-EOF, __FILE__, __LINE__ + 1
(class << self; self; end).class_eval <<-EOF, __FILE__, __LINE__ + 1 # Get a binding with 'self' set to self, and no locals.
# Get a binding with 'self' set to self, and no locals. #
# # The default definee is determined by the context in which the
# The default definee is determined by the context in which the # definition is eval'd.
# definition is eval'd. #
# # Please don't call this method directly, see {__binding__}.
# Please don't call this method directly, see {__binding__}. #
# # @return [Binding]
# @return [Binding] def __pry__
def __pry__ ::Kernel.binding
# In ruby-1.8.7 ::Kernel.binding sets self to Kernel in the returned binding. end
# Luckily ruby-1.8.7 doesn't have BasicObject, so this is safe. EOF
::Kernel.binding self.__pry__
end
EOF
self.__pry__
end
end end
end end

View file

@ -90,10 +90,6 @@ class Pry
RbConfig::CONFIG['ruby_install_name'] == 'ruby' RbConfig::CONFIG['ruby_install_name'] == 'ruby'
end end
def mri_18?
mri? && RUBY_VERSION =~ /1.8/
end
def mri_19? def mri_19?
mri? && RUBY_VERSION =~ /1.9/ mri? && RUBY_VERSION =~ /1.9/
end end

View file

@ -146,18 +146,14 @@ class Pry
def exec_hook(event_name, *args, &block) def exec_hook(event_name, *args, &block)
@hooks[event_name] ||= [] @hooks[event_name] ||= []
# silence warnings to get rid of 1.8's "warning: multiple values @hooks[event_name].map do |hook_name, callable|
# for a block parameter" warnings begin
Pry::Helpers::BaseHelpers.silence_warnings do callable.call(*args, &block)
@hooks[event_name].map do |hook_name, callable| rescue RescuableException => e
begin errors << e
callable.call(*args, &block) e
rescue RescuableException => e end
errors << e end.last
e
end
end.last
end
end end
# Return the number of hook functions registered for the `event_name` event. # Return the number of hook functions registered for the `event_name` event.

View file

@ -405,8 +405,6 @@ class Pry
end end
# @return [Array<String>] All known aliases for the method. # @return [Array<String>] All known aliases for the method.
# @note On Ruby 1.8 this method always returns an empty Array for methods
# implemented in C.
def aliases def aliases
owner = @method.owner owner = @method.owner
# Avoid using `to_sym` on {Method#name}, which returns a `String`, because # Avoid using `to_sym` on {Method#name}, which returns a `String`, because

View file

@ -44,7 +44,8 @@ class Pry::Terminal
require 'io/console' require 'io/console'
$stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize) $stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
rescue LoadError rescue LoadError
# They're probably on 1.8 without the io-console gem. We'll keep trying. # They probably don't have the io/console stdlib or the io-console gem.
# We'll keep trying.
end end
def screen_size_according_to_env def screen_size_according_to_env

View file

@ -47,10 +47,6 @@ module PryTestHelpers
end end
end end
def mri18_and_no_real_source_location?
Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
end
# Open a temp file and yield it to the block, closing it after # Open a temp file and yield it to the block, closing it after
# @return [String] The path of the temp file # @return [String] The path of the temp file
def temp_file(ext='.rb') def temp_file(ext='.rb')

View file

@ -66,28 +66,12 @@ class Pry
end end
# Returns an array of the names of the constants accessible in the wrapped # Returns an array of the names of the constants accessible in the wrapped
# module. This provides a consistent interface between 1.8 and 1.9 and also # module. This avoids the problem of accidentally calling the singleton
# avoids the problem of accidentally calling the singleton method # method `Module.constants`.
# `Module.constants`.
# @param [Boolean] inherit Include the names of constants from included # @param [Boolean] inherit Include the names of constants from included
# modules? # modules?
def constants(inherit = true) def constants(inherit = true)
method = Module.instance_method(:constants).bind(@wrapped) Module.instance_method(:constants).bind(@wrapped).call(inherit)
# If we're on 1.8, we have to manually remove ancestors' constants. If
# we're on 1.9, though, it's better to use the built-in `inherit` param,
# since it doesn't do things like incorrectly remove Pry::Config.
if method.arity == 0
consts = method.call
if !inherit
ancestors_ = Pry::Method.safe_send(@wrapped, :ancestors)
consts -= (ancestors_ - [@wrapped]).map(&:constants).flatten
end
else
consts = method.call(inherit)
end
consts
end end
# The prefix that would appear before methods defined on this class. # The prefix that would appear before methods defined on this class.
@ -259,7 +243,7 @@ class Pry
# @return [Enumerator, Array] on JRuby 1.9 and higher returns Array, on # @return [Enumerator, Array] on JRuby 1.9 and higher returns Array, on
# other rubies returns Enumerator # other rubies returns Enumerator
def candidates def candidates
enum = generator.new do |y| enum = Enumerator.new do |y|
(0...number_of_candidates).each do |num| (0...number_of_candidates).each do |num|
y.yield candidate(num) y.yield candidate(num)
end end
@ -292,18 +276,6 @@ class Pry
private private
# Ruby 1.8 doesn't support `Enumerator` (it's called Generator instead)
#
# @return [Object] Return the appropriate generator class.
def generator
@generator ||= if defined?(Enumerator)
Enumerator
else
require 'generator'
Generator
end
end
# @return [Pry::WrappedModule::Candidate] The candidate with the # @return [Pry::WrappedModule::Candidate] The candidate with the
# highest rank, that is the 'monkey patch' of this module with the # highest rank, that is the 'monkey patch' of this module with the
# highest number of methods, which contains a source code line that # highest number of methods, which contains a source code line that

View file

@ -664,10 +664,8 @@ describe "Pry::Command" do
pry_eval('my---test').should =~ /my-testmy-test/ pry_eval('my---test').should =~ /my-testmy-test/
end end
if !mri18_and_no_real_source_location? it "shows the source of the process method" do
it "shows the source of the process method" do pry_eval('show-source my-test').should =~ /output.puts command_name/
pry_eval('show-source my-test').should =~ /output.puts command_name/
end
end end
describe "command options hash" do describe "command options hash" do

View file

@ -1,70 +1,63 @@
require 'helper' require 'helper'
# we turn off the test for MRI 1.8 because our source_location hack MyKlass = Class.new do
# for C methods actually runs the methods - and since it runs ALL def hello
# methods (in an attempt to find a match) it runs 'exit' and aborts "timothy"
# the test, causing a failure. We should fix this in the future by end
# blacklisting certain methods for 1.8 MRI (such as exit, fork, and so on) def goodbye
unless Pry::Helpers::BaseHelpers.mri_18? "jenny"
MyKlass = Class.new do end
def hello def tea_tim?
"timothy" "timothy"
end
def tea_time?
"polly"
end
end
describe "find-method" do
describe "find matching methods by name regex (-n option)" do
it "should find a method by regex" do
pry_eval("find-method hell MyKlass").should =~
/MyKlass.*?hello/m
end end
def goodbye
"jenny" it "should NOT match a method that does not match the regex" do
end pry_eval("find-method hell MyKlass").should.not =~
def tea_tim? /MyKlass.*?goodbye/m
"timothy"
end
def tea_time?
"polly"
end end
end end
describe "find-method" do describe "find matching methods by content regex (-c option)" do
describe "find matching methods by name regex (-n option)" do it "should find a method by regex" do
it "should find a method by regex" do
pry_eval("find-method hell MyKlass").should =~
/MyKlass.*?hello/m
end
it "should NOT match a method that does not match the regex" do
pry_eval("find-method hell MyKlass").should.not =~
/MyKlass.*?goodbye/m
end
end
describe "find matching methods by content regex (-c option)" do
it "should find a method by regex" do
pry_eval("find-method -c timothy MyKlass").should =~
/MyKlass.*?hello/m
end
it "should NOT match a method that does not match the regex" do
pry_eval("find-method timothy MyKlass").should.not =~
/MyKlass.*?goodbye/m
end
end
it "should work with badly behaved constants" do
MyKlass::X = Object.new
def (MyKlass::X).hash
raise "mooo"
end
pry_eval("find-method -c timothy MyKlass").should =~ pry_eval("find-method -c timothy MyKlass").should =~
/MyKlass.*?hello/m /MyKlass.*?hello/m
end end
it "should escape regexes correctly" do it "should NOT match a method that does not match the regex" do
good = /tea_time\?/ pry_eval("find-method timothy MyKlass").should.not =~
bad = /tea_tim\?/ /MyKlass.*?goodbye/m
pry_eval('find-method tea_time? MyKlass').should =~ good
pry_eval('find-method tea_time? MyKlass').should =~ good
pry_eval('find-method tea_time\? MyKlass').should.not =~ bad
pry_eval('find-method tea_time\? MyKlass').should =~ good
end end
end end
Object.remove_const(:MyKlass) it "should work with badly behaved constants" do
MyKlass::X = Object.new
def (MyKlass::X).hash
raise "mooo"
end
pry_eval("find-method -c timothy MyKlass").should =~
/MyKlass.*?hello/m
end
it "should escape regexes correctly" do
good = /tea_time\?/
bad = /tea_tim\?/
pry_eval('find-method tea_time? MyKlass').should =~ good
pry_eval('find-method tea_time? MyKlass').should =~ good
pry_eval('find-method tea_time\? MyKlass').should.not =~ bad
pry_eval('find-method tea_time\? MyKlass').should =~ good
end
end end
Object.remove_const(:MyKlass)

View file

@ -1,7 +1,6 @@
require 'helper' require 'helper'
describe "gem-list" do describe "gem-list" do
# fixing bug for 1.8 compat
it 'should not raise when invoked' do it 'should not raise when invoked' do
proc { proc {
pry_eval(self, 'gem-list') pry_eval(self, 'gem-list')

View file

@ -34,18 +34,16 @@ describe "ls" do
end end
end end
if defined?(BasicObject) describe "BasicObject" do
describe "BasicObject" do it "should work on BasicObject" do
it "should work on BasicObject" do pry_eval("ls BasicObject.new").should =~ /BasicObject#methods:.*__send__/m
pry_eval("ls BasicObject.new").should =~ /BasicObject#methods:.*__send__/m end
end
it "should work on subclasses of BasicObject" do it "should work on subclasses of BasicObject" do
pry_eval( pry_eval(
"class LessBasic < BasicObject; def jaroussky; 5; end; end", "class LessBasic < BasicObject; def jaroussky; 5; end; end",
"ls LessBasic.new" "ls LessBasic.new"
).should =~ /LessBasic#methods:.*jaroussky/m ).should =~ /LessBasic#methods:.*jaroussky/m
end
end end
end end

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -41,16 +41,14 @@ describe "whereami" do
Object.remove_const(:Cor) Object.remove_const(:Cor)
end end
if defined?(BasicObject) it 'should work in BasicObjects' do
it 'should work in BasicObjects' do cor = Class.new(BasicObject) do
cor = Class.new(BasicObject) do def blimey!
def blimey! ::Kernel.binding # omnom
::Kernel.binding # omnom end
end end.new.blimey!
end.new.blimey!
pry_eval(cor, 'whereami').should =~ /::Kernel.binding [#] omnom/ pry_eval(cor, 'whereami').should =~ /::Kernel.binding [#] omnom/
end
end end
it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do

View file

@ -144,7 +144,8 @@ describe Pry::Method do
m.name.should == "gag" m.name.should == "gag"
end end
if defined?(BasicObject) && !Pry::Helpers::BaseHelpers.rbx? # rubinius issue 1921 # Temporarily disabled to work around rubinius/rubinius#2871.
unless Pry::Helpers::BaseHelpers.rbx?
it "should find the right method from a BasicObject" do it "should find the right method from a BasicObject" do
a = Class.new(BasicObject) { def gag; ::Kernel.binding; end; def self.line; __LINE__; end } a = Class.new(BasicObject) { def gag; ::Kernel.binding; end; def self.line; __LINE__; end }
@ -433,8 +434,8 @@ describe Pry::Method do
it "should include the Pry::Method.instance_resolution_order of Class after the singleton classes" do it "should include the Pry::Method.instance_resolution_order of Class after the singleton classes" do
Pry::Method.resolution_order(LS::Top).should == Pry::Method.resolution_order(LS::Top).should ==
[singleton_class(LS::Top), singleton_class(Object), (defined? BasicObject) && singleton_class(BasicObject)].compact + [singleton_class(LS::Top), singleton_class(Object), singleton_class(BasicObject),
Pry::Method.instance_resolution_order(Class) *Pry::Method.instance_resolution_order(Class)]
end end
end end
end end
@ -496,15 +497,11 @@ describe Pry::Method do
end end
end end
unless Pry::Helpers::BaseHelpers.mri_18? it 'should be able to find aliases for methods implemented in C' do
# Ruby 1.8 doesn't support this feature. meth = Pry::Method(Hash.new.method(:key?))
it 'should be able to find aliases for methods implemented in C' do aliases = Set.new(meth.aliases)
meth = Pry::Method(Hash.new.method(:key?))
aliases = Set.new(meth.aliases)
aliases.should == Set.new(["include?", "member?", "has_key?"]) aliases.should == Set.new(["include?", "member?", "has_key?"])
end
end end
end end
end end

View file

@ -5,15 +5,11 @@ describe Pry do
@str_output = StringIO.new @str_output = StringIO.new
end end
if RUBY_VERSION =~ /1.9/ describe "Exotic object support" do
describe "Exotic object support" do # regression test for exotic object support
# regression test for exotic object support it "Should not error when return value is a BasicObject instance" do
it "Should not error when return value is a BasicObject instance" do ReplTester.start do
input('BasicObject.new').should =~ /^=> #<BasicObject:/
ReplTester.start do
input('BasicObject.new').should =~ /^=> #<BasicObject:/
end
end end
end end
end end
@ -89,11 +85,9 @@ describe Pry do
}.should.raise(NameError) }.should.raise(NameError)
end end
if defined?(BasicObject) it 'should be able to operate inside the BasicObject class' do
it 'should be able to operate inside the BasicObject class' do pry_eval(BasicObject, ":foo", "Pad.obj = _")
pry_eval(BasicObject, ":foo", "Pad.obj = _") Pad.obj.should == :foo
Pad.obj.should == :foo
end
end end
it 'should set an ivar on an object' do it 'should set an ivar on an object' do
@ -325,9 +319,8 @@ describe Pry do
end end
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
# should include float in here, but test fails for some reason [:test, 0, true, false, nil,
# on 1.8.7, no idea why! (0.0 unless Pry::Helpers::BaseHelpers.jruby?)].each do |val|
[:test, 0, true, false, nil].each do |val|
pry_eval(val, "def hello; end"); pry_eval(val, "def hello; end");
val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
end end

View file

@ -15,11 +15,9 @@ describe "Pry.run_command" do
out.string.should =~ /hokey_pokey/ out.string.should =~ /hokey_pokey/
end end
if !PryTestHelpers.mri18_and_no_real_source_location? # This is a regression test as 0.9.11 broke this behaviour
# This is a regression test as 0.9.11 broke this behaviour it 'can perform a show-source' do
it 'can perform a show-source' do Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new
Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new out.string.should =~ /roken is dodelijk/
out.string.should =~ /roken is dodelijk/
end
end end
end end