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

ruby-changes:60942

From: aycabta <ko1@a...>
Date: Wed, 29 Apr 2020 19:14:34 +0900 (JST)
Subject: [ruby-changes:60942] 3864fbc6d8 (master): [ruby/irb] Check existence of rc files in irb_info command

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

From 3864fbc6d85b834be4567fa1d5bd0dccc4dfd808 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Tue, 28 Apr 2020 17:06:43 +0900
Subject: [ruby/irb] Check existence of rc files in irb_info command

https://github.com/ruby/irb/commit/cdbb9dfc9f

diff --git a/lib/irb/cmd/info.rb b/lib/irb/cmd/info.rb
index ddf57b0..53ec71d 100644
--- a/lib/irb/cmd/info.rb
+++ b/lib/irb/cmd/info.rb
@@ -9,12 +9,11 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/info.rb#L9
       def execute
         Class.new {
           def inspect
-            <<~EOM.chomp
-              Ruby version: #{RUBY_VERSION}
-              IRB version: #{IRB.version}
-              InputMethod: #{IRB.CurrentContext.io.inspect}
-              .irbrc path: #{IRB.rc_file}
-            EOM
+            str  = "Ruby version: #{RUBY_VERSION}\n"
+            str += "IRB version: #{IRB.version}\n"
+            str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
+            str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
+            str
           end
           alias_method :to_s, :inspect
         }.new
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index 47fc5db..8f337e0 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -220,9 +220,11 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/input-method.rb#L220
 
       # For debug message
       def inspect
-        inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
         readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
-        "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION} and #{inputrc_path}"
+        str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
+        inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
+        str += " and #{inputrc_path}" if File.exist?(inputrc_path)
+        str
       end
     end
   rescue LoadError
@@ -323,12 +325,14 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/input-method.rb#L325
     # For debug message
     def inspect
       config = Reline::Config.new
+      str = "ReidlineInputMethod with Reline #{Reline::VERSION}"
       if config.respond_to?(:inputrc_path)
         inputrc_path = config.inputrc_path
       else
         inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
       end
-      "ReidlineInputMethod with Reline #{Reline::VERSION} and #{inputrc_path}"
+      str += " and #{inputrc_path}" if File.exist?(inputrc_path)
+      str
     end
   end
 end
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index 1f38551..7a9e7d7 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -60,5 +60,55 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L60
       }x
       assert_match expected, irb.context.main.irb_info.to_s
     end
+
+    def test_irb_info_multiline_without_rc_files
+      inputrc_backup = ENV["INPUTRC"]
+      ENV["INPUTRC"] = "unkown_inpurc"
+      ext_backup = IRB::IRBRC_EXT
+      IRB.__send__(:remove_const, :IRBRC_EXT)
+      IRB.const_set(:IRBRC_EXT, "unkown_ext")
+      IRB.setup(__FILE__, argv: [])
+      IRB.conf[:USE_MULTILINE] = true
+      IRB.conf[:USE_SINGLELINE] = false
+      workspace = IRB::WorkSpace.new(self)
+      irb = IRB::Irb.new(workspace)
+      IRB.conf[:MAIN_CONTEXT] = irb.context
+      expected = %r{
+        Ruby\sversion: .+\n
+        IRB\sversion:\sirb .+\n
+        InputMethod:\sReidlineInputMethod\swith\sReline\s[^ ]+(?!\sand\s.+)\n
+        \z
+      }x
+      assert_match expected, irb.context.main.irb_info.to_s
+    ensure
+      ENV["INPUTRC"] = inputrc_backup
+      IRB.__send__(:remove_const, :IRBRC_EXT)
+      IRB.const_set(:IRBRC_EXT, ext_backup)
+    end
+
+    def test_irb_info_singleline_without_rc_files
+      inputrc_backup = ENV["INPUTRC"]
+      ENV["INPUTRC"] = "unkown_inpurc"
+      ext_backup = IRB::IRBRC_EXT
+      IRB.__send__(:remove_const, :IRBRC_EXT)
+      IRB.const_set(:IRBRC_EXT, "unkown_ext")
+      IRB.setup(__FILE__, argv: [])
+      IRB.conf[:USE_MULTILINE] = false
+      IRB.conf[:USE_SINGLELINE] = true
+      workspace = IRB::WorkSpace.new(self)
+      irb = IRB::Irb.new(workspace)
+      IRB.conf[:MAIN_CONTEXT] = irb.context
+      expected = %r{
+        Ruby\sversion: .+\n
+        IRB\sversion:\sirb .+\n
+        InputMethod:\sReadlineInputMethod\swith\s[^ ]+\s[^ ]+(?!\sand\s.+)\n
+        \z
+      }x
+      assert_match expected, irb.context.main.irb_info.to_s
+    ensure
+      ENV["INPUTRC"] = inputrc_backup
+      IRB.__send__(:remove_const, :IRBRC_EXT)
+      IRB.const_set(:IRBRC_EXT, ext_backup)
+    end
   end
 end
-- 
cgit v0.10.2


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

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