From 9908177857a28633d6279c43a1ad4dfedcb98596 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 17 Dec 2020 20:06:18 +0900 Subject: 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. --- test/ruby/test_marshal.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'test/ruby/test_marshal.rb') diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index fd62ea774b..ef8b261321 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -8,7 +8,6 @@ class TestMarshal < Test::Unit::TestCase def setup @verbose = $VERBOSE - $VERBOSE = nil end def teardown @@ -157,20 +156,29 @@ class TestMarshal < Test::Unit::TestCase end def test_change_class_name + self.class.__send__(:remove_const, :C3) if self.class.const_defined?(:C3) eval("class C3; def _dump(s); 'foo'; end; end") m = Marshal.dump(C3.new) assert_raise(TypeError) { Marshal.load(m) } + self.class.__send__(:remove_const, :C3) eval("C3 = nil") assert_raise(TypeError) { Marshal.load(m) } + ensure + self.class.__send__(:remove_const, :C3) if self.class.const_defined?(:C3) end def test_change_struct + self.class.__send__(:remove_const, :C3) if self.class.const_defined?(:C3) eval("C3 = Struct.new(:foo, :bar)") m = Marshal.dump(C3.new("FOO", "BAR")) + self.class.__send__(:remove_const, :C3) eval("C3 = Struct.new(:foo)") assert_raise(TypeError) { Marshal.load(m) } + self.class.__send__(:remove_const, :C3) eval("C3 = Struct.new(:foo, :baz)") assert_raise(TypeError) { Marshal.load(m) } + ensure + self.class.__send__(:remove_const, :C3) if self.class.const_defined?(:C3) end class C4 @@ -542,7 +550,7 @@ class TestMarshal < Test::Unit::TestCase end class TestForRespondToFalse - def respond_to?(a) + def respond_to?(a, priv = false) false end end @@ -570,7 +578,7 @@ class TestMarshal < Test::Unit::TestCase end def test_continuation - require "continuation" + EnvUtil.suppress_warning {require "continuation"} c = Bug9523.new assert_raise_with_message(RuntimeError, /Marshal\.dump reentered at marshal_dump/) do Marshal.dump(c) -- cgit v1.2.3