summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-11-19 20:58:11 +0900
committeraycabta <aycabta@gmail.com>2019-11-20 08:19:58 +0900
commitbc0da8e3ff409f09888ffe98e6e66b503ebc8083 (patch)
treecdd65b9033ce8cfff0d3e608cfb8838e2de29afc /test
parentff41663403d3eb76d95f465cb94e14d2faaa04d1 (diff)
Generate history file path correctly when $HOME/.irbrc doesn't exist
Diffstat (limited to 'test')
-rw-r--r--test/irb/test_init.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb
index 11e293ad18..94b32ddb32 100644
--- a/test/irb/test_init.rb
+++ b/test/irb/test_init.rb
@@ -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)