2017-12-12 06:25:16 -05:00
|
|
|
# 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
|
2018-08-18 00:09:48 -04:00
|
|
|
IRB.setup(eval("__FILE__"), argv: %w[-f])
|
2017-12-12 06:25:16 -05:00
|
|
|
assert_equal argv, ARGV
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-18 00:09:48 -04:00
|
|
|
def test_setup_with_minimum_argv_does_not_change_dollar0
|
2017-12-12 08:56:48 -05:00
|
|
|
orig = $0.dup
|
2018-08-18 00:09:48 -04:00
|
|
|
IRB.setup(eval("__FILE__"), argv: %w[-f])
|
2017-12-12 08:56:48 -05:00
|
|
|
assert_equal orig, $0
|
|
|
|
end
|
|
|
|
|
2017-12-12 06:25:16 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def with_argv(argv)
|
|
|
|
orig = ARGV.dup
|
|
|
|
ARGV.replace(argv)
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ARGV.replace(orig)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|