ruby-changes:60169
From: Nobuyoshi <ko1@a...>
Date: Sun, 23 Feb 2020 16:48:59 +0900 (JST)
Subject: [ruby-changes:60169] 6298ec2875 (master): Warn non-nil `$\` [Feature #14240]
https://git.ruby-lang.org/ruby.git/commit/?id=6298ec2875 From 6298ec2875a6f1a1e75698c96ceac94362f20bcf Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 20 Jan 2020 17:53:46 +0900 Subject: Warn non-nil `$\` [Feature #14240] diff --git a/io.c b/io.c index b3175df..e388e38 100644 --- a/io.c +++ b/io.c @@ -7570,11 +7570,11 @@ rb_f_printf(int argc, VALUE *argv, VALUE _) https://github.com/ruby/ruby/blob/trunk/io.c#L7570 } static void -rb_output_fs_setter(VALUE val, ID id, VALUE *var) +deprecated_str_setter(VALUE val, ID id, VALUE *var) { rb_str_setter(val, id, &val); if (!NIL_P(val)) { - rb_warn_deprecated("`$,'", NULL); + rb_warn_deprecated("`%s'", NULL, rb_id2name(id)); } *var = val; } @@ -13282,7 +13282,7 @@ Init_IO(void) https://github.com/ruby/ruby/blob/trunk/io.c#L13282 rb_define_method(rb_cIO, "initialize", rb_io_initialize, -1); rb_output_fs = Qnil; - rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_output_fs_setter); + rb_define_hooked_variable("$,", &rb_output_fs, 0, deprecated_str_setter); rb_default_rs = rb_fstring_lit("\n"); /* avoid modifying RS_default */ rb_gc_register_mark_object(rb_default_rs); @@ -13290,7 +13290,7 @@ Init_IO(void) https://github.com/ruby/ruby/blob/trunk/io.c#L13290 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_output_rs, 0, rb_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/print_spec.rb b/spec/ruby/core/io/print_spec.rb index 2021cd5..0e88053 100644 --- a/spec/ruby/core/io/print_spec.rb +++ b/spec/ruby/core/io/print_spec.rb @@ -4,12 +4,12 @@ require_relative 'fixtures/classes' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/print_spec.rb#L4 describe IO, "#print" do before :each do @old_separator = $\ - $\ = '->' + suppress_warning {$\ = '->'} @name = tmp("io_print") end after :each do - $\ = @old_separator + suppress_warning {$\ = @old_separator} rm_r @name end diff --git a/spec/ruby/core/kernel/p_spec.rb b/spec/ruby/core/kernel/p_spec.rb index 798bd47..1bdd174 100644 --- a/spec/ruby/core/kernel/p_spec.rb +++ b/spec/ruby/core/kernel/p_spec.rb @@ -57,10 +57,14 @@ describe "Kernel#p" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/p_spec.rb#L57 } -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") - $\ = " *helicopter sound*\n" + suppress_warning { + $\ = " *helicopter sound*\n" + } -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") - $/ = " *helicopter sound*\n" + suppress_warning { + $/ = " *helicopter sound*\n" + } -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") end diff --git a/spec/ruby/library/English/English_spec.rb b/spec/ruby/library/English/English_spec.rb index f6153ec..480602d 100644 --- a/spec/ruby/library/English/English_spec.rb +++ b/spec/ruby/library/English/English_spec.rb @@ -67,18 +67,18 @@ describe "English" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/English/English_spec.rb#L67 it "aliases $ORS to $\\" do original = $\ - $\ = "\t" + suppress_warning {$\ = "\t"} $ORS.should_not be_nil $ORS.should == $\ - $\ = original + suppress_warning {$\ = original} end it "aliases $OUTPUT_RECORD_SEPARATOR to $\\" do original = $\ - $\ = "\t" + suppress_warning {$\ = "\t"} $OUTPUT_RECORD_SEPARATOR.should_not be_nil $OUTPUT_RECORD_SEPARATOR.should == $\ - $\ = original + suppress_warning {$\ = original} end it "aliases $INPUT_LINE_NUMBER to $." do diff --git a/spec/ruby/library/stringio/print_spec.rb b/spec/ruby/library/stringio/print_spec.rb index d0f07d1..6ac6430 100644 --- a/spec/ruby/library/stringio/print_spec.rb +++ b/spec/ruby/library/stringio/print_spec.rb @@ -39,13 +39,14 @@ describe "StringIO#print" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/print_spec.rb#L39 end it "honors the output record separator global" do - old_rs, $\ = $\, 'x' + old_rs = $\ + suppress_warning {$\ = 'x'} begin @io.print(5, 6, 7, 8) @io.string.should == '5678xle' ensure - $\ = old_rs + suppress_warning {$\ = old_rs} end end @@ -58,13 +59,14 @@ describe "StringIO#print" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/print_spec.rb#L59 end it "correctly updates the current position when honoring the output record separator global" do - old_rs, $\ = $\, 'x' + old_rs = $\ + suppress_warning {$\ = 'x'} begin @io.print(5, 6, 7, 8) @io.pos.should eql(5) ensure - $\ = old_rs + suppress_warning {$\ = old_rs} end end end diff --git a/spec/ruby/library/stringio/puts_spec.rb b/spec/ruby/library/stringio/puts_spec.rb index 2d3db25..a9f289a 100644 --- a/spec/ruby/library/stringio/puts_spec.rb +++ b/spec/ruby/library/stringio/puts_spec.rb @@ -30,11 +30,12 @@ describe "StringIO#puts when passed an Array" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/puts_spec.rb#L30 it "does not honor the global output record separator $\\" do begin - old_rs, $\ = $\, "test" + old_rs = $\ + suppress_warning {$\ = "test"} @io.puts([1, 2, 3, 4]) @io.string.should == "1\n2\n3\n4\n" ensure - $\ = old_rs + suppress_warning {$\ = old_rs} end end @@ -68,11 +69,12 @@ describe "StringIO#puts when passed 1 or more objects" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/puts_spec.rb#L69 it "does not honor the global output record separator $\\" do begin - old_rs, $\ = $\, "test" + old_rs = $\ + suppress_warning {$\ = "test"} @io.puts(1, 2, 3, 4) @io.string.should == "1\n2\n3\n4\n" ensure - $\ = old_rs + suppress_warning {$\ = old_rs} end end @@ -117,11 +119,12 @@ describe "StringIO#puts when passed no arguments" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/stringio/puts_spec.rb#L119 it "does not honor the global output record separator $\\" do begin - old_rs, $\ = $\, "test" + old_rs = $\ + suppress_warning {$\ = "test"} @io.puts @io.string.should == "\n" ensure - $\ = old_rs + suppress_warning {$\ = old_rs} end end end diff --git a/spec/ruby/optional/capi/globals_spec.rb b/spec/ruby/optional/capi/globals_spec.rb index 84694b1..ffc5790 100644 --- a/spec/ruby/optional/capi/globals_spec.rb +++ b/spec/ruby/optional/capi/globals_spec.rb @@ -140,7 +140,7 @@ describe "CApiGlobalSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/globals_spec.rb#L140 end after :each do - $\ = @dollar_backslash + suppress_warning {$\ = @dollar_backslash} end it "returns nil by default" do @@ -148,7 +148,7 @@ describe "CApiGlobalSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/globals_spec.rb#L148 end it "returns the value of $\\" do - $\ = "foo" + suppress_warning {$\ = "foo"} @f.rb_output_rs.should == "foo" end end diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index af2b08d..a6df5c8 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2568,8 +2568,10 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2568 end def test_print_separators - EnvUtil.suppress_warning {$, = ':'} - $\ = "\n" + EnvUtil.suppress_warning { + $, = ':' + $\ = "\n" + } pipe(proc do |w| w.print('a') EnvUtil.suppress_warning {w.print('a','b','c')} -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/