зеркало из https://github.com/github/ruby.git
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
4751caecc3
Коммит
3ee0648dc7
8
array.c
8
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);
|
||||
|
|
12
io.c
12
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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
Загрузка…
Ссылка в новой задаче