[前][次][番号順一覧][スレッド一覧]

ruby-changes:58847

From: aycabta <ko1@a...>
Date: Wed, 20 Nov 2019 08:21:18 +0900 (JST)
Subject: [ruby-changes:58847] bc0da8e3ff (master): Generate history file path correctly when $HOME/.irbrc doesn't exist

https://git.ruby-lang.org/ruby.git/commit/?id=bc0da8e3ff

From bc0da8e3ff409f09888ffe98e6e66b503ebc8083 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Tue, 19 Nov 2019 20:58:11 +0900
Subject: Generate history file path correctly when $HOME/.irbrc doesn't exist


diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index 5dd0c12..0035746 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -274,11 +274,11 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/init.rb#L274
     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
diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb
index 11e293a..94b32dd 100644
--- a/test/irb/test_init.rb
+++ b/test/irb/test_init.rb
@@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/test/irb/test_init.rb#L1
 # frozen_string_literal: false
 require "test/unit"
 require "irb"
+require "fileutils"
 
 module TestIRB
   class TestInit < Test::Unit::TestCase
@@ -18,6 +19,45 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_init.rb#L19
       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)
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]