use absolute package name, add test cases

pull/23765/head
Hannah Shi 4 years ago
parent 0649026e8a
commit c8986bc73e
  1. 2
      src/compiler/ruby_generator_string-inl.h
  2. 27
      src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto
  3. 29
      src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto
  4. 20
      src/ruby/spec/pb/codegen/package_option_spec.rb

@ -124,7 +124,7 @@ inline std::string RubyTypeOf(const grpc::protobuf::Descriptor* descriptor) {
ReplacePrefix(&proto_type, ".", ""); // remove the leading . (no package)
proto_type = RubyPackage(descriptor->file()) + "." + proto_type;
}
std::string res(proto_type);
std::string res("." + proto_type);
if (res.find('.') == std::string::npos) {
return res;
} else {

@ -0,0 +1,27 @@
// Copyright 2020 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package same_name;
service SameName {
rpc Health(Request) returns (Status);
}
message Status {
string msg = 1;
}
message Request {}

@ -0,0 +1,29 @@
// Copyright 2020 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package other_name;
option ruby_package = "SameName2";
service SameName2 {
rpc Health(Request) returns (Status);
}
message Status {
string msg = 1;
}
message Request {}

@ -48,6 +48,26 @@ describe 'Code Generation Options' do
expect(services[:NestedMessageTest].output).to eq(RPC::Test::New::Package::Options::Bar::Baz)
end
end
it 'should generate when package and service has same name' do
with_protos(['grpc/testing/same_package_service_name.proto']) do
expect { SameName::SameName::Service }.to raise_error(NameError)
expect(require('grpc/testing/same_package_service_name_services_pb')).to be_truthy
expect { SameName::SameName::Service }.to_not raise_error
expect { SameName::Request }.to_not raise_error
expect { SameName::Status }.to_not raise_error
end
end
it 'should generate when ruby_package and service has same name' do
with_protos(['grpc/testing/same_ruby_package_service_name.proto']) do
expect { SameName2::SameName2::Service }.to raise_error(NameError)
expect(require('grpc/testing/same_ruby_package_service_name_services_pb')).to be_truthy
expect { SameName2::SameName2::Service }.to_not raise_error
expect { SameName2::Request }.to_not raise_error
expect { SameName2::Status }.to_not raise_error
end
end
end
def with_protos(file_paths)

Loading…
Cancel
Save