2017-12-12 06:25:16 -05:00
|
|
|
# frozen_string_literal: false
|
|
|
|
require "test/unit"
|
|
|
|
require "irb"
|
2019-11-19 06:58:11 -05:00
|
|
|
require "fileutils"
|
2017-12-12 06:25:16 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-11-19 06:58:11 -05:00
|
|
|
def test_rc_file
|
2019-12-13 00:35:11 -05:00
|
|
|
backup_irbrc = ENV.delete("IRBRC") # This is for RVM...
|
2021-01-12 06:15:18 -05:00
|
|
|
backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME")
|
2019-12-13 00:35:11 -05:00
|
|
|
backup_home = ENV["HOME"]
|
2019-11-19 06:58:11 -05:00
|
|
|
Dir.mktmpdir("test_irb_init_#{$$}") do |tmpdir|
|
|
|
|
ENV["HOME"] = tmpdir
|
|
|
|
|
|
|
|
IRB.conf[:RC_NAME_GENERATOR] = nil
|
|
|
|
assert_equal(tmpdir+"/.irb#{IRB::IRBRC_EXT}", IRB.rc_file)
|
|
|
|
assert_equal(tmpdir+"/.irb_history", IRB.rc_file("_history"))
|
|
|
|
IRB.conf[:RC_NAME_GENERATOR] = nil
|
|
|
|
FileUtils.touch(tmpdir+"/.irb#{IRB::IRBRC_EXT}")
|
|
|
|
assert_equal(tmpdir+"/.irb#{IRB::IRBRC_EXT}", IRB.rc_file)
|
|
|
|
assert_equal(tmpdir+"/.irb_history", IRB.rc_file("_history"))
|
|
|
|
end
|
2019-12-13 00:35:11 -05:00
|
|
|
ensure
|
|
|
|
ENV["HOME"] = backup_home
|
2021-01-12 06:15:18 -05:00
|
|
|
ENV["XDG_CONFIG_HOME"] = backup_xdg_config_home
|
2019-12-13 00:35:11 -05:00
|
|
|
ENV["IRBRC"] = backup_irbrc
|
2019-11-19 06:58:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rc_file_in_subdir
|
2019-12-13 00:35:11 -05:00
|
|
|
backup_irbrc = ENV.delete("IRBRC") # This is for RVM...
|
2021-01-12 06:15:18 -05:00
|
|
|
backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME")
|
2019-12-13 00:35:11 -05:00
|
|
|
backup_home = ENV["HOME"]
|
2019-11-19 06:58:11 -05:00
|
|
|
Dir.mktmpdir("test_irb_init_#{$$}") do |tmpdir|
|
|
|
|
ENV["HOME"] = tmpdir
|
|
|
|
|
|
|
|
FileUtils.mkdir_p("#{tmpdir}/mydir")
|
|
|
|
Dir.chdir("#{tmpdir}/mydir") do
|
|
|
|
IRB.conf[:RC_NAME_GENERATOR] = nil
|
|
|
|
assert_equal(tmpdir+"/.irb#{IRB::IRBRC_EXT}", IRB.rc_file)
|
|
|
|
assert_equal(tmpdir+"/.irb_history", IRB.rc_file("_history"))
|
|
|
|
IRB.conf[:RC_NAME_GENERATOR] = nil
|
|
|
|
FileUtils.touch(tmpdir+"/.irb#{IRB::IRBRC_EXT}")
|
|
|
|
assert_equal(tmpdir+"/.irb#{IRB::IRBRC_EXT}", IRB.rc_file)
|
|
|
|
assert_equal(tmpdir+"/.irb_history", IRB.rc_file("_history"))
|
|
|
|
end
|
|
|
|
end
|
2019-12-13 00:35:11 -05:00
|
|
|
ensure
|
|
|
|
ENV["HOME"] = backup_home
|
2021-01-12 06:15:18 -05:00
|
|
|
ENV["XDG_CONFIG_HOME"] = backup_xdg_config_home
|
2019-12-13 00:35:11 -05:00
|
|
|
ENV["IRBRC"] = backup_irbrc
|
2019-11-19 06:58:11 -05:00
|
|
|
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
|