mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Disable deprecation warning by the default [Feature #16345]
And `-w` option turns it on.
This commit is contained in:
parent
83ff0f74bf
commit
996af2ce08
Notes:
git
2020-09-25 09:50:59 +09:00
19 changed files with 100 additions and 156 deletions
error.c
internal
ruby.cspec/ruby
core
data
env
integer
kernel
module
language
library/net/http
test/ruby
test_argf.rbtest_enumerator.rbtest_io.rbtest_lambda.rbtest_module.rbtest_object.rbtest_rubyoptions.rbtest_string.rb
tool/lib
4
error.c
4
error.c
|
@ -142,7 +142,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)
|
||||
|
|
|
@ -44,6 +44,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;
|
||||
|
||||
extern long rb_backtrace_length_limit;
|
||||
|
|
12
ruby.c
12
ruby.c
|
@ -1109,6 +1109,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;
|
||||
|
||||
|
@ -1155,6 +1156,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;
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
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
|
||||
|
||||
it "is deprecated" do
|
||||
-> { Data }.should complain(/constant ::Data is deprecated/)
|
||||
end
|
||||
end
|
||||
|
||||
it "is deprecated" do
|
||||
-> { Data }.should complain(/constant ::Data is deprecated/)
|
||||
end
|
||||
end
|
||||
|
|
14
spec/ruby/core/env/index_spec.rb
vendored
14
spec/ruby/core/env/index_spec.rb
vendored
|
@ -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 ""..."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
|
||||
|
|
|
@ -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 ""..."3.0" do
|
||||
describe "Fixnum" do
|
||||
it "is unified into Integer" do
|
||||
suppress_warning do
|
||||
Fixnum.should equal(Integer)
|
||||
end
|
||||
end
|
||||
|
||||
it "is deprecated" do
|
||||
-> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
|
||||
end
|
||||
end
|
||||
|
||||
it "is deprecated" do
|
||||
-> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
|
||||
end
|
||||
end
|
||||
describe "Bignum" do
|
||||
it "is unified into Integer" do
|
||||
suppress_warning do
|
||||
Bignum.should equal(Integer)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Bignum" do
|
||||
it "is unified into Integer" do
|
||||
suppress_warning do
|
||||
Bignum.should equal(Integer)
|
||||
it "is deprecated" do
|
||||
-> { Bignum }.should complain(/constant ::Bignum is deprecated/)
|
||||
end
|
||||
end
|
||||
|
||||
it "is deprecated" do
|
||||
-> { Bignum }.should complain(/constant ::Bignum is deprecated/)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ describe "Kernel#=~" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
ruby_version_is "2.6"..."3.0" do
|
||||
it "is deprecated" do
|
||||
-> do
|
||||
Object.new =~ /regexp/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -654,7 +654,7 @@ describe "Predefined global $," do
|
|||
-> { $, = 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
|
|||
$; = 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
|
||||
|
|
|
@ -13,7 +13,7 @@ ruby_version_is ""..."2.6" do
|
|||
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/)
|
||||
|
|
|
@ -1006,7 +1006,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
|
||||
|
@ -1017,7 +1016,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
|
||||
|
@ -1028,7 +1026,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
|
||||
|
@ -1039,7 +1036,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
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -418,19 +418,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
|
||||
|
@ -1835,70 +1822,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
|
||||
|
|
|
@ -74,12 +74,6 @@ class TestLambdaParameters < Test::Unit::TestCase
|
|||
assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]}
|
||||
end
|
||||
|
||||
def test_warning_for_non_literal_blocks
|
||||
assert_warn(/lambda without a literal block/, '[ruby-core:93482] [Feature #15973]') do
|
||||
lambda(&:symbol)
|
||||
end
|
||||
end
|
||||
|
||||
def pass_along(&block)
|
||||
lambda(&block)
|
||||
end
|
||||
|
|
|
@ -1755,23 +1755,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
|
||||
|
|
|
@ -990,13 +990,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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -1764,13 +1764,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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -209,6 +210,7 @@ module EnvUtil
|
|||
ensure
|
||||
stderr, $stderr = $stderr, stderr
|
||||
$VERBOSE = EnvUtil.original_verbose
|
||||
EnvUtil.original_warning.each {|i, v| Warning[i] = v}
|
||||
end
|
||||
module_function :verbose_warning
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue