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

fixed subtle bug related to history and exceptions being raised when StringIO objects were used for input, added more tests, added Pry#show_result method to clean up Pry#rep method

This commit is contained in:
John Mair 2011-04-16 16:47:48 +12:00
parent a29ba01df2
commit 3d85ed3243
3 changed files with 30 additions and 20 deletions

View file

@ -28,9 +28,11 @@ class Pry
end
command "hist", "Show and replay Readline history" do |*args|
hist_array = Readline::HISTORY.to_a
require 'slop'
if args.empty?
text = add_line_numbers(Readline::HISTORY.to_a.join("\n"), 0)
text = add_line_numbers(hist_array.join("\n"), 0)
stagger_output(text)
next
end
@ -47,7 +49,7 @@ class Pry
next if opts.h?
actions = Array(Readline::HISTORY.to_a[opts[:r]]).join("\n") + "\n"
actions = Array(hist_array[opts[:r]]).join("\n") + "\n"
Pry.active_instance.input = StringIO.new(actions)
end

View file

@ -143,7 +143,7 @@ class Pry
target = Pry.binding_for(target)
result = re(target)
show(result) if should_print?(result)
show_result(result) if should_print?(result)
end
# Perform a read-eval
@ -160,7 +160,6 @@ class Pry
Readline.completion_proc = Pry::InputCompleter.build_completion_proc target, instance_eval(&custom_completions)
end
# save the pry instance to active_instance
Pry.active_instance = self
target.eval("_pry_ = ::Pry.active_instance")
@ -190,18 +189,20 @@ class Pry
@suppress_output = false
eval_string = ""
val = ""
loop do
val = retrieve_line(eval_string, target)
process_line(val, eval_string, target)
break if valid_expression?(eval_string) && !null_input?(val)
break if valid_expression?(eval_string)
end
@suppress_output = true if eval_string =~ /;\Z/
@suppress_output = true if eval_string =~ /;\Z/ || null_input?(val)
eval_string
end
def show(result)
# FIXME should delete this method? it's exposing an implementation detail!
def show_result(result)
print.call output, result
end

View file

@ -55,6 +55,24 @@ describe Pry do
pry_tester.rep(Hello)
Hello.const_defined?(:Nested).should == true
end
it 'should suppress output if input ends in a ";" (single line)' do
o = Object.new
str_output = StringIO.new
pry_tester = Pry.new(:input => InputTester.new("x = 5;"), :output => str_output)
pry_tester.rep(o)
str_output.string.should == ""
end
it 'should suppress output if input ends in a ";" (multi-line)' do
o = Object.new
str_output = StringIO.new
pry_tester = Pry.new(:input => InputTester.new("def self.blah", ":test", "end;"), :output => str_output)
pry_tester.rep(o)
str_output.string.should == ""
end
end
describe "repl" do
@ -69,18 +87,6 @@ describe Pry do
o.instance_variable_get(:@x).should == 10
end
# # this is now deprecated
# it 'should execute start session and end session hooks' do
# next
# input = InputTester.new("exit")
# str_output = StringIO.new
# o = Object.new
# pry_tester = Pry.start(o, :input => input, :output => str_output)
# str_output.string.should =~ /Beginning.*#{o}/
# str_output.string.should =~ /Ending.*#{o}/
# end
end
describe "test loading rc files" do
@ -382,6 +388,7 @@ describe Pry do
str_output = StringIO.new
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => Command68).rep
str_output.string.should =~ /:kept_hello/
str_output.string.should =~ /=>/
Object.remove_const(:Command68)
end
@ -395,11 +402,11 @@ describe Pry do
str_output = StringIO.new
Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => Command68).rep
(str_output.string =~ /:kept_hello/).should == nil
str_output.string !~ /=>/
Object.remove_const(:Command68)
end
it 'should set the commands default, and the default should be overridable' do
class Command0 < Pry::CommandBase
command "hello" do