[ruby/irb] Fix exit! command warning and method behavior
(https://github.com/ruby/irb/pull/868) * Fix exit! command warning and method behavior * Remove arg(0) from Kernel.exit and Kernel.exit! https://github.com/ruby/irb/commit/372bc59bf5
This commit is contained in:
parent
39788e5888
commit
06995eb45b
@ -989,7 +989,7 @@ module IRB
|
|||||||
conf[:AT_EXIT].each{|hook| hook.call}
|
conf[:AT_EXIT].each{|hook| hook.call}
|
||||||
|
|
||||||
context.io.save_history if save_history
|
context.io.save_history if save_history
|
||||||
Kernel.exit(0) if forced_exit
|
Kernel.exit if forced_exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ module IRB
|
|||||||
def execute(*)
|
def execute(*)
|
||||||
throw :IRB_EXIT, true
|
throw :IRB_EXIT, true
|
||||||
rescue UncaughtThrowError
|
rescue UncaughtThrowError
|
||||||
Kernel.exit(0)
|
Kernel.exit!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -90,11 +90,11 @@ EOF
|
|||||||
IRB.conf[:__MAIN__] = @main
|
IRB.conf[:__MAIN__] = @main
|
||||||
@main.singleton_class.class_eval do
|
@main.singleton_class.class_eval do
|
||||||
private
|
private
|
||||||
define_method(:exit) do |*a, &b|
|
|
||||||
# Do nothing, will be overridden
|
|
||||||
end
|
|
||||||
define_method(:binding, Kernel.instance_method(:binding))
|
define_method(:binding, Kernel.instance_method(:binding))
|
||||||
define_method(:local_variables, Kernel.instance_method(:local_variables))
|
define_method(:local_variables, Kernel.instance_method(:local_variables))
|
||||||
|
# Define empty method to avoid delegator warning, will be overridden.
|
||||||
|
define_method(:exit) {|*a, &b| }
|
||||||
|
define_method(:exit!) {|*a, &b| }
|
||||||
end
|
end
|
||||||
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location)
|
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location)
|
||||||
end
|
end
|
||||||
|
@ -47,5 +47,17 @@ module TestIRB
|
|||||||
|
|
||||||
assert_match(/irb\(main\):001> 123/, output)
|
assert_match(/irb\(main\):001> 123/, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_forced_exit_out_of_irb_session
|
||||||
|
write_ruby <<~'ruby'
|
||||||
|
at_exit { puts 'un' + 'reachable' }
|
||||||
|
binding.irb
|
||||||
|
exit! # this will call exit! method overrided by command
|
||||||
|
ruby
|
||||||
|
output = run_ruby_file do
|
||||||
|
type "exit"
|
||||||
|
end
|
||||||
|
assert_not_include(output, 'unreachable')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -58,9 +58,7 @@ module TestIRB
|
|||||||
"irb_info",
|
"irb_info",
|
||||||
main: main
|
main: main
|
||||||
)
|
)
|
||||||
# Because the main object is frozen, IRB would wrap a delegator around it
|
assert_empty(err)
|
||||||
# Which's exit! method can't be overridden and would raise a warning
|
|
||||||
assert_match(/delegator does not forward private method #exit\!/, err)
|
|
||||||
assert_match(/RUBY_PLATFORM/, out)
|
assert_match(/RUBY_PLATFORM/, out)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user