Commit 9118ad65 authored by Feng Xiao's avatar Feng Xiao

Add Ruby compatibilty test against 3.0.0.

parent 963473b1
......@@ -775,6 +775,15 @@ ruby_EXTRA_DIST= \
ruby/.gitignore \
ruby/README.md \
ruby/Rakefile \
ruby/compatibility_tests/v3.0.0/tests/test_import.proto \
ruby/compatibility_tests/v3.0.0/tests/stress.rb \
ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb \
ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb \
ruby/compatibility_tests/v3.0.0/tests/generated_code.proto \
ruby/compatibility_tests/v3.0.0/tests/basic.rb \
ruby/compatibility_tests/v3.0.0/test.sh \
ruby/compatibility_tests/v3.0.0/Rakefile \
ruby/compatibility_tests/v3.0.0/README.md \
ruby/ext/google/protobuf_c/defs.c \
ruby/ext/google/protobuf_c/encode_decode.c \
ruby/ext/google/protobuf_c/extconf.rb \
......
# Protobuf Ruby Compatibility Tests
This drectory contains a snapshot of protobuf ruby 3.0.0 unittest code and
test scripts used to verifies whether the latest version of protobuf is
still compatible with 3.0.0 generated code.
require "rake/testtask"
# Proto for tests.
genproto_output = []
genproto_output << "tests/generated_code.rb"
genproto_output << "tests/test_import.rb"
file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
sh "./protoc --ruby_out=. tests/generated_code.proto"
end
file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
sh "./protoc --ruby_out=. tests/test_import.proto"
end
task :genproto => genproto_output
task :clean do
sh "rm -f #{genproto_output.join(' ')}"
end
Rake::TestTask.new(:test => :genproto) do |t|
t.test_files = FileList["tests/*.rb"]
end
task :default => [:test]
#!/bin/bash
set -ex
# Change to the script's directory
cd $(dirname $0)
# Download 3.0.0 version of protoc
PROTOC_BINARY_NAME="protoc-3.0.0-linux-x86_64.exe"
if [ `uname` = "Darwin" ]; then
PROTOC_BINARY_NAME="protoc-3.0.0-osx-x86_64.exe"
fi
wget http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0/${PROTOC_BINARY_NAME} -O protoc
chmod +x protoc
# Run tests
rake test
This diff is collapsed.
syntax = "proto3";
package a.b.c;
message TestMessage {
int32 optional_int32 = 1;
int64 optional_int64 = 2;
uint32 optional_uint32 = 3;
uint64 optional_uint64 = 4;
bool optional_bool = 5;
double optional_double = 6;
float optional_float = 7;
string optional_string = 8;
bytes optional_bytes = 9;
TestEnum optional_enum = 10;
TestMessage optional_msg = 11;
repeated int32 repeated_int32 = 21;
repeated int64 repeated_int64 = 22;
repeated uint32 repeated_uint32 = 23;
repeated uint64 repeated_uint64 = 24;
repeated bool repeated_bool = 25;
repeated double repeated_double = 26;
repeated float repeated_float = 27;
repeated string repeated_string = 28;
repeated bytes repeated_bytes = 29;
repeated TestEnum repeated_enum = 30;
repeated TestMessage repeated_msg = 31;
oneof my_oneof {
int32 oneof_int32 = 41;
int64 oneof_int64 = 42;
uint32 oneof_uint32 = 43;
uint64 oneof_uint64 = 44;
bool oneof_bool = 45;
double oneof_double = 46;
float oneof_float = 47;
string oneof_string = 48;
bytes oneof_bytes = 49;
TestEnum oneof_enum = 50;
TestMessage oneof_msg = 51;
}
map<int32, string> map_int32_string = 61;
map<int64, string> map_int64_string = 62;
map<uint32, string> map_uint32_string = 63;
map<uint64, string> map_uint64_string = 64;
map<bool, string> map_bool_string = 65;
map<string, string> map_string_string = 66;
map<string, TestMessage> map_string_msg = 67;
map<string, TestEnum> map_string_enum = 68;
map<string, int32> map_string_int32 = 69;
map<string, bool> map_string_bool = 70;
message NestedMessage {
int32 foo = 1;
}
NestedMessage nested_message = 80;
}
enum TestEnum {
Default = 0;
A = 1;
B = 2;
C = 3;
}
#!/usr/bin/ruby
# generated_code.rb is in the same directory as this test.
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
require 'generated_code_pb'
require 'test_import_pb'
require 'test/unit'
class GeneratedCodeTest < Test::Unit::TestCase
def test_generated_msg
# just test that we can instantiate the message. The purpose of this test
# is to ensure that the output of the code generator is valid Ruby and
# successfully creates message definitions and classes, not to test every
# aspect of the extension (basic.rb is for that).
m = A::B::C::TestMessage.new()
m2 = FooBar::TestImportedMessage.new()
end
end
This diff is collapsed.
#!/usr/bin/ruby
require 'google/protobuf'
require 'test/unit'
module StressTest
pool = Google::Protobuf::DescriptorPool.new
pool.build do
add_message "TestMessage" do
optional :a, :int32, 1
repeated :b, :message, 2, "M"
end
add_message "M" do
optional :foo, :string, 1
end
end
TestMessage = pool.lookup("TestMessage").msgclass
M = pool.lookup("M").msgclass
class StressTest < Test::Unit::TestCase
def get_msg
TestMessage.new(:a => 1000,
:b => [M.new(:foo => "hello"),
M.new(:foo => "world")])
end
def test_stress
m = get_msg
data = TestMessage.encode(m)
100_000.times do
mnew = TestMessage.decode(data)
mnew = mnew.dup
assert_equal mnew.inspect, m.inspect
assert TestMessage.encode(mnew) == data
end
end
end
end
syntax = "proto3";
package foo_bar;
message TestImportedMessage {}
......@@ -20,7 +20,8 @@ test_version() {
git clean -f && \
gem install bundler && bundle && \
rake test &&
cd ../conformance && make test_ruby"
cd ../conformance && make test_ruby &&
cd ../ruby/compatibility_tests/v3.0.0 && ./test.sh"
fi
}
......
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