Skip to content

Commit 05313c9

Browse files
committed
Use category: :deprecated in warnings that are related to deprecation
Also document that both :deprecated and :experimental are supported :category option values. The locations where warnings were marked as deprecation warnings was previously reviewed by shyouhei. Comment a couple locations where deprecation warnings should probably be used but are not currently used because deprecation warning enablement has not occurred at the time they are called (RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K). Add assert_deprecated_warn to test assertions. Use this to simplify some tests, and fix failing tests after marking some warnings with deprecated category.
1 parent 6ced55b commit 05313c9

File tree

14 files changed

+56
-39
lines changed

14 files changed

+56
-39
lines changed

array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2835,7 +2835,7 @@ rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
28352835
if (rb_check_arity(argc, 0, 1) == 0 || NIL_P(sep = argv[0])) {
28362836
sep = rb_output_fs;
28372837
if (!NIL_P(sep)) {
2838-
rb_warn("$, is set to non-nil value");
2838+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "$, is set to non-nil value");
28392839
}
28402840
}
28412841

io.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ rb_io_writev(VALUE io, int argc, const VALUE *argv)
19561956
if (io != rb_ractor_stderr() && RTEST(ruby_verbose)) {
19571957
VALUE klass = CLASS_OF(io);
19581958
char sep = FL_TEST(klass, FL_SINGLETON) ? (klass = io, '.') : '#';
1959-
rb_warning("%+"PRIsVALUE"%c""write is outdated interface"
1959+
rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, "%+"PRIsVALUE"%c""write is outdated interface"
19601960
" which accepts just one argument",
19611961
klass, sep);
19621962
}
@@ -7717,7 +7717,7 @@ rb_io_print(int argc, const VALUE *argv, VALUE out)
77177717
argv = &line;
77187718
}
77197719
if (argc > 1 && !NIL_P(rb_output_fs)) {
7720-
rb_warn("$, is set to non-nil value");
7720+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "$, is set to non-nil value");
77217721
}
77227722
for (i=0; i<argc; i++) {
77237723
if (!NIL_P(rb_output_fs) && i>0) {
@@ -10238,7 +10238,8 @@ rb_f_syscall(int argc, VALUE *argv, VALUE _)
1023810238
int i;
1023910239

1024010240
if (RTEST(ruby_verbose)) {
10241-
rb_warning("We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
10241+
rb_category_warning(RB_WARN_CATEGORY_DEPRECATED,
10242+
"We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
1024210243
}
1024310244

1024410245
if (argc == 0)

object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ static VALUE
15901590
rb_obj_match(VALUE obj1, VALUE obj2)
15911591
{
15921592
if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) {
1593-
rb_warn("deprecated Object#=~ is called on %"PRIsVALUE
1593+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "deprecated Object#=~ is called on %"PRIsVALUE
15941594
"; it always returns nil", rb_obj_class(obj1));
15951595
}
15961596
return Qnil;
@@ -2295,7 +2295,7 @@ VALUE
22952295
rb_mod_attr(int argc, VALUE *argv, VALUE klass)
22962296
{
22972297
if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) {
2298-
rb_warning("optional boolean argument is obsoleted");
2298+
rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, "optional boolean argument is obsoleted");
22992299
rb_attr(klass, id_for_attr(klass, argv[0]), 1, RTEST(argv[1]), TRUE);
23002300
return Qnil;
23012301
}

re.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,7 +3467,7 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
34673467
flags |= ARG_ENCODING_NONE;
34683468
}
34693469
else {
3470-
rb_warn("encoding option is ignored - %s", kcode);
3470+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "encoding option is ignored - %s", kcode);
34713471
}
34723472
}
34733473
str = StringValue(argv[0]);
@@ -3922,14 +3922,14 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
39223922
static VALUE
39233923
ignorecase_getter(ID _x, VALUE *_y)
39243924
{
3925-
rb_warn("variable $= is no longer effective");
3925+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "variable $= is no longer effective");
39263926
return Qfalse;
39273927
}
39283928

39293929
static void
39303930
ignorecase_setter(VALUE val, ID id, VALUE *_)
39313931
{
3932-
rb_warn("variable $= is no longer effective; ignored");
3932+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "variable $= is no longer effective; ignored");
39333933
}
39343934

39353935
static VALUE

ruby.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,10 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
17471747
}
17481748

17491749
if (opt->src.enc.name)
1750-
rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
1750+
/* cannot set deprecated category, as enabling deprecation warnings based on flags
1751+
* has not happened yet.
1752+
*/
1753+
rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
17511754

17521755
#if USE_MJIT
17531756
if (opt->features.set & FEATURE_BIT(jit)) {

string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8187,7 +8187,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
81878187
rb_raise(rb_eTypeError, "value of $; must be String or Regexp");
81888188
}
81898189
else {
8190-
rb_warn("$; is set to non-nil value");
8190+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "$; is set to non-nil value");
81918191
}
81928192
if (split_type != SPLIT_TYPE_AWK) {
81938193
switch (BUILTIN_TYPE(spat)) {
@@ -8413,7 +8413,7 @@ get_rs(void)
84138413
(!RB_TYPE_P(rs, T_STRING) ||
84148414
RSTRING_LEN(rs) != 1 ||
84158415
RSTRING_PTR(rs)[0] != '\n')) {
8416-
rb_warn("$/ is set to non-default value");
8416+
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "$/ is set to non-default value");
84178417
}
84188418
return rs;
84198419
}

test/ruby/test_array.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,40 +1112,40 @@ def test_values_at
11121112
def test_join
11131113
assert_deprecated_warning {$, = ""}
11141114
a = @cls[]
1115-
assert_equal("", assert_warn(/non-nil value/) {a.join})
1115+
assert_equal("", assert_deprecated_warn(/non-nil value/) {a.join})
11161116
assert_equal("", a.join(','))
1117-
assert_equal(Encoding::US_ASCII, assert_warn(/non-nil value/) {a.join}.encoding)
1117+
assert_equal(Encoding::US_ASCII, assert_deprecated_warn(/non-nil value/) {a.join}.encoding)
11181118

11191119
assert_deprecated_warning {$, = ""}
11201120
a = @cls[1, 2]
1121-
assert_equal("12", assert_warn(/non-nil value/) {a.join})
1122-
assert_equal("12", assert_warn(/non-nil value/) {a.join(nil)})
1121+
assert_equal("12", assert_deprecated_warn(/non-nil value/) {a.join})
1122+
assert_equal("12", assert_deprecated_warn(/non-nil value/) {a.join(nil)})
11231123
assert_equal("1,2", a.join(','))
11241124

11251125
assert_deprecated_warning {$, = ""}
11261126
a = @cls[1, 2, 3]
1127-
assert_equal("123", assert_warn(/non-nil value/) {a.join})
1128-
assert_equal("123", assert_warn(/non-nil value/) {a.join(nil)})
1127+
assert_equal("123", assert_deprecated_warn(/non-nil value/) {a.join})
1128+
assert_equal("123", assert_deprecated_warn(/non-nil value/) {a.join(nil)})
11291129
assert_equal("1,2,3", a.join(','))
11301130

11311131
assert_deprecated_warning {$, = ":"}
11321132
a = @cls[1, 2, 3]
1133-
assert_equal("1:2:3", assert_warn(/non-nil value/) {a.join})
1134-
assert_equal("1:2:3", assert_warn(/non-nil value/) {a.join(nil)})
1133+
assert_equal("1:2:3", assert_deprecated_warn(/non-nil value/) {a.join})
1134+
assert_equal("1:2:3", assert_deprecated_warn(/non-nil value/) {a.join(nil)})
11351135
assert_equal("1,2,3", a.join(','))
11361136

11371137
assert_deprecated_warning {$, = ""}
11381138

11391139
e = ''.force_encoding('EUC-JP')
11401140
u = ''.force_encoding('UTF-8')
1141-
assert_equal(Encoding::US_ASCII, assert_warn(/non-nil value/) {[[]].join}.encoding)
1142-
assert_equal(Encoding::US_ASCII, assert_warn(/non-nil value/) {[1, [u]].join}.encoding)
1143-
assert_equal(Encoding::UTF_8, assert_warn(/non-nil value/) {[u, [e]].join}.encoding)
1144-
assert_equal(Encoding::UTF_8, assert_warn(/non-nil value/) {[u, [1]].join}.encoding)
1145-
assert_equal(Encoding::UTF_8, assert_warn(/non-nil value/) {[Struct.new(:to_str).new(u)].join}.encoding)
1141+
assert_equal(Encoding::US_ASCII, assert_deprecated_warn(/non-nil value/) {[[]].join}.encoding)
1142+
assert_equal(Encoding::US_ASCII, assert_deprecated_warn(/non-nil value/) {[1, [u]].join}.encoding)
1143+
assert_equal(Encoding::UTF_8, assert_deprecated_warn(/non-nil value/) {[u, [e]].join}.encoding)
1144+
assert_equal(Encoding::UTF_8, assert_deprecated_warn(/non-nil value/) {[u, [1]].join}.encoding)
1145+
assert_equal(Encoding::UTF_8, assert_deprecated_warn(/non-nil value/) {[Struct.new(:to_str).new(u)].join}.encoding)
11461146
bug5379 = '[ruby-core:39776]'
1147-
assert_equal(Encoding::US_ASCII, assert_warn(/non-nil value/) {[[], u, nil].join}.encoding, bug5379)
1148-
assert_equal(Encoding::UTF_8, assert_warn(/non-nil value/) {[[], "\u3042", nil].join}.encoding, bug5379)
1147+
assert_equal(Encoding::US_ASCII, assert_deprecated_warn(/non-nil value/) {[[], u, nil].join}.encoding, bug5379)
1148+
assert_equal(Encoding::UTF_8, assert_deprecated_warn(/non-nil value/) {[[], "\u3042", nil].join}.encoding, bug5379)
11491149
ensure
11501150
$, = nil
11511151
end

test/ruby/test_io.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ def capture.write(str)
26212621
end
26222622

26232623
capture.clear
2624-
assert_warning(/[.#]write is outdated/) do
2624+
assert_deprecated_warning(/[.#]write is outdated/) do
26252625
stdout, $stdout = $stdout, capture
26262626
puts "hey"
26272627
ensure

test/ruby/test_module.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,10 @@ def initialize
906906
@foo = :foo
907907
@bar = :bar
908908
end
909-
assert_warning(/optional boolean argument/) do
909+
assert_deprecated_warning(/optional boolean argument/) do
910910
attr :foo, true
911911
end
912-
assert_warning(/optional boolean argument/) do
912+
assert_deprecated_warning(/optional boolean argument/) do
913913
attr :bar, false
914914
end
915915
end

test/ruby/test_regexp.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_ruby_dev_24887
4242

4343
def test_yoshidam_net_20041111_1
4444
s = "[\xC2\xA0-\xC3\xBE]"
45-
r = assert_warning(/ignored/) {Regexp.new(s, nil, "u")}
45+
r = assert_deprecated_warning(/ignored/) {Regexp.new(s, nil, "u")}
4646
assert_match(r, "\xC3\xBE")
4747
end
4848

@@ -665,9 +665,9 @@ def test_regsub_K
665665
end
666666

667667
def test_ignorecase
668-
v = assert_warning(/variable \$= is no longer effective/) { $= }
668+
v = assert_deprecated_warning(/variable \$= is no longer effective/) { $= }
669669
assert_equal(false, v)
670-
assert_warning(/variable \$= is no longer effective; ignored/) { $= = nil }
670+
assert_deprecated_warning(/variable \$= is no longer effective; ignored/) { $= = nil }
671671
end
672672

673673
def test_match_setter

0 commit comments

Comments
 (0)