1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test/ruby: suppress runtime warnings

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-02-19 07:58:09 +00:00
parent 41f4317f45
commit c7f815eed8
10 changed files with 36 additions and 29 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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