From c7f815eed897a8d78b19e041a569d2667a403f4a Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 19 Feb 2016 07:58:09 +0000 Subject: test/ruby: suppress runtime warnings git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_autoload.rb | 10 ++++++++-- test/ruby/test_const.rb | 2 +- test/ruby/test_file_exhaustive.rb | 2 +- test/ruby/test_iseq.rb | 4 +++- test/ruby/test_m17n.rb | 10 +++------- test/ruby/test_math.rb | 6 +++--- test/ruby/test_rational.rb | 3 ++- test/ruby/test_refinement.rb | 6 ++++-- test/ruby/test_syntax.rb | 20 ++++++++++---------- test/ruby/test_variable.rb | 2 +- 10 files changed, 36 insertions(+), 29 deletions(-) diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index b793fd2a7f..b2d8d660fe 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -189,7 +189,9 @@ p Foo::Bar end def ruby_impl_require - Kernel.module_eval do; alias :old_require :require; end + Kernel.module_eval do + alias old_require require + end called_with = [] Kernel.send :define_method, :require do |path| called_with << path @@ -197,7 +199,11 @@ p Foo::Bar end yield called_with ensure - Kernel.module_eval do; alias :require :old_require; undef :old_require; end + Kernel.module_eval do + undef require + alias require old_require + undef old_require + end end def test_require_implemented_in_ruby_is_called diff --git a/test/ruby/test_const.rb b/test/ruby/test_const.rb index 0b2c4497c6..ff83257c5a 100644 --- a/test/ruby/test_const.rb +++ b/test/ruby/test_const.rb @@ -37,7 +37,7 @@ class TestConst < Test::Unit::TestCase self.class.class_eval { include Const2 } - STDERR.print "intentionally redefines TEST3, TEST4\n" if $VERBOSE + # STDERR.print "intentionally redefines TEST3, TEST4\n" if $VERBOSE assert defined?(TEST1) assert_equal 1, TEST1 assert defined?(TEST2) diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index 53b867e56b..53b75c6594 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -107,7 +107,7 @@ class TestFileExhaustive < Test::Unit::TestCase end def symlinkfile - return @symlinkfile if @symlinkfile + return @symlinkfile if defined? @symlinkfile @symlinkfile = make_tmp_filename("symlinkfile") begin File.symlink(regular_file, @symlinkfile) diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 06931c8ae6..501043eab2 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -9,7 +9,9 @@ class TestISeq < Test::Unit::TestCase end def compile(src, line = nil, opt = nil) - RubyVM::InstructionSequence.new(src, __FILE__, __FILE__, line, opt) + EnvUtil.suppress_warning do + RubyVM::InstructionSequence.new(src, __FILE__, __FILE__, line, opt) + end end def lines src diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 3a45f1f028..8e7e4c6f91 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1673,13 +1673,9 @@ class TestM17N < Test::Unit::TestCase def test_inspect_with_default_internal bug11787 = '[ruby-dev:49415] [Bug #11787]' - orig_int = Encoding.default_internal - Encoding.default_internal = ::Encoding::EUC_JP - s = begin - [e("\xB4\xC1\xBB\xFA")].inspect - ensure - Encoding.default_internal = orig_int - end + s = EnvUtil.with_default_internal(::Encoding::EUC_JP) do + [e("\xB4\xC1\xBB\xFA")].inspect + end assert_equal(e("[\"\xB4\xC1\xBB\xFA\"]"), s, bug11787) end end diff --git a/test/ruby/test_math.rb b/test/ruby/test_math.rb index f2805a2d74..72ed987719 100644 --- a/test/ruby/test_math.rb +++ b/test/ruby/test_math.rb @@ -289,7 +289,7 @@ class TestMath < Test::Unit::TestCase check(Math.exp((0 + 1)._to_f), Math.exp(0)) check(Math.log((0 + 1)._to_f), Math.log(0)) - Fixnum.class_eval { alias to_f _to_f } + Fixnum.class_eval { undef to_f; alias to_f _to_f; undef _to_f } end def test_bignum_to_f @@ -307,7 +307,7 @@ class TestMath < Test::Unit::TestCase check(Math.cos((1 << 62 << 1)._to_f), Math.cos(1 << 62)) check(Math.log((1 << 62 << 1)._to_f), Math.log(1 << 62)) - Bignum.class_eval { alias to_f _to_f } + Bignum.class_eval { undef to_f; alias to_f _to_f; undef _to_f } end def test_rational_to_f @@ -326,6 +326,6 @@ class TestMath < Test::Unit::TestCase check(Math.exp((0r + 1)._to_f), Math.exp(0r)) check(Math.log((0r + 1)._to_f), Math.log(0r)) - Rational.class_eval { alias to_f _to_f } + Rational.class_eval { undef to_f; alias to_f _to_f; undef _to_f } end end diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 44e186f9cc..ae46965bcd 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -904,7 +904,8 @@ class Rational_Test < Test::Unit::TestCase def test_fixed_bug n = Float::MAX.to_i * 2 - assert_equal(1.0, Rational(n + 2, n + 1).to_f, '[ruby-dev:33852]') + x = EnvUtil.suppress_warning {Rational(n + 2, n + 1).to_f} + assert_equal(1.0, x, '[ruby-dev:33852]') end def test_power_of_1_and_minus_1 diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 99987da988..60d0c9a7d2 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -503,8 +503,10 @@ class TestRefinement < Test::Unit::TestCase end class C - def foo - "redefined" + EnvUtil.suppress_warning do + def foo + "redefined" + end end end end diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index e2c524b8b1..81a0f6e102 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -369,22 +369,22 @@ WARN def test_duplicated_arg assert_syntax_error("def foo(a, a) end", /duplicated argument name/) - assert_nothing_raised { def foo(_, _) end } + assert_valid_syntax("def foo(_, _) end") end def test_duplicated_rest assert_syntax_error("def foo(a, *a) end", /duplicated argument name/) - assert_nothing_raised { def foo(_, *_) end } + assert_valid_syntax("def foo(_, *_) end") end def test_duplicated_opt assert_syntax_error("def foo(a, a=1) end", /duplicated argument name/) - assert_nothing_raised { def foo(_, _=1) end } + assert_valid_syntax("def foo(_, _=1) end") end def test_duplicated_opt_rest assert_syntax_error("def foo(a=1, *a) end", /duplicated argument name/) - assert_nothing_raised { def foo(_=1, *_) end } + assert_valid_syntax("def foo(_=1, *_) end") end def test_duplicated_rest_opt @@ -397,12 +397,12 @@ WARN def test_duplicated_opt_post assert_syntax_error("def foo(a=1, a) end", /duplicated argument name/) - assert_nothing_raised { def foo(_=1, _) end } + assert_valid_syntax("def foo(_=1, _) end") end def test_duplicated_kw assert_syntax_error("def foo(a, a: 1) end", /duplicated argument name/) - assert_nothing_raised { def foo(_, _: 1) end } + assert_valid_syntax("def foo(_, _: 1) end") end def test_duplicated_rest_kw @@ -412,22 +412,22 @@ WARN def test_duplicated_opt_kw assert_syntax_error("def foo(a=1, a: 1) end", /duplicated argument name/) - assert_nothing_raised { def foo(_=1, _: 1) end } + assert_valid_syntax("def foo(_=1, _: 1) end") end def test_duplicated_kw_kwrest assert_syntax_error("def foo(a: 1, **a) end", /duplicated argument name/) - assert_nothing_raised { def foo(_: 1, **_) end } + assert_valid_syntax("def foo(_: 1, **_) end") end def test_duplicated_rest_kwrest assert_syntax_error("def foo(*a, **a) end", /duplicated argument name/) - assert_nothing_raised { def foo(*_, **_) end } + assert_valid_syntax("def foo(*_, **_) end") end def test_duplicated_opt_kwrest assert_syntax_error("def foo(a=1, **a) end", /duplicated argument name/) - assert_nothing_raised { def foo(_=1, **_) end } + assert_valid_syntax("def foo(_=1, **_) end") end def test_duplicated_when diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb index 3da836bfc2..c8e2617df6 100644 --- a/test/ruby/test_variable.rb +++ b/test/ruby/test_variable.rb @@ -141,7 +141,7 @@ class TestVariable < Test::Unit::TestCase v.instance_variable_set(:@foo, :bar) end - assert_nil v.instance_variable_get(:@foo) + assert_nil EnvUtil.suppress_warning {v.instance_variable_get(:@foo)} assert_not_send([v, :instance_variable_defined?, :@foo]) assert_raise_with_message(RuntimeError, msg) do -- cgit v1.2.3