ruby-changes:63084
From: Nobuyoshi <ko1@a...>
Date: Fri, 25 Sep 2020 09:50:53 +0900 (JST)
Subject: [ruby-changes:63084] 996af2ce08 (master): Disable deprecation warning by the default [Feature #16345]
https://git.ruby-lang.org/ruby.git/commit/?id=996af2ce08 From 996af2ce086249e904b2ce95ab2fcd1de7d757be Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 31 Aug 2020 14:58:31 +0900 Subject: Disable deprecation warning by the default [Feature #16345] And `-w` option turns it on. diff --git a/error.c b/error.c index 6a9aa2f..9f8cdf8 100644 --- a/error.c +++ b/error.c @@ -142,7 +142,9 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, https://github.com/ruby/ruby/blob/trunk/error.c#L142 return exc; } -static unsigned int warning_disabled_categories; +static unsigned int warning_disabled_categories = ( + 1U << RB_WARN_CATEGORY_DEPRECATED | + 0); static unsigned int rb_warning_category_mask(VALUE category) diff --git a/internal/error.h b/internal/error.h index ff60d00..cf6495f 100644 --- a/internal/error.h +++ b/internal/error.h @@ -44,6 +44,7 @@ typedef enum { https://github.com/ruby/ruby/blob/trunk/internal/error.h#L44 RB_WARN_CATEGORY_NONE, RB_WARN_CATEGORY_DEPRECATED, RB_WARN_CATEGORY_EXPERIMENTAL, + RB_WARN_CATEGORY_ALL_BITS = 0x6, /* no RB_WARN_CATEGORY_NONE bit */ } rb_warning_category_t; extern long rb_backtrace_length_limit; diff --git a/ruby.c b/ruby.c index cfde2ff..9ca980d 100644 --- a/ruby.c +++ b/ruby.c @@ -1109,6 +1109,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1109 warning = 1; ruby_verbose = Qtrue; } + FEATURE_SET(opt->warn, RB_WARN_CATEGORY_ALL_BITS); s++; goto reswitch; @@ -1155,6 +1156,17 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1156 } } warning = 1; + switch (v) { + case 0: + FEATURE_SET_TO(opt->warn, RB_WARN_CATEGORY_ALL_BITS, 0); + break; + case 1: + FEATURE_SET_TO(opt->warn, 1U << RB_WARN_CATEGORY_DEPRECATED, 0); + break; + default: + FEATURE_SET(opt->warn, RB_WARN_CATEGORY_ALL_BITS); + break; + } } goto reswitch; diff --git a/spec/ruby/core/data/constants_spec.rb b/spec/ruby/core/data/constants_spec.rb index 0e47a82..18f6d42 100644 --- a/spec/ruby/core/data/constants_spec.rb +++ b/spec/ruby/core/data/constants_spec.rb @@ -1,13 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/data/constants_spec.rb#L1 require_relative '../../spec_helper' -describe "Data" do - it "is a subclass of Object" do - suppress_warning do - Data.superclass.should == Object +ruby_version_is ""..."3.0" do + describe "Data" do + it "is a subclass of Object" do + suppress_warning do + Data.superclass.should == Object + end end - end - it "is deprecated" do - -> { Data }.should complain(/constant ::Data is deprecated/) + it "is deprecated" do + -> { Data }.should complain(/constant ::Data is deprecated/) + end end end diff --git a/spec/ruby/core/env/index_spec.rb b/spec/ruby/core/env/index_spec.rb index 43875f5..a0c90f8 100644 --- a/spec/ruby/core/env/index_spec.rb +++ b/spec/ruby/core/env/index_spec.rb @@ -1,12 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/env/index_spec.rb#L1 require_relative '../../spec_helper' require_relative 'shared/key' -describe "ENV.index" do - it_behaves_like :env_key, :index +ruby_version_is ""..."3.0" do + describe "ENV.index" do + it_behaves_like :env_key, :index - it "warns about deprecation" do - -> do - ENV.index("foo") - end.should complain(/warning: ENV.index is deprecated; use ENV.key/) + it "warns about deprecation" do + -> do + ENV.index("foo") + end.should complain(/warning: ENV.index is deprecated; use ENV.key/) + end end end diff --git a/spec/ruby/core/integer/constants_spec.rb b/spec/ruby/core/integer/constants_spec.rb index 3b8b01e..35601f8 100644 --- a/spec/ruby/core/integer/constants_spec.rb +++ b/spec/ruby/core/integer/constants_spec.rb @@ -1,25 +1,27 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/integer/constants_spec.rb#L1 require_relative '../../spec_helper' -describe "Fixnum" do - it "is unified into Integer" do - suppress_warning do - Fixnum.should equal(Integer) +ruby_version_is ""..."3.0" do + describe "Fixnum" do + it "is unified into Integer" do + suppress_warning do + Fixnum.should equal(Integer) + end end - end - it "is deprecated" do - -> { Fixnum }.should complain(/constant ::Fixnum is deprecated/) + it "is deprecated" do + -> { Fixnum }.should complain(/constant ::Fixnum is deprecated/) + end end -end -describe "Bignum" do - it "is unified into Integer" do - suppress_warning do - Bignum.should equal(Integer) + describe "Bignum" do + it "is unified into Integer" do + suppress_warning do + Bignum.should equal(Integer) + end end - end - it "is deprecated" do - -> { Bignum }.should complain(/constant ::Bignum is deprecated/) + it "is deprecated" do + -> { Bignum }.should complain(/constant ::Bignum is deprecated/) + end end end diff --git a/spec/ruby/core/kernel/match_spec.rb b/spec/ruby/core/kernel/match_spec.rb index 6dc1eb7..e8ef320 100644 --- a/spec/ruby/core/kernel/match_spec.rb +++ b/spec/ruby/core/kernel/match_spec.rb @@ -14,7 +14,7 @@ describe "Kernel#=~" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/match_spec.rb#L14 end end - ruby_version_is "2.6" do + ruby_version_is "2.6"..."3.0" do it "is deprecated" do -> do Object.new =~ /regexp/ diff --git a/spec/ruby/core/module/deprecate_constant_spec.rb b/spec/ruby/core/module/deprecate_constant_spec.rb index 7bcced9..6a8086b 100644 --- a/spec/ruby/core/module/deprecate_constant_spec.rb +++ b/spec/ruby/core/module/deprecate_constant_spec.rb @@ -10,6 +10,16 @@ describe "Module#deprecate_constant" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/deprecate_constant_spec.rb#L10 @module.private_constant :PRIVATE @module.deprecate_constant :PRIVATE @pattern = /deprecated/ + if Warning.respond_to?(:[]) + @deprecated = Warning[:deprecated] + Warning[:deprecated] = true + end + end + + after :each do + if Warning.respond_to?(:[]) + Warning[:deprecated] = @deprecated + end end describe "when accessing the deprecated module" do diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index 5ce4e77..cb04627 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -654,7 +654,7 @@ describe "Predefined global $," do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/predefined_spec.rb#L654 -> { $, = Object.new }.should raise_error(TypeError) end - ruby_version_is "2.7" do + ruby_version_is "2.7"..."3.0" do it "warns if assigned non-nil" do -> { $, = "_" }.should complain(/warning: `\$,' is deprecated/) end @@ -693,7 +693,7 @@ describe "Predefined global $;" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/predefined_spec.rb#L693 $; = nil end - ruby_version_is "2.7" do + ruby_version_is "2.7"..."3.0" do it "warns if assigned non-nil" do -> { $; = "_" }.should complain(/warning: `\$;' is deprecated/) end diff --git a/spec/ruby/library/net/http/HTTPServerException_spec.rb b/spec/ruby/library/net/http/HTTPServerException_spec.rb index 87841ab..6800c62 100644 --- a/spec/ruby/library/net/http/HTTPServerException_spec.rb +++ b/spec/ruby/library/net/http/HTTPServerException_spec.rb @@ -13,7 +13,7 @@ ruby_version_is ""..."2.6" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/net/http/HTTPServerException_spec.rb#L13 end end -ruby_version_is "2.6" do +ruby_version_is "2.6"..."3.0" do describe "Net::HTTPServerException" do it "is a subclass of Net::ProtoServerError and is warned as deprecated" do -> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/) diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index 4734d5b..e558f76 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -1006,7 +1006,6 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L1006 ARGF.lines {|l| s << l } p s }; - assert_match(/deprecated/, f.gets) assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\"]\n", f.read) end end @@ -1017,7 +1016,6 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L1016 $stderr = $stdout print Marshal.dump(ARGF.bytes.to_a) }; - assert_match(/deprecated/, f.gets) assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read)) end end @@ -1028,7 +1026,6 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L1026 $stderr = $stdout print [Marshal.dump(ARGF.chars.to_a)].pack('m') }; - assert_match(/deprecated/, f.gets) assert_equal(["1", "\n", "2", "\n", "3", "\n", "4", "\n", "5", "\n", "6", "\n"], Marshal.load(f.read.unpack('m').first)) end end @@ -1039,7 +1036,6 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L1036 $stderr = $stdout print Marshal.dump(ARGF.codepoints.to_a) }; - assert_match(/deprecated/, f.gets) assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read)) end end diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 75cf1ae..b619150 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -72,7 +72,6 @@ class TestEnumerator < Test::Unit::TestCase https://github. (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/