test/ruby: Check warning messages at a finer granularity

Instead of suppressing all warnings wholly in each test scripts by
setting `$VERBOSE` to `nil` in `setup` methods.
This commit is contained in:
Nobuyoshi Nakada 2020-12-17 20:06:18 +09:00 committed by GitHub
parent d597d7a8b6
commit 9908177857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2020-12-17 20:06:42 +09:00
Merged: https://github.com/ruby/ruby/pull/3925

Merged-By: nobu <nobu@ruby-lang.org>
17 changed files with 153 additions and 114 deletions

View file

@ -27,7 +27,6 @@ class TestModule < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
@deprecated = Warning[:deprecated]
Warning[:deprecated] = true
end
@ -487,6 +486,7 @@ class TestModule < Test::Unit::TestCase
end
a2 = a.dup.new
a.class_eval do
alias _b b
def b; 1 end
end
assert_equal(2, a2.b)
@ -900,14 +900,18 @@ class TestModule < Test::Unit::TestCase
end
def test_attr_obsoleted_flag
c = Class.new
c.class_eval do
c = Class.new do
extend Test::Unit::Assertions
def initialize
@foo = :foo
@bar = :bar
end
attr :foo, true
attr :bar, false
assert_warning(/optional boolean argument/) do
attr :foo, true
end
assert_warning(/optional boolean argument/) do
attr :bar, false
end
end
o = c.new
assert_equal(true, o.respond_to?(:foo))
@ -952,6 +956,7 @@ class TestModule < Test::Unit::TestCase
assert_equal(:foo, c2.const_get(:Foo))
assert_raise(NameError) { c2.const_get(:Foo, false) }
c1.__send__(:remove_const, :Foo)
eval("c1::Foo = :foo")
assert_raise(NameError) { c1::Bar }
assert_raise(NameError) { c2::Bar }