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

ruby-changes:55398

From: nobu <ko1@a...>
Date: Fri, 19 Apr 2019 06:57:02 +0900 (JST)
Subject: [ruby-changes:55398] nobu:r67606 (trunk): io.c: warn non-nil $,

nobu	2019-04-19 06:56:55 +0900 (Fri, 19 Apr 2019)

  New Revision: 67606

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

  Log:
    io.c: warn non-nil $,
    
    * array.c (rb_ary_join_m): warn use of non-nil $,.
    
    * io.c (rb_output_fs_setter): warn when set to non-nil value.

  Modified files:
    trunk/array.c
    trunk/io.c
    trunk/spec/ruby/core/array/join_spec.rb
    trunk/spec/ruby/core/array/shared/join.rb
    trunk/spec/ruby/core/kernel/p_spec.rb
    trunk/spec/ruby/library/English/English_spec.rb
    trunk/spec/ruby/optional/capi/globals_spec.rb
    trunk/test/lib/with_different_ofs.rb
    trunk/test/ruby/test_io.rb
Index: test/lib/with_different_ofs.rb
===================================================================
--- test/lib/with_different_ofs.rb	(revision 67605)
+++ test/lib/with_different_ofs.rb	(revision 67606)
@@ -3,10 +3,14 @@ module DifferentOFS https://github.com/ruby/ruby/blob/trunk/test/lib/with_different_ofs.rb#L3
   module WithDifferentOFS
     def setup
       super
+      verbose, $VERBOSE = $VERBOSE, nil
       @ofs, $, = $,, "-"
+      $VERBOSE = verbose
     end
     def teardown
+      verbose, $VERBOSE = $VERBOSE, nil
       $, = @ofs
+      $VERBOSE = verbose
       super
     end
   end
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 67605)
+++ test/ruby/test_io.rb	(revision 67606)
@@ -2480,7 +2480,7 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2480
   end
 
   def test_print_separators
-    $, = ':'
+    EnvUtil.suppress_warning {$, = ':'}
     $\ = "\n"
     pipe(proc do |w|
       w.print('a')
Index: array.c
===================================================================
--- array.c	(revision 67605)
+++ array.c	(revision 67606)
@@ -2358,11 +2358,11 @@ rb_ary_join_m(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/array.c#L2358
 {
     VALUE sep;
 
-    if (rb_check_arity(argc, 0, 1) == 0) {
-        sep = rb_output_fs;
-    }
-    else if (NIL_P(sep = argv[0])) {
+    if (rb_check_arity(argc, 0, 1) == 0 || NIL_P(sep = argv[0])) {
         sep = rb_output_fs;
+        if (!NIL_P(sep)) {
+            rb_warn("$, is set to non-nil value");
+        }
     }
 
     return rb_ary_join(ary, sep);
Index: io.c
===================================================================
--- io.c	(revision 67605)
+++ io.c	(revision 67606)
@@ -7525,6 +7525,16 @@ rb_f_printf(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/io.c#L7525
     return Qnil;
 }
 
+static void
+rb_output_fs_setter(VALUE val, ID id, VALUE *var)
+{
+    rb_str_setter(val, id, &val);
+    if (!NIL_P(val)) {
+        rb_warn("non-nil $, will be deprecated");
+    }
+    *var = val;
+}
+
 /*
  *  call-seq:
  *     ios.print               -> nil
@@ -13172,7 +13182,7 @@ Init_IO(void) https://github.com/ruby/ruby/blob/trunk/io.c#L13182
     rb_define_method(rb_cIO, "initialize", rb_io_initialize, -1);
 
     rb_output_fs = Qnil;
-    rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_str_setter);
+    rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_output_fs_setter);
 
     rb_default_rs = rb_fstring_lit("\n"); /* avoid modifying RS_default */
     rb_gc_register_mark_object(rb_default_rs);
Index: spec/ruby/library/English/English_spec.rb
===================================================================
--- spec/ruby/library/English/English_spec.rb	(revision 67605)
+++ spec/ruby/library/English/English_spec.rb	(revision 67606)
@@ -41,18 +41,18 @@ describe "English" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/English/English_spec.rb#L41
 
   it "aliases $OFS to $," do
     original = $,
-    $, = "|"
+    suppress_warning {$, = "|"}
     $OFS.should_not be_nil
     $OFS.should == $,
-    $, = original
+    suppress_warning {$, = original}
   end
 
   it "aliases $OUTPUT_FIELD_SEPARATOR to $," do
     original = $,
-    $, = "|"
+    suppress_warning {$, = "|"}
     $OUTPUT_FIELD_SEPARATOR.should_not be_nil
     $OUTPUT_FIELD_SEPARATOR.should == $,
-    $, = original
+    suppress_warning {$, = original}
   end
 
   it "aliases $RS to $/" do
Index: spec/ruby/optional/capi/globals_spec.rb
===================================================================
--- spec/ruby/optional/capi/globals_spec.rb	(revision 67605)
+++ spec/ruby/optional/capi/globals_spec.rb	(revision 67606)
@@ -159,7 +159,7 @@ describe "CApiGlobalSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/globals_spec.rb#L159
     end
 
     after :each do
-      $, = @dollar_comma
+      suppress_warning {$, = @dollar_comma}
     end
 
     it "returns nil by default" do
@@ -167,7 +167,7 @@ describe "CApiGlobalSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/globals_spec.rb#L167
     end
 
     it "returns the value of $\\" do
-      $, = "foo"
+      suppress_warning {$, = "foo"}
       @f.rb_output_fs.should == "foo"
     end
   end
Index: spec/ruby/core/array/shared/join.rb
===================================================================
--- spec/ruby/core/array/shared/join.rb	(revision 67605)
+++ spec/ruby/core/array/shared/join.rb	(revision 67606)
@@ -19,8 +19,10 @@ describe :array_join_with_default_separa https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/shared/join.rb#L19
   end
 
   it "returns a string formed by concatenating each String element separated by $," do
-    $, = " | "
-    ["1", "2", "3"].send(@method).should == "1 | 2 | 3"
+    suppress_warning {
+      $, = " | "
+      ["1", "2", "3"].send(@method).should == "1 | 2 | 3"
+    }
   end
 
   it "attempts coercion via #to_str first" do
Index: spec/ruby/core/array/join_spec.rb
===================================================================
--- spec/ruby/core/array/join_spec.rb	(revision 67605)
+++ spec/ruby/core/array/join_spec.rb	(revision 67606)
@@ -38,11 +38,13 @@ describe "Array#join with $," do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/join_spec.rb#L38
   end
 
   after :each do
-    $, = @before_separator
+    suppress_warning {$, = @before_separator}
   end
 
   it "separates elements with default separator when the passed separator is nil" do
-    $, = "_"
-    [1, 2, 3].join(nil).should == '1_2_3'
+    suppress_warning {
+      $, = "_"
+      [1, 2, 3].join(nil).should == '1_2_3'
+    }
   end
 end
Index: spec/ruby/core/kernel/p_spec.rb
===================================================================
--- spec/ruby/core/kernel/p_spec.rb	(revision 67605)
+++ spec/ruby/core/kernel/p_spec.rb	(revision 67606)
@@ -7,7 +7,9 @@ describe "Kernel#p" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/p_spec.rb#L7
   end
 
   after :each do
-    $/, $\, $, = @rs_f, @rs_b, @rs_c
+    suppress_warning {
+      $/, $\, $, = @rs_f, @rs_b, @rs_c
+    }
   end
 
   it "is a private method" do
@@ -50,7 +52,9 @@ describe "Kernel#p" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/p_spec.rb#L52
     o = mock("Inspector Gadget")
     o.should_receive(:inspect).any_number_of_times.and_return "Next time, Gadget, NEXT TIME!"
 
-    $, = " *helicopter sound*\n"
+    suppress_warning {
+      $, = " *helicopter sound*\n"
+    }
     lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
 
     $\ = " *helicopter sound*\n"

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

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