ruby-changes:63201
From: nagachika <ko1@a...>
Date: Tue, 29 Sep 2020 22:43:43 +0900 (JST)
Subject: [ruby-changes:63201] df3f52a633 (ruby_2_7): merge revision(s) 996af2ce086249e904b2ce95ab2fcd1de7d757be: [Backport #16345] [Backport #17000]
https://git.ruby-lang.org/ruby.git/commit/?id=df3f52a633 From df3f52a6331f1a47af9933b77311a8650727d8d1 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Tue, 29 Sep 2020 22:43:25 +0900 Subject: merge revision(s) 996af2ce086249e904b2ce95ab2fcd1de7d757be: [Backport #16345] [Backport #17000] Disable deprecation warning by the default [Feature #16345] And `-w` option turns it on. diff --git a/error.c b/error.c index 9557d85..c29e902 100644 --- a/error.c +++ b/error.c @@ -128,7 +128,9 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, https://github.com/ruby/ruby/blob/trunk/error.c#L128 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.h b/internal.h index b431c47..5053422 100644 --- a/internal.h +++ b/internal.h @@ -1561,6 +1561,7 @@ typedef enum { https://github.com/ruby/ruby/blob/trunk/internal.h#L1561 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; rb_warning_category_t rb_warning_category_from_name(VALUE category); bool rb_warning_category_enabled_p(rb_warning_category_t category); diff --git a/ruby.c b/ruby.c index 7903f58..96d8f75 100644 --- a/ruby.c +++ b/ruby.c @@ -1066,6 +1066,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1066 warning = 1; ruby_verbose = Qtrue; } + FEATURE_SET(opt->warn, RB_WARN_CATEGORY_ALL_BITS); s++; goto reswitch; @@ -1112,6 +1113,17 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1113 } } 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 1b4c0d2..000da8f 100644 --- a/spec/ruby/core/data/constants_spec.rb +++ b/spec/ruby/core/data/constants_spec.rb @@ -8,6 +8,13 @@ describe "Data" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/data/constants_spec.rb#L8 end ruby_version_is "2.5" do + before :each do + @deprecated = Warning[:deprecated] + Warning[:deprecated] = true + end + after :each do + Warning[:deprecated] = @deprecated + end it "is deprecated" do -> { Data }.should complain(/constant ::Data is deprecated/) end diff --git a/spec/ruby/core/env/index_spec.rb b/spec/ruby/core/env/index_spec.rb index 43875f5..2457b65 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 ""..."2.7" 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..cdb7537 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 ""..."2.7" 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..687cd68 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"..."2.7" do it "is deprecated" do -> do Object.new =~ /regexp/ diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index 2a79548..7854af4 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -49,6 +49,14 @@ describe "Kernel#proc" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/proc_spec.rb#L49 end ruby_version_is "2.7" do + before :each do + @deprecated = Warning[:deprecated] + Warning[:deprecated] = true + end + after :each do + Warning[:deprecated] = @deprecated + end + it "can be created when called with no block" do def some_method proc 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/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index cc03346..8faf142 100644 --- a/spec/ruby/core/proc/new_spec.rb +++ b/spec/ruby/core/proc/new_spec.rb @@ -204,6 +204,14 @@ describe "Proc.new without a block" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/proc/new_spec.rb#L204 end ruby_version_is "2.7" do + before :each do + @deprecated = Warning[:deprecated] + Warning[:deprecated] = true + end + after :each do + Warning[:deprecated] = @deprecated + end + it "can be created if invoked from within a method with a block" do -> { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) end diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index cec6bc8..cdf2c28 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -1076,6 +1076,14 @@ TRUE TrueClass Synonym for true. https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/predefined_spec.rb#L1076 =end describe "The predefined global constants" do + before :each do + @deprecated = Warning[:deprecated] + Warning[:deprecated] = true + end + after :each do + Warning[:deprecated] = @deprecated + end + it "includes TRUE" do Object.const_defined?(:TRUE).should == true -> { diff --git a/spec/ruby/library/net/http/HTTPServerException_spec.rb b/spec/ruby/library/net/http/HTTPServerException_spec.rb index 87841ab..b8ac8ca 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"..."2.7" 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 277fa36..5c23565 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -991,7 +991,6 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L991 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 @@ -1002,7 +1001,6 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L1001 $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], Mar (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/