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

ruby-changes:50067

From: nagachika <ko1@a...>
Date: Sun, 4 Feb 2018 09:39:30 +0900 (JST)
Subject: [ruby-changes:50067] nagachika:r62185 (ruby_2_4): merge revision(s) 61149, 61150, 61151, 61167: [Backport #14162]

nagachika	2018-02-04 09:39:24 +0900 (Sun, 04 Feb 2018)

  New Revision: 62185

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62185

  Log:
    merge revision(s) 61149,61150,61151,61167: [Backport #14162]
    
    irb.rb: preserve ARGV on binding.irb
    
    This is not perfectly good solution (at least we don't want to have ARGV
    as default value of `argv` argument), but unfortunately IRB.setup and
    IRB.parse_opts are public methods and we can't make breaking change to
    those methods.
    
    We may deprecate using them and then make them private in the future,
    but the removal should not be in Ruby 2.5. So I kept their interface for
    now.
    
    [Bug #14162] [close GH-1770]
    
    * properties.
    
    irb/init.rb: make sure ARGV refers to toplevel one
    
    irb/test_init.rb: add test to ensure $0
    
    is not changed.
    
    At first `ARGV.unshift('something')` was suggested for r61149,
    but it wasn't sufficient because it modifies $0.
    
    Not only to preserve ARGV, but also r61149 intends to preserve $0.
    This test prevents future breakage of the behavior.

  Added files:
    branches/ruby_2_4/test/irb/test_init.rb
  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/lib/irb/init.rb
    branches/ruby_2_4/lib/irb.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 62184)
+++ ruby_2_4/version.h	(revision 62185)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.4"
-#define RUBY_RELEASE_DATE "2018-02-03"
-#define RUBY_PATCHLEVEL 232
+#define RUBY_RELEASE_DATE "2018-02-04"
+#define RUBY_PATCHLEVEL 233
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 3
+#define RUBY_RELEASE_DAY 4
 
 #include "ruby/version.h"
 
Index: ruby_2_4/lib/irb/init.rb
===================================================================
--- ruby_2_4/lib/irb/init.rb	(revision 62184)
+++ ruby_2_4/lib/irb/init.rb	(revision 62185)
@@ -13,10 +13,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb/init.rb#L13
 module IRB # :nodoc:
 
   # initialize config
-  def IRB.setup(ap_path)
+  def IRB.setup(ap_path, argv: ::ARGV)
     IRB.init_config(ap_path)
     IRB.init_error
-    IRB.parse_opts
+    IRB.parse_opts(argv: argv)
     IRB.run_config
     IRB.load_modules
 
@@ -122,9 +122,9 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb/init.rb#L122
   end
 
   # option analyzing
-  def IRB.parse_opts
+  def IRB.parse_opts(argv: ::ARGV)
     load_path = []
-    while opt = ARGV.shift
+    while opt = argv.shift
       case opt
       when "-f"
         @CONF[:RC] = false
@@ -136,7 +136,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb/init.rb#L136
       when "-w"
         $VERBOSE = true
       when /^-W(.+)?/
-        opt = $1 || ARGV.shift
+        opt = $1 || argv.shift
         case opt
         when "0"
           $VERBOSE = nil
@@ -146,19 +146,19 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb/init.rb#L146
           $VERBOSE = true
         end
       when /^-r(.+)?/
-        opt = $1 || ARGV.shift
+        opt = $1 || argv.shift
         @CONF[:LOAD_MODULES].push opt if opt
       when /^-I(.+)?/
-        opt = $1 || ARGV.shift
+        opt = $1 || argv.shift
         load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
       when '-U'
         set_encoding("UTF-8", "UTF-8")
       when /^-E(.+)?/, /^--encoding(?:=(.+))?/
-        opt = $1 || ARGV.shift
+        opt = $1 || argv.shift
         set_encoding(*opt.split(':', 2))
       when "--inspect"
-        if /^-/ !~ ARGV.first
-          @CONF[:INSPECT_MODE] = ARGV.shift
+        if /^-/ !~ argv.first
+          @CONF[:INSPECT_MODE] = argv.shift
         else
           @CONF[:INSPECT_MODE] = true
         end
@@ -177,7 +177,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb/init.rb#L177
       when "--noverbose"
         @CONF[:VERBOSE] = false
       when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
-        opt = $1 || ARGV.shift
+        opt = $1 || argv.shift
         prompt_mode = opt.upcase.tr("-", "_").intern
         @CONF[:PROMPT_MODE] = prompt_mode
       when "--noprompt"
@@ -189,13 +189,13 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb/init.rb#L189
       when "--tracer"
         @CONF[:USE_TRACER] = true
       when /^--back-trace-limit(?:=(.+))?/
-        @CONF[:BACK_TRACE_LIMIT] = ($1 || ARGV.shift).to_i
+        @CONF[:BACK_TRACE_LIMIT] = ($1 || argv.shift).to_i
       when /^--context-mode(?:=(.+))?/
-        @CONF[:CONTEXT_MODE] = ($1 || ARGV.shift).to_i
+        @CONF[:CONTEXT_MODE] = ($1 || argv.shift).to_i
       when "--single-irb"
         @CONF[:SINGLE_IRB] = true
       when /^--irb_debug(?:=(.+))?/
-        @CONF[:DEBUG_LEVEL] = ($1 || ARGV.shift).to_i
+        @CONF[:DEBUG_LEVEL] = ($1 || argv.shift).to_i
       when "-v", "--version"
         print IRB.version, "\n"
         exit 0
@@ -204,7 +204,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb/init.rb#L204
         IRB.print_usage
         exit 0
       when "--"
-        if opt = ARGV.shift
+        if opt = argv.shift
           @CONF[:SCRIPT] = opt
           $0 = opt
         end
Index: ruby_2_4/lib/irb.rb
===================================================================
--- ruby_2_4/lib/irb.rb	(revision 62184)
+++ ruby_2_4/lib/irb.rb	(revision 62185)
@@ -709,7 +709,7 @@ end https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/irb.rb#L709
 class Binding
   # :nodoc:
   def irb
-    IRB.setup(eval("__FILE__"))
+    IRB.setup(eval("__FILE__"), argv: [])
     IRB::Irb.new(IRB::WorkSpace.new(self)).run(IRB.conf)
   end
 end
Index: ruby_2_4/test/irb/test_init.rb
===================================================================
--- ruby_2_4/test/irb/test_init.rb	(nonexistent)
+++ ruby_2_4/test/irb/test_init.rb	(revision 62185)
@@ -0,0 +1,31 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/irb/test_init.rb#L1
+# frozen_string_literal: false
+require "test/unit"
+require "irb"
+
+module TestIRB
+  class TestInit < Test::Unit::TestCase
+    def test_setup_with_argv_preserves_global_argv
+      argv = ["foo", "bar"]
+      with_argv(argv) do
+        IRB.setup(eval("__FILE__"), argv: [])
+        assert_equal argv, ARGV
+      end
+    end
+
+    def test_setup_with_empty_argv_does_not_change_dollar0
+      orig = $0.dup
+      IRB.setup(eval("__FILE__"), argv: [])
+      assert_equal orig, $0
+    end
+
+    private
+
+    def with_argv(argv)
+      orig = ARGV.dup
+      ARGV.replace(argv)
+      yield
+    ensure
+      ARGV.replace(orig)
+    end
+  end
+end

Property changes on: ruby_2_4/test/irb/test_init.rb
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 62184)
+++ ruby_2_4	(revision 62185)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r61149-61151,61167

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

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