package_with_underscore_test.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright 2018 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. require 'open3'
  15. require 'tmpdir'
  16. def main
  17. root_dir = File.join(File.dirname(__FILE__), '..', '..', '..')
  18. pb_dir = File.join(root_dir, 'src', 'ruby', 'end2end', 'protos')
  19. bins_dir = File.join(root_dir, 'cmake', 'build')
  20. plugin = File.join(bins_dir, 'grpc_ruby_plugin')
  21. protoc = File.join(bins_dir, 'third_party', 'protobuf', 'protoc')
  22. got = nil
  23. Dir.mktmpdir do |tmp_dir|
  24. gen_out = File.join(tmp_dir, 'package_with_underscore', 'service_services_pb.rb')
  25. pid = spawn(
  26. protoc,
  27. "--proto_path=#{pb_dir}",
  28. 'package_with_underscore/service.proto',
  29. "--grpc_out=#{tmp_dir}",
  30. "--plugin=protoc-gen-grpc=#{plugin}"
  31. )
  32. Process.waitpid2(pid)
  33. File.open(gen_out) { |f| got = f.read }
  34. end
  35. correct_modularized_rpc = 'rpc :TestOne, ' \
  36. '::Grpc::Testing::PackageWithUnderscore::Data::Request, ' \
  37. '::Grpc::Testing::PackageWithUnderscore::Data::Response'
  38. return if got.include?(correct_modularized_rpc)
  39. fail 'generated file does not match with correct_modularized_rpc'
  40. end
  41. main