diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2018-07-02 15:11:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-02 15:11:36 -0700 |
commit | 78ba021b846e060d5b8f3424259d30a1f3ae4eef (patch) | |
tree | 901d1625c4e796aa89f4e2bdd331e59b48eaac3f | |
parent | 2c30fa71e7af67ef42a3c71651ee5baedfb2fbfe (diff) |
Add continuous test for ruby 2.3, 2.4 and 2.5 (#4829)
* Add continuous test for ruby 2.3, 2.4 and 2.5
* Change ruby 2.5 to 2.5.0
* No need to provide argument to rb_funcall when argc is 0
* Fix tests for ruby 2.5
* Use rescue instead of assert_raise to accept subclass of error
-rw-r--r-- | ruby/compatibility_tests/v3.0.0/tests/basic.rb | 159 | ||||
-rw-r--r-- | ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb | 2 | ||||
-rw-r--r-- | ruby/ext/google/protobuf_c/storage.c | 4 | ||||
-rw-r--r-- | ruby/tests/basic.rb | 4 | ||||
-rw-r--r-- | ruby/tests/repeated_field_test.rb | 2 | ||||
-rwxr-xr-x | tests.sh | 15 |
6 files changed, 150 insertions, 36 deletions
diff --git a/ruby/compatibility_tests/v3.0.0/tests/basic.rb b/ruby/compatibility_tests/v3.0.0/tests/basic.rb index 05fe0278..e2559036 100644 --- a/ruby/compatibility_tests/v3.0.0/tests/basic.rb +++ b/ruby/compatibility_tests/v3.0.0/tests/basic.rb @@ -222,33 +222,55 @@ module BasicTest def test_type_errors m = TestMessage.new - assert_raise TypeError do + + # Use rescue to allow subclasses of error + success = false + begin m.optional_int32 = "hello" + rescue TypeError + success = true end - assert_raise TypeError do - m.optional_string = 42 - end - assert_raise TypeError do + assert(success) + + success = false + begin m.optional_string = nil + rescue TypeError + success = true end - assert_raise TypeError do + assert(success) + + success = false + begin m.optional_bool = 42 + rescue TypeError + success = true end - assert_raise TypeError do + assert(success) + + success = false + begin m.optional_msg = TestMessage.new # expects TestMessage2 + rescue TypeError + success = true end + assert(success) - assert_raise TypeError do + success = false + begin m.repeated_int32 = [] # needs RepeatedField + rescue TypeError + success = true end + assert(success) - assert_raise TypeError do - m.repeated_int32.push "hello" - end - - assert_raise TypeError do + success = false + begin m.repeated_msg.push TestMessage.new + rescue TypeError + success = true end + assert(success) end def test_string_encoding @@ -275,7 +297,7 @@ module BasicTest # strings are immutable so we can't do this, but serialize should catch it. m.optional_string = "asdf".encode!('UTF-8') - assert_raise RuntimeError do + assert_raise do m.optional_string.encode!('ASCII-8BIT') end end @@ -312,10 +334,14 @@ module BasicTest assert l.pop == 9 assert l == [5, 2, 3, 4, 7, 8] - assert_raise TypeError do + success = false + begin m = TestMessage.new l.push m + rescue TypeError + success = true end + assert(success) m = TestMessage.new m.repeated_int32 = l @@ -362,12 +388,22 @@ module BasicTest l = Google::Protobuf::RepeatedField.new(:message, TestMessage) l.push TestMessage.new assert l.count == 1 - assert_raise TypeError do + + success = false + begin l.push TestMessage2.new + rescue TypeError + success = true end - assert_raise TypeError do + assert(success) + + success = false + begin l.push 42 + rescue TypeError + success = true end + assert(success) l2 = l.dup assert l2[0] == l[0] @@ -493,9 +529,14 @@ module BasicTest assert m.length == 0 assert m == {} - assert_raise TypeError do + success = false + begin m[1] = 1 + rescue TypeError + success = true end + assert(success) + assert_raise RangeError do m["asdf"] = 0x1_0000_0000 end @@ -514,18 +555,28 @@ module BasicTest assert_raise RangeError do m[0x8000_0000] = 1 end - assert_raise TypeError do + + success = false + begin m["asdf"] = 1 + rescue TypeError + success = true end + assert(success) m = Google::Protobuf::Map.new(:int64, :int32) m[0x1000_0000_0000_0000] = 1 assert_raise RangeError do m[0x1_0000_0000_0000_0000] = 1 end - assert_raise TypeError do + + success = false + begin m["asdf"] = 1 + rescue TypeError + success = true end + assert(success) m = Google::Protobuf::Map.new(:uint32, :int32) m[0x8000_0000] = 1 @@ -548,18 +599,32 @@ module BasicTest m = Google::Protobuf::Map.new(:bool, :int32) m[true] = 1 m[false] = 2 - assert_raise TypeError do + + success = false + begin m[1] = 1 + rescue TypeError + success = true end - assert_raise TypeError do + assert(success) + + success = false + begin m["asdf"] = 1 + rescue TypeError + success = true end + assert(success) m = Google::Protobuf::Map.new(:string, :int32) m["asdf"] = 1 - assert_raise TypeError do + success = false + begin m[1] = 1 + rescue TypeError + success = true end + assert(success) assert_raise Encoding::UndefinedConversionError do bytestring = ["FFFF"].pack("H*") m[bytestring] = 1 @@ -570,17 +635,25 @@ module BasicTest m[bytestring] = 1 # Allowed -- we will automatically convert to ASCII-8BIT. m["asdf"] = 1 - assert_raise TypeError do + success = false + begin m[1] = 1 + rescue TypeError + success = true end + assert(success) end def test_map_msg_enum_valuetypes m = Google::Protobuf::Map.new(:string, :message, TestMessage) m["asdf"] = TestMessage.new - assert_raise TypeError do + success = false + begin m["jkl;"] = TestMessage2.new + rescue TypeError + success = true end + assert(success) m = Google::Protobuf::Map.new( :string, :message, TestMessage, @@ -645,23 +718,39 @@ module BasicTest m.map_string_msg.delete("c") assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) } - assert_raise TypeError do + success = false + begin m.map_string_msg["e"] = TestMessage.new # wrong value type + rescue TypeError + success = true end + assert(success) # ensure nothing was added by the above assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) } m.map_string_int32 = Google::Protobuf::Map.new(:string, :int32) - assert_raise TypeError do + success = false + begin m.map_string_int32 = Google::Protobuf::Map.new(:string, :int64) + rescue TypeError + success = true end - assert_raise TypeError do + assert(success) + success = false + begin m.map_string_int32 = {} + rescue TypeError + success = true end + assert(success) - assert_raise TypeError do + success = false + begin m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" }) + rescue TypeError + success = true end + assert(success) end def test_map_encode_decode @@ -922,22 +1011,30 @@ module BasicTest def test_def_errors s = Google::Protobuf::DescriptorPool.new - assert_raise TypeError do + success = false + begin s.build do # enum with no default (integer value 0) add_enum "MyEnum" do value :A, 1 end end + rescue TypeError + success = true end - assert_raise TypeError do + assert(success) + success = false + begin s.build do # message with required field (unsupported in proto3) add_message "MyMessage" do required :foo, :int32, 1 end end + rescue TypeError + success = true end + assert(success) end def test_corecursive diff --git a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb index 25727b7b..201fe36b 100644 --- a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb +++ b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb @@ -18,7 +18,7 @@ class RepeatedFieldTest < Test::Unit::TestCase # jRuby additions to the Array class that we can ignore arr_methods -= [ :indices, :iter_for_each, :iter_for_each_index, :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple, - :nitems, :iter_for_reverse_each, :indexes] + :nitems, :iter_for_reverse_each, :indexes, :append, :prepend] arr_methods.each do |method_name| assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}" end diff --git a/ruby/ext/google/protobuf_c/storage.c b/ruby/ext/google/protobuf_c/storage.c index 5d0ac976..163b2f81 100644 --- a/ruby/ext/google/protobuf_c/storage.c +++ b/ruby/ext/google/protobuf_c/storage.c @@ -177,7 +177,7 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, } case UPB_TYPE_STRING: if (CLASS_OF(value) == rb_cSymbol) { - value = rb_funcall(value, rb_intern("to_s"), 0, NULL); + value = rb_funcall(value, rb_intern("to_s"), 0); } else if (CLASS_OF(value) != rb_cString) { rb_raise(cTypeError, "Invalid argument for string field."); } @@ -207,7 +207,7 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class, case UPB_TYPE_ENUM: { int32_t int_val = 0; if (TYPE(value) == T_STRING) { - value = rb_funcall(value, rb_intern("to_sym"), 0, NULL); + value = rb_funcall(value, rb_intern("to_sym"), 0); } else if (!is_ruby_num(value) && TYPE(value) != T_SYMBOL) { rb_raise(cTypeError, "Expected number or symbol type for enum field."); diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 9e9ff385..f174402b 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -350,7 +350,9 @@ module BasicTest # strings are immutable so we can't do this, but serialize should catch it. m.optional_string = "asdf".encode!('UTF-8') - assert_raise RuntimeError do + # Ruby 2.5 changed to raise FrozenError. However, assert_raise don't + # accept subclass. Don't specify type here. + assert_raise do m.optional_string.encode!('ASCII-8BIT') end end diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 61ac4afd..a4f3aab8 100644 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -18,7 +18,7 @@ class RepeatedFieldTest < Test::Unit::TestCase # jRuby additions to the Array class that we can ignore arr_methods -= [ :indices, :iter_for_each, :iter_for_each_index, :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple, - :nitems, :iter_for_reverse_each, :indexes] + :nitems, :iter_for_reverse_each, :indexes, :append, :prepend] arr_methods.each do |method_name| assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}" end @@ -325,6 +325,18 @@ build_ruby22() { internal_build_cpp # For conformance tests. cd ruby && bash travis-test.sh ruby-2.2 && cd .. } +build_ruby23() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.3 && cd .. +} +build_ruby24() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.4 && cd .. +} +build_ruby25() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.5.0 && cd .. +} build_jruby() { internal_build_cpp # For conformance tests. # TODO(xiaofeng): Upgrade to jruby-9.x. There are some broken jests to be @@ -334,6 +346,9 @@ build_jruby() { build_ruby_all() { build_ruby21 build_ruby22 + build_ruby23 + build_ruby24 + build_ruby25 # TODO(teboring): Disable jruby test temperarily for it randomly fails. # https://grpc-testing.appspot.com/job/protobuf_pull_request/735/consoleFull. # build_jruby |