ruby-changes:60168
From: Nobuyoshi <ko1@a...>
Date: Sun, 23 Feb 2020 16:48:58 +0900 (JST)
Subject: [ruby-changes:60168] 8a7e0aaaef (master): Warn non-nil `$/` [Feature #14240]
https://git.ruby-lang.org/ruby.git/commit/?id=8a7e0aaaef From 8a7e0aaaef3b19f90d6debe6781e4b3031f56237 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 21 Jan 2020 08:37:44 +0900 Subject: Warn non-nil `$/` [Feature #14240] diff --git a/io.c b/io.c index e388e38..03209f7 100644 --- a/io.c +++ b/io.c @@ -13288,8 +13288,8 @@ Init_IO(void) https://github.com/ruby/ruby/blob/trunk/io.c#L13288 rb_gc_register_mark_object(rb_default_rs); rb_rs = rb_default_rs; rb_output_rs = Qnil; - rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter); - rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter); + rb_define_hooked_variable("$/", &rb_rs, 0, deprecated_str_setter); + rb_define_hooked_variable("$-0", &rb_rs, 0, deprecated_str_setter); rb_define_hooked_variable("$\\", &rb_output_rs, 0, deprecated_str_setter); rb_define_virtual_variable("$_", get_LAST_READ_LINE, set_LAST_READ_LINE); diff --git a/spec/ruby/core/io/puts_spec.rb b/spec/ruby/core/io/puts_spec.rb index 3e4b877..be220c40 100644 --- a/spec/ruby/core/io/puts_spec.rb +++ b/spec/ruby/core/io/puts_spec.rb @@ -16,7 +16,7 @@ describe "IO#puts" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/puts_spec.rb#L16 ScratchPad.clear @io.close if @io rm_r @name - $/ = @before_separator + suppress_warning {$/ = @before_separator} end it "writes just a newline when given no args" do @@ -105,7 +105,7 @@ describe "IO#puts" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/puts_spec.rb#L105 end it "ignores the $/ separator global" do - $/ = ":" + suppress_warning {$/ = ":"} @io.puts(5).should == nil ScratchPad.recorded.should == "5\n" end diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb index 0d4f002..eb99eb8 100644 --- a/spec/ruby/core/io/readlines_spec.rb +++ b/spec/ruby/core/io/readlines_spec.rb @@ -22,11 +22,11 @@ describe "IO#readlines" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/readlines_spec.rb#L22 describe "when passed no arguments" do before :each do - @sep, $/ = $/, " " + suppress_warning {@sep, $/ = $/, " "} end after :each do - $/ = @sep + suppress_warning {$/ = @sep} end it "returns an Array containing lines based on $/" do @@ -184,7 +184,7 @@ describe "IO.readlines" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/readlines_spec.rb#L184 after :each do Encoding.default_external = @external Encoding.default_internal = @internal - $/ = @dollar_slash + suppress_warning {$/ = @dollar_slash} end it "encodes lines using the default external encoding" do @@ -196,7 +196,7 @@ describe "IO.readlines" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/readlines_spec.rb#L196 it "encodes lines using the default internal encoding, when set" do Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_16 - $/ = $/.encode Encoding::UTF_16 + suppress_warning {$/ = $/.encode Encoding::UTF_16} lines = IO.readlines(@name) lines.all? { |s| s.encoding == Encoding::UTF_16 }.should be_true end diff --git a/spec/ruby/core/io/shared/each.rb b/spec/ruby/core/io/shared/each.rb index 0b2dfa3..91766fb 100644 --- a/spec/ruby/core/io/shared/each.rb +++ b/spec/ruby/core/io/shared/each.rb @@ -168,12 +168,12 @@ describe :io_each_default_separator, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/shared/each.rb#L168 before :each do @io = IOSpecs.io_fixture "lines.txt" ScratchPad.record [] - @sep, $/ = $/, " " + suppress_warning {@sep, $/ = $/, " "} end after :each do @io.close if @io - $/ = @sep + suppress_warning {$/ = @sep} end it "uses $/ as the default line separator" do diff --git a/spec/ruby/core/io/shared/readlines.rb b/spec/ruby/core/io/shared/readlines.rb index de803f4..339684a 100644 --- a/spec/ruby/core/io/shared/readlines.rb +++ b/spec/ruby/core/io/shared/readlines.rb @@ -60,11 +60,11 @@ describe :io_readlines_options_19, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/shared/readlines.rb#L60 end after :each do - $/ = @sep + suppress_warning {$/ = @sep} end it "defaults to $/ as the separator" do - $/ = " " + suppress_warning {$/ = " "} result = IO.send(@method, @name, 10, &@object) (result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit end diff --git a/spec/ruby/core/kernel/fixtures/classes.rb b/spec/ruby/core/kernel/fixtures/classes.rb index 2f2bbf1..623b45c 100644 --- a/spec/ruby/core/kernel/fixtures/classes.rb +++ b/spec/ruby/core/kernel/fixtures/classes.rb @@ -49,7 +49,7 @@ module KernelSpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/fixtures/classes.rb#L49 def self.chomp(str, method, sep="\n") code = "$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_" - IO.popen([*ruby_exe, "-n", "-e", code], "r+") do |io| + IO.popen([*ruby_exe, "-W0", "-n", "-e", code], "r+") do |io| io.puts io.close_write io.read diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb index b067299..774f437 100644 --- a/spec/ruby/core/kernel/warn_spec.rb +++ b/spec/ruby/core/kernel/warn_spec.rb @@ -8,8 +8,9 @@ describe "Kernel#warn" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/warn_spec.rb#L8 end after :each do - $VERBOSE = @before_verbose + $VERBOSE = nil $/ = @before_separator + $VERBOSE = @before_verbose end it "is a private method" do diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb index 20a0925..a893bf7 100644 --- a/spec/ruby/core/string/chomp_spec.rb +++ b/spec/ruby/core/string/chomp_spec.rb @@ -6,11 +6,13 @@ describe "String#chomp" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/string/chomp_spec.rb#L6 describe "when passed no argument" do before do # Ensure that $/ is set to the default value + @verbose, $VERBOSE = $VERBOSE, nil @dollar_slash, $/ = $/, "\n" end after do $/ = @dollar_slash + $VERBOSE = @verbose end it "does not modify a String with no trailing carriage return or newline" do @@ -179,11 +181,13 @@ describe "String#chomp!" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/string/chomp_spec.rb#L181 describe "when passed no argument" do before do # Ensure that $/ is set to the default value + @verbose, $VERBOSE = $VERBOSE, nil @dollar_slash, $/ = $/, "\n" end after do $/ = @dollar_slash + $VERBOSE = @verbose end it "modifies self" do @@ -350,11 +354,13 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/string/chomp_spec.rb#L354 describe "String#chomp" do before :each do + @verbose, $VERBOSE = $VERBOSE, nil @before_separator = $/ end after :each do $/ = @before_separator + $VERBOSE = @verbose end it "does not modify a multi-byte character" do @@ -379,11 +385,13 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/string/chomp_spec.rb#L385 describe "String#chomp!" do before :each do + @verbose, $VERBOSE = $VERBOSE, nil @before_separator = $/ end after :each do $/ = @before_separator + $VERBOSE = @verbose end it "returns nil when the String is not modified" do diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb index 843b123..d8c4805 100644 --- a/spec/ruby/core/string/shared/each_line.rb +++ b/spec/ruby/core/string/shared/each_line.rb @@ -84,7 +84,7 @@ describe :string_each_line, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/string/shared/each_line.rb#L84 end after :each do - $/ = @before_separator + suppress_warning {$/ = @before_separator} end it "as the separator when none is given" do @@ -96,10 +96,10 @@ describe :string_each_line, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/string/shared/each_line.rb#L96 expected = [] str.send(@method, sep) { |x| expected << x } - $/ = sep + suppress_warning {$/ = sep} actual = [] - str.send(@method) { |x| actual << x } + suppress_warning {str.send(@method) { |x| actual << x }} actual.should == expected end diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index 6f902eb..e9fce1c 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -541,6 +541,7 @@ $stdout IO The current standard output. Assignment to $std https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/predefined_spec.rb#L541 describe "Predefined global $/" do before :each do + @verbose, $VERBOSE = $VERBOSE, nil @dollar_slash = $/ @dollar_dash_zero = $-0 end @@ -548,6 +549,7 @@ describe "Predefined global $/" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/predefined_spec.rb#L549 after :each do $/ = @dollar_slash $-0 = @dollar_dash_zero + $VERBOSE = @verbose end it "can be assigned a String" do @@ -589,6 +591,7 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/predefined_spec.rb#L591 describe "Predefined global $-0" do before :each do + @verbose, $VERBOSE = $VERBOSE, nil @dollar_slash = $/ @dollar_dash_zero = $-0 end @@ -596,6 +599,7 @@ describe "Predefined global $-0" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/predefined_spec.rb#L599 after :each do $/ = @dollar_slash $-0 = @dollar_dash_zero + $VERBOSE = @verbose end it "can be assigned a String" do diff --git a/spec/ruby/library/stringio/gets_sp (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/