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

test/ruby: suppress parser warnings

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-02-19 07:48:02 +00:00
parent 311b715483
commit 41f4317f45
31 changed files with 103 additions and 90 deletions

View file

@ -4,17 +4,17 @@ require "test/unit"
class TestCasingOptions < Test::Unit::TestCase
def assert_raise_functional_operations (arg, *options)
assert_raise(ArgumentError) { arg.upcase *options }
assert_raise(ArgumentError) { arg.downcase *options }
assert_raise(ArgumentError) { arg.capitalize *options }
assert_raise(ArgumentError) { arg.swapcase *options }
assert_raise(ArgumentError) { arg.upcase(*options) }
assert_raise(ArgumentError) { arg.downcase(*options) }
assert_raise(ArgumentError) { arg.capitalize(*options) }
assert_raise(ArgumentError) { arg.swapcase(*options) }
end
def assert_raise_bang_operations (arg, *options)
assert_raise(ArgumentError) { arg.upcase! *options }
assert_raise(ArgumentError) { arg.downcase! *options }
assert_raise(ArgumentError) { arg.capitalize! *options }
assert_raise(ArgumentError) { arg.swapcase! *options }
assert_raise(ArgumentError) { arg.upcase!(*options) }
assert_raise(ArgumentError) { arg.downcase!(*options) }
assert_raise(ArgumentError) { arg.capitalize!(*options) }
assert_raise(ArgumentError) { arg.swapcase!(*options) }
end
def assert_raise_both_types (*options)
@ -36,17 +36,17 @@ class TestCasingOptions < Test::Unit::TestCase
end
def assert_okay_functional_operations (arg, *options)
assert_nothing_raised { arg.upcase *options }
assert_nothing_raised { arg.downcase *options }
assert_nothing_raised { arg.capitalize *options }
assert_nothing_raised { arg.swapcase *options }
assert_nothing_raised { arg.upcase(*options) }
assert_nothing_raised { arg.downcase(*options) }
assert_nothing_raised { arg.capitalize(*options) }
assert_nothing_raised { arg.swapcase(*options) }
end
def assert_okay_bang_operations (arg, *options)
assert_nothing_raised { arg.upcase! *options }
assert_nothing_raised { arg.downcase! *options }
assert_nothing_raised { arg.capitalize! *options }
assert_nothing_raised { arg.swapcase! *options }
assert_nothing_raised { arg.upcase!(*options) }
assert_nothing_raised { arg.downcase!(*options) }
assert_nothing_raised { arg.capitalize!(*options) }
assert_nothing_raised { arg.swapcase!(*options) }
end
def assert_okay_both_types (*options)

View file

@ -22,8 +22,8 @@ class TestCaseFold < Test::Unit::TestCase
.collect.with_index { |linedata, linenumber| [linenumber.to_i+1, linedata.chomp] }
.reject { |number, data| data =~ /^(#|$)/ }
.collect do |linenumber, linedata|
data, name = linedata.split /#\s*/
code, kind, result, _ = data.split /;\s*/
data, _ = linedata.split(/#\s*/)
code, kind, result, _ = data.split(/;\s*/)
CaseTest.new code.to_i(16).chr('UTF-8'),
result.split(/ /).collect { |hex| hex.to_i(16) }.pack('U*'),
kind, linenumber
@ -81,6 +81,8 @@ class TestCaseFold < Test::Unit::TestCase
"12345#{to_codepoints(target)}67890 and /#{reg}/i do not match " +
"(CaseFolding.txt line #{test[:line]})"
rescue Encoding::UndefinedConversionError
source = source
regexp = regexp
end
end
end

View file

@ -2409,7 +2409,7 @@ class TestArray < Test::Unit::TestCase
def test_combination_clear
bug9939 = '[ruby-core:63149] [Bug #9939]'
assert_separately([], <<-'end;')
assert_ruby_status([], <<-'end;', bug9939)
100_000.times {Array.new(1000)}
a = [*0..100]
a.combination(3) {|*,x| a.clear}

View file

@ -198,7 +198,7 @@ class TestBacktrace < Test::Unit::TestCase
def test_caller_locations_base_label
assert_equal("#{__method__}", caller_locations(0, 1)[0].base_label)
loc, = tap {|loc| break caller_locations(0, 1)}
loc, = tap {break caller_locations(0, 1)}
assert_equal("#{__method__}", loc.base_label)
begin
raise
@ -209,7 +209,7 @@ class TestBacktrace < Test::Unit::TestCase
def test_caller_locations_label
assert_equal("#{__method__}", caller_locations(0, 1)[0].label)
loc, = tap {|loc| break caller_locations(0, 1)}
loc, = tap {break caller_locations(0, 1)}
assert_equal("block in #{__method__}", loc.label)
begin
raise

View file

@ -211,9 +211,9 @@ class TestBasicInstructions < Test::Unit::TestCase
assert_raise(NameError) { a }
assert_raise(NameError) { b }
assert_raise(NameError) { c }
a = "NOT OK"
b = "NOT OK"
c = "NOT OK"
a = a = "NOT OK"
b = b = "NOT OK"
c = c = "NOT OK"
end
class Const
@ -611,8 +611,8 @@ class TestBasicInstructions < Test::Unit::TestCase
x = OP.new
assert_equal 42, x.foo = 42, bug7773
assert_equal 42, x.foo, bug7773
assert_equal -6, x.send(:foo=, -6), bug7773
assert_equal -6, x.foo, bug7773
assert_equal (-6), x.send(:foo=, -6), bug7773
assert_equal (-6), x.foo, bug7773
assert_equal :Bug1996, x.send(:x=, :case_when_setter_returns_other_value), bug7773
assert_equal :case_when_setter_returns_other_value, x.x, bug7773
end

View file

@ -370,6 +370,9 @@ class TestClass < Test::Unit::TestCase
end
end;
}
assert_raise_with_message(TypeError, /#{n}/) {
Class.new(c)
}
assert_raise_with_message(TypeError, /#{n}/) {
m.module_eval "class #{n} < Class.new; end"
}

View file

@ -206,7 +206,7 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal([], @empty.first(10))
bug5801 = '[ruby-dev:45041]'
assert_in_out_err([], <<-'end;', [], /unexpected break/)
assert_in_out_err([], <<-'end;', [], /unexpected break/, bug5801)
empty = Object.new
class << empty
attr_reader :block
@ -703,7 +703,7 @@ class TestEnumerable < Test::Unit::TestCase
bug9605 = '[ruby-core:61340]'
lambda2 = ->(x, i) { x == 'c' }
assert_equal(['c',2], @obj.each_with_index.detect(&lambda2))
assert_equal(['c',2], @obj.each_with_index.detect(&lambda2), bug9605)
end
def test_select
@ -723,7 +723,7 @@ class TestEnumerable < Test::Unit::TestCase
bug9605 = '[ruby-core:61340]'
lambda2 = ->(x, i) { x == 'c' }
assert_equal([['c',2]], @obj.each_with_index.select(&lambda2))
assert_equal([['c',2]], @obj.each_with_index.select(&lambda2), bug9605)
end
def test_map

View file

@ -103,6 +103,7 @@ class TestEnumerator < Test::Unit::TestCase
1.times do
foo = [1,2,3].to_enum
GC.start
foo
end
GC.start
end

View file

@ -53,7 +53,7 @@ class TestEnv < Test::Unit::TestCase
end
assert_raise(TypeError) {
tmp = ENV[1]
ENV[1]
}
assert_raise(TypeError) {
ENV[1] = 'foo'
@ -318,7 +318,7 @@ class TestEnv < Test::Unit::TestCase
assert_equal("test", k)
assert_equal("foo", v)
end
assert_invalid_env {|v| ENV.assoc(v)}
assert_invalid_env {|var| ENV.assoc(var)}
end
def test_has_value2

View file

@ -258,9 +258,9 @@ class TestEval < Test::Unit::TestCase
#
def make_test_binding
local1 = "local1"
local1 = local1 = "local1"
lambda {
local2 = "local2"
local2 = local2 = "local2"
return binding
}.call
end
@ -287,7 +287,7 @@ class TestEval < Test::Unit::TestCase
assert_equal('assert(true)', eval("$foo"))
assert_equal(true, eval("true"))
i = 5
i = i = 5
assert(eval("i == 5"))
assert_equal(5, eval("i"))
assert(eval("defined? i"))
@ -308,6 +308,7 @@ class TestEval < Test::Unit::TestCase
module EvTest
EVTEST1 = 25
evtest2 = 125
evtest2 = evtest2
binding
end
)
@ -354,7 +355,7 @@ class TestEval < Test::Unit::TestCase
p = binding
eval "foo11 = 1", p
foo22 = 5
proc{foo11=22}.call
proc{foo11=22;foo11}.call
proc{foo22=55}.call
# assert_equal(eval("foo11"), eval("foo11", p))
# assert_equal(1, eval("foo11"))

View file

@ -20,8 +20,8 @@ class TestException < Test::Unit::TestCase
if bad
bad = false
retry
assert(false)
end
assert(!bad)
end
assert(true)
end
@ -626,6 +626,7 @@ end.join
end
def test_cause_raised_in_rescue
a = nil
e = assert_raise_with_message(RuntimeError, 'b') {
begin
raise 'a'
@ -633,6 +634,7 @@ end.join
begin
raise 'b'
rescue => b
assert_same(a, b.cause)
begin
raise 'c'
rescue
@ -641,15 +643,17 @@ end.join
end
end
}
assert_equal('a', e.cause.message, 'cause should not be overwritten by reraise')
assert_same(a, e.cause, 'cause should not be overwritten by reraise')
end
def test_cause_at_raised
a = nil
e = assert_raise_with_message(RuntimeError, 'b') {
begin
raise 'a'
rescue => a
b = RuntimeError.new('b')
assert_nil(b.cause)
begin
raise 'c'
rescue
@ -658,6 +662,7 @@ end.join
end
}
assert_equal('c', e.cause.message, 'cause should be the exception at raised')
assert_same(a, e.cause.cause)
end
def test_raise_with_cause
@ -682,6 +687,7 @@ end.join
begin
raise 'b'
rescue => b
assert_same(a, b.cause)
begin
raise 'c'
rescue
@ -691,6 +697,7 @@ end.join
end
}
assert_equal('d', e.cause.message, 'cause option should be honored always')
assert_nil(e.cause.cause)
end
def test_unknown_option
@ -751,7 +758,8 @@ end.join
assert_same(obj, e.receiver)
def obj.test(a, b=nil, *c, &d)
e = a
1.times {|f| g = foo}
1.times {|f| g = foo; g}
e
end
e = assert_raise(NameError) {
obj.test(3)
@ -776,7 +784,7 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
assert_equal 0, errs.size
err = outs.first.force_encoding('utf-8')
assert err.valid_encoding?, 'must be valid encoding'
assert_match /\u3042/, err
assert_match %r/\u3042/, err
end
end

View file

@ -305,7 +305,7 @@ class TestFixnum < Test::Unit::TestCase
big = 1 << 66
assert_eql 1, 1 ** -big , bug5715
assert_eql 1, (-1) ** -big , bug5715
assert_eql -1, (-1) ** -(big+1) , bug5715
assert_eql (-1), (-1) ** -(big+1), bug5715
end
def test_power_of_0

View file

@ -9,6 +9,7 @@ class TestFlip < Test::Unit::TestCase
assert_nothing_raised(NotImplementedError, bug6899) do
2000.times {eval %[(foo..bar) ? 1 : 2]}
end
foo = bar
end
def test_shared_eval

View file

@ -1330,7 +1330,7 @@ class TestHash < Test::Unit::TestCase
def o.respond_to?(*args)
super
end
assert_raise(TypeError) {{foo: o}.dig(:foo, :foo)}
assert_raise(TypeError, bug12030) {{foo: o}.dig(:foo, :foo)}
end
def test_cmp

View file

@ -2185,7 +2185,7 @@ End
assert_file.exist?(fname)
stdin = $stdin.dup
begin
assert_nothing_raised(Errno::ENOENT, enc) {
assert_nothing_raised(Errno::ENOENT, "#{bug11320}: #{enc}") {
$stdin.reopen(fname, 'r')
}
ensure
@ -2461,7 +2461,7 @@ End
def test_flush_in_finalizer1
require 'tempfile'
bug3910 = '[ruby-dev:42341]'
t = Tempfile.open("bug3910") {|t|
tmp = Tempfile.open("bug3910") {|t|
path = t.path
t.close
fds = []
@ -2481,7 +2481,7 @@ End
f.close
end
}
t.close!
tmp.close!
end
def test_flush_in_finalizer2
@ -2959,7 +2959,6 @@ End
def test_frozen_autoclose
with_pipe do |r,w|
fd = r.fileno
assert_equal(true, r.freeze.autoclose?)
end
end

View file

@ -89,9 +89,9 @@ class TestISeq < Test::Unit::TestCase
LINE_BEFORE_METHOD = __LINE__
def method_test_line_trace
a = 1
_a = 1
b = 2
_b = 2
end

View file

@ -109,7 +109,7 @@ class TestIterator < Test::Unit::TestCase
def test_append_method_to_built_in_class
x = [[1,2],[3,4],[5,6]]
assert_equal(x.iter_test1{|x|x}, x.iter_test2{|x|x})
assert_equal(x.iter_test1{|e|e}, x.iter_test2{|e|e})
end
class IterTest

View file

@ -61,9 +61,9 @@ class TestLambdaParameters < Test::Unit::TestCase
assert_equal(nil, ->(&b){ b }.call)
foo { puts "bogus block " }
assert_equal(1, ->(&b){ b.call }.call { 1 })
b = nil
assert_equal(1, ->(&b){ b.call }.call { 1 })
assert_nil(b)
_b = nil
assert_equal(1, ->(&_b){ _b.call }.call { 1 })
assert_nil(_b)
end
def test_call_block_from_lambda

View file

@ -322,7 +322,7 @@ class TestMethod < Test::Unit::TestCase
def o.define(n)
define_singleton_method(n)
end
assert_raise(ArgumentError) {o.define(:bar) {:bar}}
assert_raise(ArgumentError, bug11283) {o.define(:bar) {:bar}}
end
def test_define_method_invalid_arg
@ -804,7 +804,7 @@ class TestMethod < Test::Unit::TestCase
def test_curry_from_proc
c = Class.new {
define_method(:three_args) {|a,b,c| a + b + c}
define_method(:three_args) {|x,y,z| x + y + z}
}
assert_curry_three_args(c.new.method(:three_args))
end
@ -901,7 +901,7 @@ class TestMethod < Test::Unit::TestCase
class C
D = "Const_D"
def foo
a = b = c = 12345
a = b = c = a = b = c = 12345
end
end
@ -909,16 +909,16 @@ class TestMethod < Test::Unit::TestCase
bug11012 = '[ruby-core:68673] [Bug #11012]'
b = C.new.method(:foo).to_proc.binding
assert_equal([], b.local_variables)
assert_equal("Const_D", b.eval("D")) # Check CREF
assert_equal([], b.local_variables, bug11012)
assert_equal("Const_D", b.eval("D"), bug11012) # Check CREF
assert_raise(NameError){ b.local_variable_get(:foo) }
assert_equal(123, b.local_variable_set(:foo, 123))
assert_equal(123, b.local_variable_get(:foo))
assert_equal(456, b.local_variable_set(:bar, 456))
assert_equal(123, b.local_variable_get(:foo))
assert_equal(456, b.local_variable_get(:bar))
assert_equal([:bar, :foo], b.local_variables.sort)
assert_raise(NameError, bug11012){ b.local_variable_get(:foo) }
assert_equal(123, b.local_variable_set(:foo, 123), bug11012)
assert_equal(123, b.local_variable_get(:foo), bug11012)
assert_equal(456, b.local_variable_set(:bar, 456), bug11012)
assert_equal(123, b.local_variable_get(:foo), bug11012)
assert_equal(456, b.local_variable_get(:bar), bug11012)
assert_equal([:bar, :foo], b.local_variables.sort, bug11012)
end
class MethodInMethodClass

View file

@ -844,7 +844,7 @@ class TestObject < Test::Unit::TestCase
end
end
assert_raise_with_message(#{exc}, "bug5473") {1.foo}
assert_raise_with_message(#{exc}, "bug5473", #{bug5473.dump}) {1.foo}
SRC
end
end

View file

@ -681,14 +681,14 @@ x = __ENCODING__
def test_invalid_char
bug10117 = '[ruby-core:64243] [Bug #10117]'
invalid_char = /Invalid char `\\x01'/
x = 1
x = x = 1
assert_in_out_err(%W"-e \x01x", "", [], invalid_char, bug10117)
assert_syntax_error("\x01x", invalid_char, bug10117)
assert_equal(nil, eval("\x04x"))
end
def test_literal_concat
x = "baz"
x = x = "baz"
assert_equal("foobarbaz", eval('"foo" "bar#{x}"'))
end
@ -759,7 +759,7 @@ x = __ENCODING__
$VERBOSE = true
stderr = $stderr
$stderr = StringIO.new("")
x = 1
x = x = 1
assert_nil eval("x; nil")
assert_nil eval("1+1; nil")
assert_nil eval("TestParse; nil")
@ -825,7 +825,7 @@ x = __ENCODING__
end
assert_nothing_raised do
x = "bar"
x = x = "bar"
eval <<-END, nil, __FILE__, __LINE__+1
:"foo#{"x"}baz" ? 1 : 2
END

View file

@ -82,7 +82,7 @@ class TestRubyPrimitive < Test::Unit::TestCase
end
i = 0
while i < 3
r = A3::B3::C # cache
r = r = A3::B3::C # cache
class A3::B3
remove_const :C
end

View file

@ -1264,8 +1264,8 @@ class TestProc < Test::Unit::TestCase
def test_local_variables
b = get_binding
assert_equal(%i'if case when begin end a', b.local_variables)
a = tap {|;a, b| break binding.local_variables}
assert_equal(%i[a b], a.sort)
a = tap {|;x, y| x = y; break binding.local_variables}
assert_equal(%i[a b x y], a.sort)
end
def test_local_variables_nested
@ -1274,7 +1274,7 @@ class TestProc < Test::Unit::TestCase
end
def local_variables_of(bind)
this_should_not_be_in_bind = 2
this_should_not_be_in_bind = this_should_not_be_in_bind = 2
bind.local_variables
end

View file

@ -913,7 +913,7 @@ class Rational_Test < Test::Unit::TestCase
one = Rational( 1, 1)
assert_eql one, one ** -big , bug5715
assert_eql one, (-one) ** -big , bug5715
assert_eql -one, (-one) ** -(big+1) , bug5715
assert_eql (-one), (-one) ** -(big+1) , bug5715
assert_equal Complex, ((-one) ** Rational(1,3)).class
end

View file

@ -818,14 +818,14 @@ class TestRubyOptions < Test::Unit::TestCase
["--disable-frozen-string-literal", false],
[nil, false],
]
debug = [
debugs = [
["--debug-frozen-string-literal", true],
["--debug=frozen-string-literal", true],
["--debug", true],
[nil, false],
]
opts = ["--disable=gems"]
frozen.product(debug) do |(opt1, freeze), (opt2, debug)|
frozen.product(debugs) do |(opt1, freeze), (opt2, debug)|
opt = opts + [opt1, opt2].compact
err = !freeze ? [] : debug ? with_debug_pat : wo_debug_pat
assert_in_out_err(opt, '"foo" << "bar"', [], err)

View file

@ -1359,7 +1359,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
assert_consistent_call_return '[Bug #9959]' do
begin
method_test_argument_error_on_bmethod(wrong_key: 2)
rescue => e
rescue
# ignore
end
end
@ -1369,7 +1369,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
assert_consistent_call_return '[Bug #9961]' do
begin
-Numeric.new
rescue => e
rescue
# ignore
end
end
@ -1413,7 +1413,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
return if Thread.current != target_th
evs << tp.event
}.enable{
a = Bug10724.new
Bug10724.new
}
assert_equal([:call, :return], evs)

View file

@ -174,7 +174,7 @@ class TestSprintf < Test::Unit::TestCase
end
bug11766 = '[ruby-core:71806] [Bug #11766]'
assert_equal("x"*10+" 1.0", sprintf("x"*10+"%8.1f", 1r))
assert_equal("x"*10+" 1.0", sprintf("x"*10+"%8.1f", 1r), bug11766)
end
def test_hash

View file

@ -485,8 +485,8 @@ class TestSuper < Test::Unit::TestCase
bug9740 = '[ruby-core:62017] [Bug #9740]'
b.module_eval do
define_method(:foo) do |result|
um.bind(self).call(result)
define_method(:foo) do |res|
um.bind(self).call(res)
end
end

View file

@ -356,7 +356,7 @@ class TestSymbol < Test::Unit::TestCase
def test_symbol_fstr_leak
bug10686 = '[ruby-core:67268] [Bug #10686]'
x = 0
x = x = 0
assert_no_memory_leak([], '200_000.times { |i| i.to_s.to_sym }; GC.start', <<-"end;", bug10686, limit: 1.71, rss: true)
200_000.times { |i| (i + 200_000).to_s.to_sym }
end;

View file

@ -205,7 +205,7 @@ class TestSyntax < Test::Unit::TestCase
def test_keyword_invalid_name
bug11663 = '[ruby-core:71356] [Bug #11663]'
o = Object.new
o = o = Object.new
assert_syntax_error('def o.foo(arg1?:) end', /arg1\?/, bug11663)
assert_syntax_error('def o.foo(arg1?:, arg2:) end', /arg1\?/, bug11663)
assert_syntax_error('proc {|arg1?:|}', /arg1\?/, bug11663)
@ -362,7 +362,7 @@ WARN
def test_cmdarg_kwarg_lvar_clashing_method
bug12073 = '[ruby-core:73816] [Bug#12073]'
a = 1
a = a = 1
assert_valid_syntax("a b: 1")
assert_valid_syntax("a = 1; a b: 1", bug12073)
end
@ -442,7 +442,7 @@ WARN
}
}
assert_warning(/#{w}/){#/3: #{w}.+4: #{w}.+5: #{w}.+5: #{w}/m){
a = 1
a = a = 1
eval %q{
case 1
when 1, 1
@ -590,7 +590,7 @@ e"
end
def test_dedented_heredoc_with_interpolated_string
w = ""
w = w = ""
result = " \#{mesg} a\n" \
" zy\n"
expect = '#{mesg} a'"\n" \

View file

@ -90,14 +90,12 @@ class TestVariable < Test::Unit::TestCase
def test_shadowing_local_variables
bug9486 = '[ruby-core:60501] [Bug #9486]'
x = tap {|x| break local_variables}
assert_equal([:x, :bug9486], x)
assert_equal([:x, :bug9486], tap {|x| break local_variables}, bug9486)
end
def test_shadowing_block_local_variables
bug9486 = '[ruby-core:60501] [Bug #9486]'
x = tap {|;x| break local_variables}
assert_equal([:x, :bug9486], x)
assert_equal([:x, :bug9486], tap {|;x| x = x; break local_variables}, bug9486)
end
def test_global_variables