Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
f4f32a5b
Commit
f4f32a5b
authored
Mar 07, 2019
by
Joe Bolinger
Committed by
Paul Yang
Mar 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make tests work on older rubies (#5823)
parent
1568deab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
38 deletions
+39
-38
basic.rb
ruby/tests/basic.rb
+7
-4
common_tests.rb
ruby/tests/common_tests.rb
+26
-31
type_errors.rb
ruby/tests/type_errors.rb
+6
-3
No files found.
ruby/tests/basic.rb
View file @
f4f32a5b
...
...
@@ -358,6 +358,9 @@ module BasicTest
assert_equal
:proto3
,
file_descriptor
.
syntax
end
# Ruby 2.5 changed to raise FrozenError instead of RuntimeError
FrozenErrorType
=
Gem
::
Version
.
new
(
RUBY_VERSION
)
<
Gem
::
Version
.
new
(
'2.5'
)
?
RuntimeError
:
FrozenError
def
test_map_freeze
m
=
proto_module
::
MapMessage
.
new
m
.
map_string_int32
[
'a'
]
=
5
...
...
@@ -369,10 +372,10 @@ module BasicTest
assert
m
.
map_string_int32
.
frozen?
assert
m
.
map_string_msg
.
frozen?
assert_raise
(
FrozenError
)
{
m
.
map_string_int32
[
'foo'
]
=
1
}
assert_raise
(
FrozenError
)
{
m
.
map_string_msg
[
'bar'
]
=
proto_module
::
TestMessage2
.
new
}
assert_raise
(
FrozenError
)
{
m
.
map_string_int32
.
delete
(
'a'
)
}
assert_raise
(
FrozenError
)
{
m
.
map_string_int32
.
clear
}
assert_raise
(
FrozenError
Type
)
{
m
.
map_string_int32
[
'foo'
]
=
1
}
assert_raise
(
FrozenError
Type
)
{
m
.
map_string_msg
[
'bar'
]
=
proto_module
::
TestMessage2
.
new
}
assert_raise
(
FrozenError
Type
)
{
m
.
map_string_int32
.
delete
(
'a'
)
}
assert_raise
(
FrozenError
Type
)
{
m
.
map_string_int32
.
clear
}
end
end
end
ruby/tests/common_tests.rb
View file @
f4f32a5b
...
...
@@ -4,6 +4,9 @@
# and that the including class should define a 'proto_module' method which returns
# the enclosing module of the proto message classes.
module
CommonTests
# Ruby 2.5 changed to raise FrozenError instead of RuntimeError
FrozenErrorType
=
Gem
::
Version
.
new
(
RUBY_VERSION
)
<
Gem
::
Version
.
new
(
'2.5'
)
?
RuntimeError
:
FrozenError
def
test_defaults
m
=
proto_module
::
TestMessage
.
new
assert
m
.
optional_int32
==
0
...
...
@@ -204,15 +207,7 @@ module CommonTests
# strings are immutable so we can't do this, but serialize should catch it.
m
.
optional_string
=
"asdf"
.
encode!
(
'UTF-8'
)
# Ruby 2.5 changed to raise FrozenError. However, assert_raise don't
# accept subclass.
ok
=
false
begin
m
.
optional_string
.
encode!
(
'ASCII-8BIT'
)
rescue
RuntimeError
ok
=
true
end
assert
ok
assert_raise
(
FrozenErrorType
)
{
m
.
optional_string
.
encode!
(
'ASCII-8BIT'
)
}
end
def
test_rptfield_int32
...
...
@@ -1274,32 +1269,32 @@ module CommonTests
m
.
optional_int32
=
10
m
.
freeze
frozen_error
=
assert_raise
(
FrozenError
)
{
m
.
optional_int32
=
20
}
frozen_error
=
assert_raise
(
FrozenError
Type
)
{
m
.
optional_int32
=
20
}
assert_equal
"can't modify frozen
#{
proto_module
}
::TestMessage"
,
frozen_error
.
message
assert_equal
10
,
m
.
optional_int32
assert_equal
true
,
m
.
frozen?
assert_raise
(
FrozenError
)
{
m
.
optional_int64
=
2
}
assert_raise
(
FrozenError
)
{
m
.
optional_uint32
=
3
}
assert_raise
(
FrozenError
)
{
m
.
optional_uint64
=
4
}
assert_raise
(
FrozenError
)
{
m
.
optional_bool
=
true
}
assert_raise
(
FrozenError
)
{
m
.
optional_float
=
6.0
}
assert_raise
(
FrozenError
)
{
m
.
optional_double
=
7.0
}
assert_raise
(
FrozenError
)
{
m
.
optional_string
=
'8'
}
assert_raise
(
FrozenError
)
{
m
.
optional_bytes
=
nil
}
assert_raise
(
FrozenError
)
{
m
.
optional_msg
=
proto_module
::
TestMessage2
.
new
}
assert_raise
(
FrozenError
)
{
m
.
optional_enum
=
:A
}
assert_raise
(
FrozenError
)
{
m
.
repeated_int32
=
1
}
assert_raise
(
FrozenError
)
{
m
.
repeated_int64
=
2
}
assert_raise
(
FrozenError
)
{
m
.
repeated_uint32
=
3
}
assert_raise
(
FrozenError
)
{
m
.
repeated_uint64
=
4
}
assert_raise
(
FrozenError
)
{
m
.
repeated_bool
=
true
}
assert_raise
(
FrozenError
)
{
m
.
repeated_float
=
6.0
}
assert_raise
(
FrozenError
)
{
m
.
repeated_double
=
7.0
}
assert_raise
(
FrozenError
)
{
m
.
repeated_string
=
'8'
}
assert_raise
(
FrozenError
)
{
m
.
repeated_bytes
=
nil
}
assert_raise
(
FrozenError
)
{
m
.
repeated_msg
=
proto_module
::
TestMessage2
.
new
}
assert_raise
(
FrozenError
)
{
m
.
repeated_enum
=
:A
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_int64
=
2
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_uint32
=
3
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_uint64
=
4
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_bool
=
true
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_float
=
6.0
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_double
=
7.0
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_string
=
'8'
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_bytes
=
nil
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_msg
=
proto_module
::
TestMessage2
.
new
}
assert_raise
(
FrozenError
Type
)
{
m
.
optional_enum
=
:A
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_int32
=
1
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_int64
=
2
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_uint32
=
3
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_uint64
=
4
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_bool
=
true
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_float
=
6.0
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_double
=
7.0
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_string
=
'8'
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_bytes
=
nil
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_msg
=
proto_module
::
TestMessage2
.
new
}
assert_raise
(
FrozenError
Type
)
{
m
.
repeated_enum
=
:A
}
end
def
test_eq
...
...
ruby/tests/type_errors.rb
View file @
f4f32a5b
...
...
@@ -8,13 +8,16 @@ require 'google/protobuf/well_known_types'
require
'generated_code_pb'
class
TestTypeErrors
<
Test
::
Unit
::
TestCase
# Ruby 2.4 unified Fixnum with Integer
IntegerType
=
Gem
::
Version
.
new
(
RUBY_VERSION
)
<
Gem
::
Version
.
new
(
'2.4'
)
?
Fixnum
:
Integer
def
test_bad_string
check_error
Google
::
Protobuf
::
TypeError
,
"Invalid argument for string field 'optional_string' (given
Integer
)."
do
"Invalid argument for string field 'optional_string' (given
#{
IntegerType
.
name
}
)."
do
A
::
B
::
C
::
TestMessage
.
new
(
optional_string:
4
)
end
check_error
Google
::
Protobuf
::
TypeError
,
"Invalid argument for string field 'oneof_string' (given
Integer
)."
do
"Invalid argument for string field 'oneof_string' (given
#{
IntegerType
.
name
}
)."
do
A
::
B
::
C
::
TestMessage
.
new
(
oneof_string:
4
)
end
check_error
ArgumentError
,
...
...
@@ -151,7 +154,7 @@ class TestTypeErrors < Test::Unit::TestCase
def
test_bad_msg
check_error
Google
::
Protobuf
::
TypeError
,
"Invalid type
Integer
to assign to submessage field 'optional_msg'."
do
"Invalid type
#{
IntegerType
.
name
}
to assign to submessage field 'optional_msg'."
do
A
::
B
::
C
::
TestMessage
.
new
(
optional_msg:
2
)
end
check_error
Google
::
Protobuf
::
TypeError
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment