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:
parent
ff41663403
commit
bc0da8e3ff
2 changed files with 45 additions and 5 deletions
|
@ -274,11 +274,11 @@ module IRB # :nodoc:
|
||||||
if home = ENV["HOME"]
|
if home = ENV["HOME"]
|
||||||
yield proc{|rc| home+"/.irb#{rc}"}
|
yield proc{|rc| home+"/.irb#{rc}"}
|
||||||
end
|
end
|
||||||
home = Dir.pwd
|
current_dir = Dir.pwd
|
||||||
yield proc{|rc| home+"/.irb#{rc}"}
|
yield proc{|rc| current_dir+"/.irb#{rc}"}
|
||||||
yield proc{|rc| home+"/irb#{rc.sub(/\A_?/, '.')}"}
|
yield proc{|rc| current_dir+"/irb#{rc.sub(/\A_?/, '.')}"}
|
||||||
yield proc{|rc| home+"/_irb#{rc}"}
|
yield proc{|rc| current_dir+"/_irb#{rc}"}
|
||||||
yield proc{|rc| home+"/$irb#{rc}"}
|
yield proc{|rc| current_dir+"/$irb#{rc}"}
|
||||||
end
|
end
|
||||||
|
|
||||||
# loading modules
|
# loading modules
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: false
|
||||||
require "test/unit"
|
require "test/unit"
|
||||||
require "irb"
|
require "irb"
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
module TestIRB
|
module TestIRB
|
||||||
class TestInit < Test::Unit::TestCase
|
class TestInit < Test::Unit::TestCase
|
||||||
|
@ -18,6 +19,45 @@ module TestIRB
|
||||||
assert_equal orig, $0
|
assert_equal orig, $0
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def with_argv(argv)
|
def with_argv(argv)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue