2011-04-29 15:55:35 +01:00
|
|
|
unless Object.const_defined? 'Pry'
|
|
|
|
$:.unshift File.expand_path '../../lib', __FILE__
|
|
|
|
require 'pry'
|
|
|
|
end
|
|
|
|
|
2011-09-12 19:44:59 -07:00
|
|
|
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}"
|
2011-09-12 01:06:47 -07:00
|
|
|
|
2011-04-29 15:55:35 +01:00
|
|
|
require 'bacon'
|
2011-06-05 23:41:59 +01:00
|
|
|
require 'open4'
|
2011-04-29 15:55:35 +01:00
|
|
|
|
2011-04-05 00:18:07 +12:00
|
|
|
# Ensure we do not execute any rc files
|
|
|
|
Pry::RC_FILES.clear
|
2011-05-29 01:38:00 +12:00
|
|
|
|
|
|
|
# in case the tests call reset_defaults, ensure we reset them to
|
|
|
|
# amended (test friendly) values
|
|
|
|
class << Pry
|
|
|
|
alias_method :orig_reset_defaults, :reset_defaults
|
|
|
|
def reset_defaults
|
|
|
|
orig_reset_defaults
|
|
|
|
|
|
|
|
Pry.color = false
|
|
|
|
Pry.pager = false
|
|
|
|
Pry.config.should_load_rc = false
|
2011-06-02 21:41:41 +12:00
|
|
|
Pry.config.plugins.enabled = false
|
2011-06-09 12:26:57 +02:00
|
|
|
Pry.config.history.should_load = false
|
|
|
|
Pry.config.history.should_save = false
|
2011-05-29 01:38:00 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-14 05:40:30 +12:00
|
|
|
class MockPryException
|
|
|
|
attr_accessor :bt_index
|
|
|
|
attr_accessor :backtrace
|
|
|
|
|
|
|
|
def initialize(*backtrace)
|
|
|
|
@backtrace = backtrace
|
|
|
|
@bt_index = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
"mock exception"
|
|
|
|
end
|
|
|
|
|
|
|
|
def bt_source_location_for(index)
|
|
|
|
backtrace[index] =~ /(.*):(\d+)/
|
|
|
|
[$1, $2.to_i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-01 15:47:29 +12:00
|
|
|
# are we on Jruby platform?
|
|
|
|
def jruby?
|
|
|
|
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
|
|
|
|
end
|
|
|
|
|
|
|
|
# are we on rbx platform?
|
|
|
|
def rbx?
|
|
|
|
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
|
|
|
end
|
|
|
|
|
2011-05-29 01:38:00 +12:00
|
|
|
Pry.reset_defaults
|
2011-04-05 00:18:07 +12:00
|
|
|
|
2011-09-01 05:05:21 +12:00
|
|
|
# this is to test exception code (cat --ex)
|
|
|
|
def broken_method
|
|
|
|
this method is broken
|
|
|
|
end
|
|
|
|
|
2011-05-19 15:28:38 +12:00
|
|
|
# sample doc
|
|
|
|
def sample_method
|
|
|
|
:sample
|
|
|
|
end
|
|
|
|
|
2011-08-27 17:13:15 +03:00
|
|
|
# another sample doc
|
|
|
|
def another_sample_method
|
|
|
|
:another_sample
|
|
|
|
end
|
|
|
|
|
2011-09-09 02:49:11 +03:00
|
|
|
# Set I/O streams.
|
|
|
|
#
|
|
|
|
# Out defaults to an anonymous StringIO.
|
|
|
|
#
|
|
|
|
def redirect_pry_io(new_in, new_out = StringIO.new)
|
2011-05-19 15:28:38 +12:00
|
|
|
old_in = Pry.input
|
|
|
|
old_out = Pry.output
|
|
|
|
|
|
|
|
Pry.input = new_in
|
|
|
|
Pry.output = new_out
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
Pry.input = old_in
|
|
|
|
Pry.output = old_out
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-24 00:59:48 -07:00
|
|
|
def mock_pry(*args)
|
|
|
|
input = InputTester.new(*args)
|
|
|
|
output = StringIO.new
|
|
|
|
|
|
|
|
redirect_pry_io(input, output) do
|
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
|
|
|
|
output.string
|
|
|
|
end
|
|
|
|
|
2011-05-06 22:44:59 +12:00
|
|
|
def redirect_global_pry_input(new_io)
|
|
|
|
old_io = Pry.input
|
|
|
|
Pry.input = new_io
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
Pry.input = old_io
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_global_pry_output(new_io)
|
|
|
|
old_io = Pry.output
|
|
|
|
Pry.output = new_io
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
Pry.output = old_io
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-12 12:16:04 +11:00
|
|
|
class Module
|
|
|
|
public :remove_const
|
2011-05-25 02:57:18 +12:00
|
|
|
public :remove_method
|
2010-12-22 03:03:52 +13:00
|
|
|
end
|
|
|
|
|
2011-03-06 03:17:54 +13:00
|
|
|
|
2010-12-22 03:03:52 +13:00
|
|
|
class InputTester
|
2010-12-24 21:30:51 +13:00
|
|
|
def initialize(*actions)
|
2011-07-24 16:20:32 -07:00
|
|
|
if actions.last.is_a?(Hash) && actions.last.keys == [:history]
|
|
|
|
@hist = actions.pop[:history]
|
|
|
|
end
|
2010-12-24 21:30:51 +13:00
|
|
|
@orig_actions = actions.dup
|
|
|
|
@actions = actions
|
2010-12-22 03:03:52 +13:00
|
|
|
end
|
|
|
|
|
2011-01-10 00:51:45 +13:00
|
|
|
def readline(*)
|
2011-07-24 16:20:32 -07:00
|
|
|
@actions.shift.tap{ |line| @hist << line if @hist }
|
2010-12-22 03:03:52 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
def rewind
|
2011-01-08 01:18:09 +13:00
|
|
|
@actions = @orig_actions.dup
|
2010-12-22 03:03:52 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-19 21:50:45 +13:00
|
|
|
class Pry
|
|
|
|
|
|
|
|
# null output class - doesn't write anywwhere.
|
|
|
|
class NullOutput
|
|
|
|
def self.puts(*) end
|
2011-04-08 13:06:39 +12:00
|
|
|
def self.string(*) end
|
2011-01-19 21:50:45 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-14 05:40:30 +12:00
|
|
|
# Open a temp file and yield it to the block, closing it after
|
|
|
|
# @return [String] The path of the temp file
|
|
|
|
def temp_file
|
|
|
|
file = Tempfile.new("tmp")
|
|
|
|
yield file
|
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
end
|
|
|
|
|
2011-01-19 21:50:45 +13:00
|
|
|
|
2011-05-07 07:32:05 +02:00
|
|
|
CommandTester = Pry::CommandSet.new do
|
2011-01-18 03:38:09 +13:00
|
|
|
command "command1", "command 1 test" do
|
2011-01-21 22:17:12 +13:00
|
|
|
output.puts "command1"
|
2011-01-12 12:16:04 +11:00
|
|
|
end
|
|
|
|
|
2011-01-18 03:38:09 +13:00
|
|
|
command "command2", "command 2 test" do |arg|
|
2011-01-21 22:17:12 +13:00
|
|
|
output.puts arg
|
2010-12-22 03:03:52 +13:00
|
|
|
end
|
|
|
|
end
|