diff options
-rw-r--r-- | error.c | 4 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | ruby.c | 12 | ||||
-rw-r--r-- | spec/ruby/core/data/constants_spec.rb | 7 | ||||
-rw-r--r-- | spec/ruby/core/env/index_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/integer/constants_spec.rb | 32 | ||||
-rw-r--r-- | spec/ruby/core/kernel/match_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/kernel/proc_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/module/deprecate_constant_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/proc/new_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/language/predefined_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/library/net/http/HTTPServerException_spec.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_argf.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_enumerator.rb | 1 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 77 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 40 | ||||
-rw-r--r-- | test/ruby/test_object.rb | 9 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 7 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 7 | ||||
-rw-r--r-- | tool/lib/envutil.rb | 5 | ||||
-rw-r--r-- | version.h | 2 |
21 files changed, 120 insertions, 140 deletions
@@ -128,7 +128,9 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, 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 b431c47e9a..5053422cc8 100644 --- a/internal.h +++ b/internal.h @@ -1561,6 +1561,7 @@ typedef enum { 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); @@ -1066,6 +1066,7 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) 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) } } 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 1b4c0d2df3..000da8fd09 100644 --- a/spec/ruby/core/data/constants_spec.rb +++ b/spec/ruby/core/data/constants_spec.rb @@ -8,6 +8,13 @@ describe "Data" do 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 43875f5a50..2457b65cc6 100644 --- a/spec/ruby/core/env/index_spec.rb +++ b/spec/ruby/core/env/index_spec.rb @@ -1,12 +1,14 @@ 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 3b8b01e330..cdb7537392 100644 --- a/spec/ruby/core/integer/constants_spec.rb +++ b/spec/ruby/core/integer/constants_spec.rb @@ -1,25 +1,27 @@ 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 6dc1eb7de8..687cd68da4 100644 --- a/spec/ruby/core/kernel/match_spec.rb +++ b/spec/ruby/core/kernel/match_spec.rb @@ -14,7 +14,7 @@ describe "Kernel#=~" do 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 2a79548313..7854af44d0 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 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 7bcced981b..6a8086bc8f 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 @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 cc033467e5..8faf142614 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 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 cec6bc852c..cdf2c28dcb 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -1076,6 +1076,14 @@ TRUE TrueClass Synonym for true. =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 87841ab499..b8ac8cac76 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 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 277fa368f5..5c2356524f 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -991,7 +991,6 @@ class TestArgf < Test::Unit::TestCase 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 $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 @@ -1013,7 +1011,6 @@ class TestArgf < Test::Unit::TestCase $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 @@ -1024,7 +1021,6 @@ class TestArgf < Test::Unit::TestCase $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 75cf1aeec6..b619150571 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -72,7 +72,6 @@ class TestEnumerator < Test::Unit::TestCase _, err = capture_io do assert_equal([1, 2, 3], Enumerator.new(@obj, :foo, 1, 2, 3).to_a) end - assert_match 'Enumerator.new without a block is deprecated', err assert_equal([1, 2, 3], Enumerator.new { |y| i = 0; loop { y << (i += 1) } }.take(3)) assert_raise(ArgumentError) { Enumerator.new } diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index c66446d2e8..306f0bcce0 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -405,19 +405,6 @@ class TestIO < Test::Unit::TestCase } end - def test_codepoints - make_tempfile {|t| - bug2959 = '[ruby-core:28650]' - a = "" - File.open(t, 'rt') {|f| - assert_warn(/deprecated/) { - f.codepoints {|c| a << c} - } - } - assert_equal("foo\nbar\nbaz\n", a, bug2959) - } - end - def test_rubydev33072 t = make_tempfile path = t.path @@ -1822,70 +1809,6 @@ class TestIO < Test::Unit::TestCase end) end - def test_lines - verbose, $VERBOSE = $VERBOSE, nil - pipe(proc do |w| - w.puts "foo" - w.puts "bar" - w.puts "baz" - w.close - end, proc do |r| - e = nil - assert_warn(/deprecated/) { - e = r.lines - } - assert_equal("foo\n", e.next) - assert_equal("bar\n", e.next) - assert_equal("baz\n", e.next) - assert_raise(StopIteration) { e.next } - end) - ensure - $VERBOSE = verbose - end - - def test_bytes - verbose, $VERBOSE = $VERBOSE, nil - pipe(proc do |w| - w.binmode - w.puts "foo" - w.puts "bar" - w.puts "baz" - w.close - end, proc do |r| - e = nil - assert_warn(/deprecated/) { - e = r.bytes - } - (%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c| - assert_equal(c.ord, e.next) - end - assert_raise(StopIteration) { e.next } - end) - ensure - $VERBOSE = verbose - end - - def test_chars - verbose, $VERBOSE = $VERBOSE, nil - pipe(proc do |w| - w.puts "foo" - w.puts "bar" - w.puts "baz" - w.close - end, proc do |r| - e = nil - assert_warn(/deprecated/) { - e = r.chars - } - (%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c| - assert_equal(c, e.next) - end - assert_raise(StopIteration) { e.next } - end) - ensure - $VERBOSE = verbose - end - def test_readbyte pipe(proc do |w| w.binmode diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 2e7e5804d0..69f03ae772 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1579,23 +1579,31 @@ class TestModule < Test::Unit::TestCase c = Class.new c.const_set(:FOO, "foo") c.deprecate_constant(:FOO) - assert_warn(/deprecated/) {c::FOO} - assert_warn(/#{c}::FOO is deprecated/) {Class.new(c)::FOO} + assert_warn(/deprecated/) do + Warning[:deprecated] = true + c::FOO + end + assert_warn(/#{c}::FOO is deprecated/) do + Warning[:deprecated] = true + Class.new(c)::FOO + end bug12382 = '[ruby-core:75505] [Bug #12382]' - assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"} - Warning[:deprecated] = false - assert_warn('') {c::FOO} - end - - NIL = nil - FALSE = false - deprecate_constant(:NIL, :FALSE) - - def test_deprecate_nil_constant - w = EnvUtil.verbose_warning {2.times {FALSE}} - assert_equal(1, w.scan("::FALSE").size, w) - w = EnvUtil.verbose_warning {2.times {NIL}} - assert_equal(1, w.scan("::NIL").size, w) + assert_warn(/deprecated/, bug12382) do + Warning[:deprecated] = true + c.class_eval "FOO" + end + assert_warn('') do + Warning[:deprecated] = false + c::FOO + end + assert_warn('') do + Warning[:deprecated] = false + Class.new(c)::FOO + end + assert_warn('') do + Warning[:deprecated] = false + c.class_eval "FOO" + end end def test_constants_with_private_constant diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index add5b9fb15..442a7551a0 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -954,13 +954,4 @@ class TestObject < Test::Unit::TestCase end EOS end - - def test_matcher - assert_warning(/deprecated Object#=~ is called on Object/) do - assert_equal(Object.new =~ 42, nil) - end - assert_warning(/deprecated Object#=~ is called on Array/) do - assert_equal([] =~ 42, nil) - end - end end diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 093720b1fc..fba53cd982 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -80,6 +80,9 @@ class TestRubyOptions < Test::Unit::TestCase assert_in_out_err(%w(-W:experimental -e) + ['p Warning[:experimental]'], "", %w(true), []) assert_in_out_err(%w(-W:no-experimental -e) + ['p Warning[:experimental]'], "", %w(false), []) assert_in_out_err(%w(-W:qux), "", [], /unknown warning category: `qux'/) + assert_in_out_err(%w(-w -e) + ['p Warning[:deprecated]'], "", %w(true), []) + assert_in_out_err(%w(-W -e) + ['p Warning[:deprecated]'], "", %w(true), []) + assert_in_out_err(%w(-e) + ['p Warning[:deprecated]'], "", %w(false), []) ensure ENV['RUBYOPT'] = save_rubyopt end @@ -333,6 +336,10 @@ class TestRubyOptions < Test::Unit::TestCase assert_in_out_err(%w(), "p $VERBOSE", ["true"]) assert_in_out_err(%w(-W1), "p $VERBOSE", ["false"]) assert_in_out_err(%w(-W0), "p $VERBOSE", ["nil"]) + assert_in_out_err(%w(), "p Warning[:deprecated]", ["true"]) + assert_in_out_err(%w(-W0), "p Warning[:deprecated]", ["false"]) + assert_in_out_err(%w(-W1), "p Warning[:deprecated]", ["false"]) + assert_in_out_err(%w(-W2), "p Warning[:deprecated]", ["true"]) ENV['RUBYOPT'] = '-W:deprecated' assert_in_out_err(%w(), "p Warning[:deprecated]", ["true"]) ENV['RUBYOPT'] = '-W:no-deprecated' diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 09d099bb4a..746471553d 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1768,13 +1768,6 @@ CODE GC.start assert_equal([], "".split, bug) end; - - begin - fs = $; - assert_warn(/`\$;' is deprecated/) {$; = " "} - ensure - EnvUtil.suppress_warning {$; = fs} - end end def test_split_encoding diff --git a/tool/lib/envutil.rb b/tool/lib/envutil.rb index 2faf48385e..74575cd50c 100644 --- a/tool/lib/envutil.rb +++ b/tool/lib/envutil.rb @@ -47,12 +47,13 @@ module EnvUtil class << self attr_accessor :timeout_scale attr_reader :original_internal_encoding, :original_external_encoding, - :original_verbose + :original_verbose, :original_warning def capture_global_values @original_internal_encoding = Encoding.default_internal @original_external_encoding = Encoding.default_external @original_verbose = $VERBOSE + @original_warning = %i[deprecated experimental].to_h {|i| [i, Warning[i]]} end end @@ -192,11 +193,13 @@ module EnvUtil end stderr, $stderr = $stderr, stderr $VERBOSE = true + Warning[:deprecated] = true yield stderr return $stderr ensure stderr, $stderr = $stderr, stderr $VERBOSE = EnvUtil.original_verbose + EnvUtil.original_warning.each {|i, v| Warning[i] = v} end module_function :verbose_warning @@ -2,7 +2,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 129 +#define RUBY_PATCHLEVEL 130 #define RUBY_RELEASE_YEAR 2020 #define RUBY_RELEASE_MONTH 9 |