diff --git a/array.c b/array.c index 45ca8e4bcd..91859cbc23 100644 --- a/array.c +++ b/array.c @@ -2358,11 +2358,11 @@ rb_ary_join_m(int argc, VALUE *argv, VALUE ary) { 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); diff --git a/io.c b/io.c index 73108f7747..7aba8be12f 100644 --- a/io.c +++ b/io.c @@ -7525,6 +7525,16 @@ rb_f_printf(int argc, VALUE *argv) 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) 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); diff --git a/spec/ruby/core/array/join_spec.rb b/spec/ruby/core/array/join_spec.rb index 16f0dcee7a..403bae7183 100644 --- a/spec/ruby/core/array/join_spec.rb +++ b/spec/ruby/core/array/join_spec.rb @@ -38,11 +38,13 @@ describe "Array#join with $," do 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 diff --git a/spec/ruby/core/array/shared/join.rb b/spec/ruby/core/array/shared/join.rb index 0fd2e0ff9b..28b3d8c04c 100644 --- a/spec/ruby/core/array/shared/join.rb +++ b/spec/ruby/core/array/shared/join.rb @@ -19,8 +19,10 @@ describe :array_join_with_default_separator, shared: true do 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 diff --git a/spec/ruby/core/kernel/p_spec.rb b/spec/ruby/core/kernel/p_spec.rb index c95055cf35..1221465243 100644 --- a/spec/ruby/core/kernel/p_spec.rb +++ b/spec/ruby/core/kernel/p_spec.rb @@ -7,7 +7,9 @@ describe "Kernel#p" do 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 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" diff --git a/spec/ruby/library/English/English_spec.rb b/spec/ruby/library/English/English_spec.rb index 45ce7ab322..f6153ec7c9 100644 --- a/spec/ruby/library/English/English_spec.rb +++ b/spec/ruby/library/English/English_spec.rb @@ -41,18 +41,18 @@ describe "English" do 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 diff --git a/spec/ruby/optional/capi/globals_spec.rb b/spec/ruby/optional/capi/globals_spec.rb index 068b372230..0bded557ba 100644 --- a/spec/ruby/optional/capi/globals_spec.rb +++ b/spec/ruby/optional/capi/globals_spec.rb @@ -159,7 +159,7 @@ describe "CApiGlobalSpecs" do end after :each do - $, = @dollar_comma + suppress_warning {$, = @dollar_comma} end it "returns nil by default" do @@ -167,7 +167,7 @@ describe "CApiGlobalSpecs" do end it "returns the value of $\\" do - $, = "foo" + suppress_warning {$, = "foo"} @f.rb_output_fs.should == "foo" end end diff --git a/test/lib/with_different_ofs.rb b/test/lib/with_different_ofs.rb index b7ac646f8f..559ed6a1d1 100644 --- a/test/lib/with_different_ofs.rb +++ b/test/lib/with_different_ofs.rb @@ -3,10 +3,14 @@ module DifferentOFS 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 diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f646c41a69..7f407647ec 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2480,7 +2480,7 @@ class TestIO < Test::Unit::TestCase end def test_print_separators - $, = ':' + EnvUtil.suppress_warning {$, = ':'} $\ = "\n" pipe(proc do |w| w.print('a')