Skip to content

Commit 996af2c

Browse files
committed
Disable deprecation warning by the default [Feature #16345]
And `-w` option turns it on.
1 parent 83ff0f7 commit 996af2c

19 files changed

+98
-154
lines changed

error.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
142142
return exc;
143143
}
144144

145-
static unsigned int warning_disabled_categories;
145+
static unsigned int warning_disabled_categories = (
146+
1U << RB_WARN_CATEGORY_DEPRECATED |
147+
0);
146148

147149
static unsigned int
148150
rb_warning_category_mask(VALUE category)

internal/error.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef enum {
4444
RB_WARN_CATEGORY_NONE,
4545
RB_WARN_CATEGORY_DEPRECATED,
4646
RB_WARN_CATEGORY_EXPERIMENTAL,
47+
RB_WARN_CATEGORY_ALL_BITS = 0x6, /* no RB_WARN_CATEGORY_NONE bit */
4748
} rb_warning_category_t;
4849

4950
extern long rb_backtrace_length_limit;

ruby.c

+12
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
11091109
warning = 1;
11101110
ruby_verbose = Qtrue;
11111111
}
1112+
FEATURE_SET(opt->warn, RB_WARN_CATEGORY_ALL_BITS);
11121113
s++;
11131114
goto reswitch;
11141115

@@ -1155,6 +1156,17 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt)
11551156
}
11561157
}
11571158
warning = 1;
1159+
switch (v) {
1160+
case 0:
1161+
FEATURE_SET_TO(opt->warn, RB_WARN_CATEGORY_ALL_BITS, 0);
1162+
break;
1163+
case 1:
1164+
FEATURE_SET_TO(opt->warn, 1U << RB_WARN_CATEGORY_DEPRECATED, 0);
1165+
break;
1166+
default:
1167+
FEATURE_SET(opt->warn, RB_WARN_CATEGORY_ALL_BITS);
1168+
break;
1169+
}
11581170
}
11591171
goto reswitch;
11601172

spec/ruby/core/data/constants_spec.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
require_relative '../../spec_helper'
22

3-
describe "Data" do
4-
it "is a subclass of Object" do
5-
suppress_warning do
6-
Data.superclass.should == Object
3+
ruby_version_is ""..."3.0" do
4+
describe "Data" do
5+
it "is a subclass of Object" do
6+
suppress_warning do
7+
Data.superclass.should == Object
8+
end
79
end
8-
end
910

10-
it "is deprecated" do
11-
-> { Data }.should complain(/constant ::Data is deprecated/)
11+
it "is deprecated" do
12+
-> { Data }.should complain(/constant ::Data is deprecated/)
13+
end
1214
end
1315
end

spec/ruby/core/env/index_spec.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
require_relative '../../spec_helper'
22
require_relative 'shared/key'
33

4-
describe "ENV.index" do
5-
it_behaves_like :env_key, :index
4+
ruby_version_is ""..."3.0" do
5+
describe "ENV.index" do
6+
it_behaves_like :env_key, :index
67

7-
it "warns about deprecation" do
8-
-> do
9-
ENV.index("foo")
10-
end.should complain(/warning: ENV.index is deprecated; use ENV.key/)
8+
it "warns about deprecation" do
9+
-> do
10+
ENV.index("foo")
11+
end.should complain(/warning: ENV.index is deprecated; use ENV.key/)
12+
end
1113
end
1214
end
+17-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
require_relative '../../spec_helper'
22

3-
describe "Fixnum" do
4-
it "is unified into Integer" do
5-
suppress_warning do
6-
Fixnum.should equal(Integer)
3+
ruby_version_is ""..."3.0" do
4+
describe "Fixnum" do
5+
it "is unified into Integer" do
6+
suppress_warning do
7+
Fixnum.should equal(Integer)
8+
end
79
end
8-
end
910

10-
it "is deprecated" do
11-
-> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
11+
it "is deprecated" do
12+
-> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
13+
end
1214
end
13-
end
1415

15-
describe "Bignum" do
16-
it "is unified into Integer" do
17-
suppress_warning do
18-
Bignum.should equal(Integer)
16+
describe "Bignum" do
17+
it "is unified into Integer" do
18+
suppress_warning do
19+
Bignum.should equal(Integer)
20+
end
1921
end
20-
end
2122

22-
it "is deprecated" do
23-
-> { Bignum }.should complain(/constant ::Bignum is deprecated/)
23+
it "is deprecated" do
24+
-> { Bignum }.should complain(/constant ::Bignum is deprecated/)
25+
end
2426
end
2527
end

spec/ruby/core/kernel/match_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
end
1515
end
1616

17-
ruby_version_is "2.6" do
17+
ruby_version_is "2.6"..."3.0" do
1818
it "is deprecated" do
1919
-> do
2020
Object.new =~ /regexp/

spec/ruby/core/module/deprecate_constant_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
@module.private_constant :PRIVATE
1111
@module.deprecate_constant :PRIVATE
1212
@pattern = /deprecated/
13+
if Warning.respond_to?(:[])
14+
@deprecated = Warning[:deprecated]
15+
Warning[:deprecated] = true
16+
end
17+
end
18+
19+
after :each do
20+
if Warning.respond_to?(:[])
21+
Warning[:deprecated] = @deprecated
22+
end
1323
end
1424

1525
describe "when accessing the deprecated module" do

spec/ruby/language/predefined_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def foo
654654
-> { $, = Object.new }.should raise_error(TypeError)
655655
end
656656

657-
ruby_version_is "2.7" do
657+
ruby_version_is "2.7"..."3.0" do
658658
it "warns if assigned non-nil" do
659659
-> { $, = "_" }.should complain(/warning: `\$,' is deprecated/)
660660
end
@@ -693,7 +693,7 @@ def foo
693693
$; = nil
694694
end
695695

696-
ruby_version_is "2.7" do
696+
ruby_version_is "2.7"..."3.0" do
697697
it "warns if assigned non-nil" do
698698
-> { $; = "_" }.should complain(/warning: `\$;' is deprecated/)
699699
end

spec/ruby/library/net/http/HTTPServerException_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414
end
1515

16-
ruby_version_is "2.6" do
16+
ruby_version_is "2.6"..."3.0" do
1717
describe "Net::HTTPServerException" do
1818
it "is a subclass of Net::ProtoServerError and is warned as deprecated" do
1919
-> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/)

test/ruby/test_argf.rb

-4
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ def test_lines
10061006
ARGF.lines {|l| s << l }
10071007
p s
10081008
};
1009-
assert_match(/deprecated/, f.gets)
10101009
assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\"]\n", f.read)
10111010
end
10121011
end
@@ -1017,7 +1016,6 @@ def test_bytes
10171016
$stderr = $stdout
10181017
print Marshal.dump(ARGF.bytes.to_a)
10191018
};
1020-
assert_match(/deprecated/, f.gets)
10211019
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
10221020
end
10231021
end
@@ -1028,7 +1026,6 @@ def test_chars
10281026
$stderr = $stdout
10291027
print [Marshal.dump(ARGF.chars.to_a)].pack('m')
10301028
};
1031-
assert_match(/deprecated/, f.gets)
10321029
assert_equal(["1", "\n", "2", "\n", "3", "\n", "4", "\n", "5", "\n", "6", "\n"], Marshal.load(f.read.unpack('m').first))
10331030
end
10341031
end
@@ -1039,7 +1036,6 @@ def test_codepoints
10391036
$stderr = $stdout
10401037
print Marshal.dump(ARGF.codepoints.to_a)
10411038
};
1042-
assert_match(/deprecated/, f.gets)
10431039
assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
10441040
end
10451041
end

test/ruby/test_enumerator.rb

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def test_initialize
7272
_, err = capture_io do
7373
assert_equal([1, 2, 3], Enumerator.new(@obj, :foo, 1, 2, 3).to_a)
7474
end
75-
assert_match 'Enumerator.new without a block is deprecated', err
7675
assert_equal([1, 2, 3], Enumerator.new { |y| i = 0; loop { y << (i += 1) } }.take(3))
7776
assert_raise(ArgumentError) { Enumerator.new }
7877

test/ruby/test_io.rb

-77
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,6 @@ def test_each_codepoint_enumerator
418418
}
419419
end
420420

421-
def test_codepoints
422-
make_tempfile {|t|
423-
bug2959 = '[ruby-core:28650]'
424-
a = ""
425-
File.open(t, 'rt') {|f|
426-
assert_warn(/deprecated/) {
427-
f.codepoints {|c| a << c}
428-
}
429-
}
430-
assert_equal("foo\nbar\nbaz\n", a, bug2959)
431-
}
432-
end
433-
434421
def test_rubydev33072
435422
t = make_tempfile
436423
path = t.path
@@ -1835,70 +1822,6 @@ def test_each_char
18351822
end)
18361823
end
18371824

1838-
def test_lines
1839-
verbose, $VERBOSE = $VERBOSE, nil
1840-
pipe(proc do |w|
1841-
w.puts "foo"
1842-
w.puts "bar"
1843-
w.puts "baz"
1844-
w.close
1845-
end, proc do |r|
1846-
e = nil
1847-
assert_warn(/deprecated/) {
1848-
e = r.lines
1849-
}
1850-
assert_equal("foo\n", e.next)
1851-
assert_equal("bar\n", e.next)
1852-
assert_equal("baz\n", e.next)
1853-
assert_raise(StopIteration) { e.next }
1854-
end)
1855-
ensure
1856-
$VERBOSE = verbose
1857-
end
1858-
1859-
def test_bytes
1860-
verbose, $VERBOSE = $VERBOSE, nil
1861-
pipe(proc do |w|
1862-
w.binmode
1863-
w.puts "foo"
1864-
w.puts "bar"
1865-
w.puts "baz"
1866-
w.close
1867-
end, proc do |r|
1868-
e = nil
1869-
assert_warn(/deprecated/) {
1870-
e = r.bytes
1871-
}
1872-
(%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c|
1873-
assert_equal(c.ord, e.next)
1874-
end
1875-
assert_raise(StopIteration) { e.next }
1876-
end)
1877-
ensure
1878-
$VERBOSE = verbose
1879-
end
1880-
1881-
def test_chars
1882-
verbose, $VERBOSE = $VERBOSE, nil
1883-
pipe(proc do |w|
1884-
w.puts "foo"
1885-
w.puts "bar"
1886-
w.puts "baz"
1887-
w.close
1888-
end, proc do |r|
1889-
e = nil
1890-
assert_warn(/deprecated/) {
1891-
e = r.chars
1892-
}
1893-
(%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c|
1894-
assert_equal(c, e.next)
1895-
end
1896-
assert_raise(StopIteration) { e.next }
1897-
end)
1898-
ensure
1899-
$VERBOSE = verbose
1900-
end
1901-
19021825
def test_readbyte
19031826
pipe(proc do |w|
19041827
w.binmode

test/ruby/test_lambda.rb

-6
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ def test_call_block_from_lambda
7474
assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]}
7575
end
7676

77-
def test_warning_for_non_literal_blocks
78-
assert_warn(/lambda without a literal block/, '[ruby-core:93482] [Feature #15973]') do
79-
lambda(&:symbol)
80-
end
81-
end
82-
8377
def pass_along(&block)
8478
lambda(&block)
8579
end

test/ruby/test_module.rb

+24-16
Original file line numberDiff line numberDiff line change
@@ -1755,23 +1755,31 @@ def test_deprecate_constant
17551755
c = Class.new
17561756
c.const_set(:FOO, "foo")
17571757
c.deprecate_constant(:FOO)
1758-
assert_warn(/deprecated/) {c::FOO}
1759-
assert_warn(/#{c}::FOO is deprecated/) {Class.new(c)::FOO}
1758+
assert_warn(/deprecated/) do
1759+
Warning[:deprecated] = true
1760+
c::FOO
1761+
end
1762+
assert_warn(/#{c}::FOO is deprecated/) do
1763+
Warning[:deprecated] = true
1764+
Class.new(c)::FOO
1765+
end
17601766
bug12382 = '[ruby-core:75505] [Bug #12382]'
1761-
assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"}
1762-
Warning[:deprecated] = false
1763-
assert_warn('') {c::FOO}
1764-
end
1765-
1766-
NIL = nil
1767-
FALSE = false
1768-
deprecate_constant(:NIL, :FALSE)
1769-
1770-
def test_deprecate_nil_constant
1771-
w = EnvUtil.verbose_warning {2.times {FALSE}}
1772-
assert_equal(1, w.scan("::FALSE").size, w)
1773-
w = EnvUtil.verbose_warning {2.times {NIL}}
1774-
assert_equal(1, w.scan("::NIL").size, w)
1767+
assert_warn(/deprecated/, bug12382) do
1768+
Warning[:deprecated] = true
1769+
c.class_eval "FOO"
1770+
end
1771+
assert_warn('') do
1772+
Warning[:deprecated] = false
1773+
c::FOO
1774+
end
1775+
assert_warn('') do
1776+
Warning[:deprecated] = false
1777+
Class.new(c)::FOO
1778+
end
1779+
assert_warn('') do
1780+
Warning[:deprecated] = false
1781+
c.class_eval "FOO"
1782+
end
17751783
end
17761784

17771785
def test_constants_with_private_constant

test/ruby/test_object.rb

-9
Original file line numberDiff line numberDiff line change
@@ -990,13 +990,4 @@ def test_clone_object_should_not_be_old
990990
end
991991
EOS
992992
end
993-
994-
def test_matcher
995-
assert_warning(/deprecated Object#=~ is called on Object/) do
996-
assert_equal(Object.new =~ 42, nil)
997-
end
998-
assert_warning(/deprecated Object#=~ is called on Array/) do
999-
assert_equal([] =~ 42, nil)
1000-
end
1001-
end
1002993
end

0 commit comments

Comments
 (0)