Commit 59133296 authored by Toby Hsieh's avatar Toby Hsieh Committed by Paul Yang

Fix most of the unused variable warnings in Ruby tests (#5313)

* Fix most of the unused variable warnings in Ruby tests

* Add encoded_field_b back in tests/common_tests.rb
parent 43613980
...@@ -204,10 +204,10 @@ module CommonTests ...@@ -204,10 +204,10 @@ module CommonTests
m.optional_string = "asdf".encode!('UTF-8') m.optional_string = "asdf".encode!('UTF-8')
# Ruby 2.5 changed to raise FrozenError. However, assert_raise don't # Ruby 2.5 changed to raise FrozenError. However, assert_raise don't
# accept subclass. # accept subclass.
ok = true ok = false
begin begin
m.optional_string.encode!('ASCII-8BIT') m.optional_string.encode!('ASCII-8BIT')
rescue RuntimeError => e rescue RuntimeError
ok = true ok = true
end end
assert ok assert ok
...@@ -341,16 +341,16 @@ module CommonTests ...@@ -341,16 +341,16 @@ module CommonTests
def test_rptfield_initialize def test_rptfield_initialize
assert_raise ArgumentError do assert_raise ArgumentError do
l = Google::Protobuf::RepeatedField.new Google::Protobuf::RepeatedField.new
end end
assert_raise ArgumentError do assert_raise ArgumentError do
l = Google::Protobuf::RepeatedField.new(:message) Google::Protobuf::RepeatedField.new(:message)
end end
assert_raise ArgumentError do assert_raise ArgumentError do
l = Google::Protobuf::RepeatedField.new([1, 2, 3]) Google::Protobuf::RepeatedField.new([1, 2, 3])
end end
assert_raise ArgumentError do assert_raise ArgumentError do
l = Google::Protobuf::RepeatedField.new(:message, [proto_module::TestMessage2.new]) Google::Protobuf::RepeatedField.new(:message, [proto_module::TestMessage2.new])
end end
end end
...@@ -620,14 +620,14 @@ module CommonTests ...@@ -620,14 +620,14 @@ module CommonTests
encoded_field_d = proto_module::OneofMessage.encode(proto_module::OneofMessage.new(:d => :B)) encoded_field_d = proto_module::OneofMessage.encode(proto_module::OneofMessage.new(:d => :B))
d3 = proto_module::OneofMessage.decode( d3 = proto_module::OneofMessage.decode(
encoded_field_c + encoded_field_a + encoded_field_d) encoded_field_c + encoded_field_a + encoded_field_b + encoded_field_d)
assert d3.a == "" assert d3.a == ""
assert d3.b == 0 assert d3.b == 0
assert d3.c == nil assert d3.c == nil
assert d3.d == :B assert d3.d == :B
d4 = proto_module::OneofMessage.decode( d4 = proto_module::OneofMessage.decode(
encoded_field_c + encoded_field_a + encoded_field_d + encoded_field_c + encoded_field_a + encoded_field_b + encoded_field_d +
encoded_field_c) encoded_field_c)
assert d4.a == "" assert d4.a == ""
assert d4.b == 0 assert d4.b == 0
...@@ -800,7 +800,7 @@ module CommonTests ...@@ -800,7 +800,7 @@ module CommonTests
m = proto_module::Recursive1.new(:foo => proto_module::Recursive2.new) m = proto_module::Recursive1.new(:foo => proto_module::Recursive2.new)
m.foo.foo = m m.foo.foo = m
assert_raise RuntimeError do assert_raise RuntimeError do
serialized = proto_module::Recursive1.encode(m) proto_module::Recursive1.encode(m)
end end
end end
...@@ -933,7 +933,6 @@ module CommonTests ...@@ -933,7 +933,6 @@ module CommonTests
data = proto_module::TestMessage.encode(m) data = proto_module::TestMessage.encode(m)
l = 0
10_000.times do 10_000.times do
m = proto_module::TestMessage.decode(data) m = proto_module::TestMessage.decode(data)
data_new = proto_module::TestMessage.encode(m) data_new = proto_module::TestMessage.encode(m)
......
...@@ -86,7 +86,7 @@ class EncodeDecodeTest < Test::Unit::TestCase ...@@ -86,7 +86,7 @@ class EncodeDecodeTest < Test::Unit::TestCase
end end
def test_encode_wrong_msg def test_encode_wrong_msg
e = assert_raise ::ArgumentError do assert_raise ::ArgumentError do
m = A::B::C::TestMessage.new( m = A::B::C::TestMessage.new(
:optional_int32 => 1, :optional_int32 => 1,
) )
......
...@@ -14,8 +14,8 @@ class GeneratedCodeProto2Test < Test::Unit::TestCase ...@@ -14,8 +14,8 @@ class GeneratedCodeProto2Test < Test::Unit::TestCase
# is to ensure that the output of the code generator is valid Ruby and # is to ensure that the output of the code generator is valid Ruby and
# successfully creates message definitions and classes, not to test every # successfully creates message definitions and classes, not to test every
# aspect of the extension (basic.rb is for that). # aspect of the extension (basic.rb is for that).
m = A::B::Proto2::TestMessage.new() A::B::Proto2::TestMessage.new
m2 = FooBar::Proto2::TestImportedMessage.new() FooBar::Proto2::TestImportedMessage.new
m3 = A::B::Proto2::TestRubyPackageMessage.new() A::B::Proto2::TestRubyPackageMessage.new
end end
end end
...@@ -14,8 +14,8 @@ class GeneratedCodeTest < Test::Unit::TestCase ...@@ -14,8 +14,8 @@ class GeneratedCodeTest < Test::Unit::TestCase
# is to ensure that the output of the code generator is valid Ruby and # is to ensure that the output of the code generator is valid Ruby and
# successfully creates message definitions and classes, not to test every # successfully creates message definitions and classes, not to test every
# aspect of the extension (basic.rb is for that). # aspect of the extension (basic.rb is for that).
m = A::B::C::TestMessage.new() A::B::C::TestMessage.new
m2 = FooBar::TestImportedMessage.new() FooBar::TestImportedMessage.new
m3 = A::B::TestRubyPackageMessage.new() A::B::TestRubyPackageMessage.new
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment