mirror of
https://github.com/ruby/ruby.git
synced 2026-10-29 17:06:21 +08:00
irb.rb: preserve ARGV on binding.irb This is not perfectly good solution (at least we don't want to have ARGV as default value of `argv` argument), but unfortunately IRB.setup and IRB.parse_opts are public methods and we can't make breaking change to those methods. We may deprecate using them and then make them private in the future, but the removal should not be in Ruby 2.5. So I kept their interface for now. [Bug #14162] [close GH-1770] * properties. irb/init.rb: make sure ARGV refers to toplevel one irb/test_init.rb: add test to ensure $0 is not changed. At first `ARGV.unshift('something')` was suggested for r61149, but it wasn't sufficient because it modifies $0. Not only to preserve ARGV, but also r61149 intends to preserve $0. This test prevents future breakage of the behavior. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
32 lines
632 B
Ruby
32 lines
632 B
Ruby
# frozen_string_literal: false
|
|
require "test/unit"
|
|
require "irb"
|
|
|
|
module TestIRB
|
|
class TestInit < Test::Unit::TestCase
|
|
def test_setup_with_argv_preserves_global_argv
|
|
argv = ["foo", "bar"]
|
|
with_argv(argv) do
|
|
IRB.setup(eval("__FILE__"), argv: [])
|
|
assert_equal argv, ARGV
|
|
end
|
|
end
|
|
|
|
def test_setup_with_empty_argv_does_not_change_dollar0
|
|
orig = $0.dup
|
|
IRB.setup(eval("__FILE__"), argv: [])
|
|
assert_equal orig, $0
|
|
end
|
|
|
|
private
|
|
|
|
def with_argv(argv)
|
|
orig = ARGV.dup
|
|
ARGV.replace(argv)
|
|
yield
|
|
ensure
|
|
ARGV.replace(orig)
|
|
end
|
|
end
|
|
end
|