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

Generate history file path correctly when $HOME/.irbrc doesn't exist

This commit is contained in:
aycabta 2019-11-19 20:58:11 +09:00
parent ff41663403
commit bc0da8e3ff
2 changed files with 45 additions and 5 deletions

View file

@ -274,11 +274,11 @@ module IRB # :nodoc:
if home = ENV["HOME"]
yield proc{|rc| home+"/.irb#{rc}"}
end
home = Dir.pwd
yield proc{|rc| home+"/.irb#{rc}"}
yield proc{|rc| home+"/irb#{rc.sub(/\A_?/, '.')}"}
yield proc{|rc| home+"/_irb#{rc}"}
yield proc{|rc| home+"/$irb#{rc}"}
current_dir = Dir.pwd
yield proc{|rc| current_dir+"/.irb#{rc}"}
yield proc{|rc| current_dir+"/irb#{rc.sub(/\A_?/, '.')}"}
yield proc{|rc| current_dir+"/_irb#{rc}"}
yield proc{|rc| current_dir+"/$irb#{rc}"}
end
# loading modules

View file

@ -1,6 +1,7 @@
# frozen_string_literal: false
require "test/unit"
require "irb"
require "fileutils"
module TestIRB
class TestInit < Test::Unit::TestCase
@ -18,6 +19,45 @@ module TestIRB
assert_equal orig, $0
end
def test_rc_file
ENV.delete("IRBRC") # This is for RVM...
Dir.mktmpdir("test_irb_init_#{$$}") do |tmpdir|
backup_home = ENV["HOME"]
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"))
ENV["HOME"] = backup_home
end
end
def test_rc_file_in_subdir
ENV.delete("IRBRC") # This is for RVM...
Dir.mktmpdir("test_irb_init_#{$$}") do |tmpdir|
backup_home = ENV["HOME"]
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
ENV["HOME"] = backup_home
end
end
private
def with_argv(argv)