Skip to content

Commit 6298ec2

Browse files
committed
Warn non-nil $\ [Feature #14240]
1 parent 588a86e commit 6298ec2

File tree

8 files changed

+37
-26
lines changed

8 files changed

+37
-26
lines changed

io.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7570,11 +7570,11 @@ rb_f_printf(int argc, VALUE *argv, VALUE _)
75707570
}
75717571

75727572
static void
7573-
rb_output_fs_setter(VALUE val, ID id, VALUE *var)
7573+
deprecated_str_setter(VALUE val, ID id, VALUE *var)
75747574
{
75757575
rb_str_setter(val, id, &val);
75767576
if (!NIL_P(val)) {
7577-
rb_warn_deprecated("`$,'", NULL);
7577+
rb_warn_deprecated("`%s'", NULL, rb_id2name(id));
75787578
}
75797579
*var = val;
75807580
}
@@ -13282,15 +13282,15 @@ Init_IO(void)
1328213282
rb_define_method(rb_cIO, "initialize", rb_io_initialize, -1);
1328313283

1328413284
rb_output_fs = Qnil;
13285-
rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_output_fs_setter);
13285+
rb_define_hooked_variable("$,", &rb_output_fs, 0, deprecated_str_setter);
1328613286

1328713287
rb_default_rs = rb_fstring_lit("\n"); /* avoid modifying RS_default */
1328813288
rb_gc_register_mark_object(rb_default_rs);
1328913289
rb_rs = rb_default_rs;
1329013290
rb_output_rs = Qnil;
1329113291
rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter);
1329213292
rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
13293-
rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);
13293+
rb_define_hooked_variable("$\\", &rb_output_rs, 0, deprecated_str_setter);
1329413294

1329513295
rb_define_virtual_variable("$_", get_LAST_READ_LINE, set_LAST_READ_LINE);
1329613296

spec/ruby/core/io/print_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
describe IO, "#print" do
55
before :each do
66
@old_separator = $\
7-
$\ = '->'
7+
suppress_warning {$\ = '->'}
88
@name = tmp("io_print")
99
end
1010

1111
after :each do
12-
$\ = @old_separator
12+
suppress_warning {$\ = @old_separator}
1313
rm_r @name
1414
end
1515

spec/ruby/core/kernel/p_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@
5757
}
5858
-> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
5959

60-
$\ = " *helicopter sound*\n"
60+
suppress_warning {
61+
$\ = " *helicopter sound*\n"
62+
}
6163
-> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
6264

63-
$/ = " *helicopter sound*\n"
65+
suppress_warning {
66+
$/ = " *helicopter sound*\n"
67+
}
6468
-> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
6569
end
6670

spec/ruby/library/English/English_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@
6767

6868
it "aliases $ORS to $\\" do
6969
original = $\
70-
$\ = "\t"
70+
suppress_warning {$\ = "\t"}
7171
$ORS.should_not be_nil
7272
$ORS.should == $\
73-
$\ = original
73+
suppress_warning {$\ = original}
7474
end
7575

7676
it "aliases $OUTPUT_RECORD_SEPARATOR to $\\" do
7777
original = $\
78-
$\ = "\t"
78+
suppress_warning {$\ = "\t"}
7979
$OUTPUT_RECORD_SEPARATOR.should_not be_nil
8080
$OUTPUT_RECORD_SEPARATOR.should == $\
81-
$\ = original
81+
suppress_warning {$\ = original}
8282
end
8383

8484
it "aliases $INPUT_LINE_NUMBER to $." do

spec/ruby/library/stringio/print_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
end
4040

4141
it "honors the output record separator global" do
42-
old_rs, $\ = $\, 'x'
42+
old_rs = $\
43+
suppress_warning {$\ = 'x'}
4344

4445
begin
4546
@io.print(5, 6, 7, 8)
4647
@io.string.should == '5678xle'
4748
ensure
48-
$\ = old_rs
49+
suppress_warning {$\ = old_rs}
4950
end
5051
end
5152

@@ -58,13 +59,14 @@
5859
end
5960

6061
it "correctly updates the current position when honoring the output record separator global" do
61-
old_rs, $\ = $\, 'x'
62+
old_rs = $\
63+
suppress_warning {$\ = 'x'}
6264

6365
begin
6466
@io.print(5, 6, 7, 8)
6567
@io.pos.should eql(5)
6668
ensure
67-
$\ = old_rs
69+
suppress_warning {$\ = old_rs}
6870
end
6971
end
7072
end

spec/ruby/library/stringio/puts_spec.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030

3131
it "does not honor the global output record separator $\\" do
3232
begin
33-
old_rs, $\ = $\, "test"
33+
old_rs = $\
34+
suppress_warning {$\ = "test"}
3435
@io.puts([1, 2, 3, 4])
3536
@io.string.should == "1\n2\n3\n4\n"
3637
ensure
37-
$\ = old_rs
38+
suppress_warning {$\ = old_rs}
3839
end
3940
end
4041

@@ -68,11 +69,12 @@
6869

6970
it "does not honor the global output record separator $\\" do
7071
begin
71-
old_rs, $\ = $\, "test"
72+
old_rs = $\
73+
suppress_warning {$\ = "test"}
7274
@io.puts(1, 2, 3, 4)
7375
@io.string.should == "1\n2\n3\n4\n"
7476
ensure
75-
$\ = old_rs
77+
suppress_warning {$\ = old_rs}
7678
end
7779
end
7880

@@ -117,11 +119,12 @@
117119

118120
it "does not honor the global output record separator $\\" do
119121
begin
120-
old_rs, $\ = $\, "test"
122+
old_rs = $\
123+
suppress_warning {$\ = "test"}
121124
@io.puts
122125
@io.string.should == "\n"
123126
ensure
124-
$\ = old_rs
127+
suppress_warning {$\ = old_rs}
125128
end
126129
end
127130
end

spec/ruby/optional/capi/globals_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@
140140
end
141141

142142
after :each do
143-
$\ = @dollar_backslash
143+
suppress_warning {$\ = @dollar_backslash}
144144
end
145145

146146
it "returns nil by default" do
147147
@f.rb_output_rs.should be_nil
148148
end
149149

150150
it "returns the value of $\\" do
151-
$\ = "foo"
151+
suppress_warning {$\ = "foo"}
152152
@f.rb_output_rs.should == "foo"
153153
end
154154
end

test/ruby/test_io.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,8 +2568,10 @@ def test_print
25682568
end
25692569

25702570
def test_print_separators
2571-
EnvUtil.suppress_warning {$, = ':'}
2572-
$\ = "\n"
2571+
EnvUtil.suppress_warning {
2572+
$, = ':'
2573+
$\ = "\n"
2574+
}
25732575
pipe(proc do |w|
25742576
w.print('a')
25752577
EnvUtil.suppress_warning {w.print('a','b','c')}

0 commit comments

Comments
 (0)