瀏覽代碼

Generated code fixtures: availability guards and descriptor paths (#1797)

Motivation:

The generated code must contain the availability guards on top of all protocols, extensions and typealiases for protocols
in order to be compiled.The full descriptors path caused errors for namespaces and services with the same name, so we will use the relative paths to them in the descriptors array from the 'Method' enum.

Modifications:

- added the availability guards in the translators
- modified the descriptors path in the typealias translator (for the descriptors array)
- modified all tests accordingly

Result:

The generated code will be compiled.
Stefana-Ioana Dranca 1 年之前
父節點
當前提交
97ee781e0a
共有 1 個文件被更改,包括 21 次插入3 次删除
  1. 21 3
      Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift

+ 21 - 3
Tests/GRPCProtobufCodeGenTests/ProtobufCodeGeneratorTests.swift

@@ -68,15 +68,18 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
                         )
                     }
                     internal static let descriptors: [MethodDescriptor] = [
-                        Helloworld.Greeter.Method.SayHello.descriptor
+                        SayHello.descriptor
                     ]
                 }
+                @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
                 internal typealias ClientProtocol = Helloworld_GreeterClientProtocol
+                @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
                 internal typealias Client = Helloworld_GreeterClient
             }
         }
 
         /// The greeting service definition.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         internal protocol Helloworld_GreeterClientProtocol: Sendable {
             /// Sends a greeting.
             func sayHello<R>(
@@ -87,6 +90,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
             ) async throws -> R where R: Sendable
         }
 
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         extension Helloworld.Greeter.ClientProtocol {
             internal func sayHello<R>(
                 request: ClientRequest.Single<Helloworld.Greeter.Method.SayHello.Input>,
@@ -173,10 +177,12 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
                 )
               }
               public static let descriptors: [MethodDescriptor] = [
-                Helloworld.Greeter.Method.SayHello.descriptor
+                SayHello.descriptor
               ]
             }
+            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
             public typealias StreamingServiceProtocol = Helloworld_GreeterStreamingServiceProtocol
+            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
             public typealias ServiceProtocol = Helloworld_GreeterServiceProtocol
           }
         }
@@ -189,6 +195,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// Conformance to `GRPCCore.RegistrableRPCService`.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         extension Helloworld.Greeter.StreamingServiceProtocol {
           @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
           public func registerMethods(with router: inout GRPCCore.RPCRouter) {
@@ -204,12 +211,14 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         public protocol Helloworld_GreeterServiceProtocol: Helloworld.Greeter.StreamingServiceProtocol {
           /// Sends a greeting.
           func sayHello(request: ServerRequest.Single<Helloworld.Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Single<Helloworld.Greeter.Method.SayHello.Output>
         }
 
         /// Partial conformance to `Helloworld_GreeterStreamingServiceProtocol`.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         extension Helloworld.Greeter.ServiceProtocol {
           public func sayHello(request: ServerRequest.Stream<Helloworld.Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Stream<Helloworld.Greeter.Method.SayHello.Output> {
             let response = try await self.sayHello(request: ServerRequest.Single(stream: request))
@@ -262,12 +271,16 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
                 )
               }
               package static let descriptors: [MethodDescriptor] = [
-                Helloworld.Greeter.Method.SayHello.descriptor
+                SayHello.descriptor
               ]
             }
+            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
             package typealias StreamingServiceProtocol = Helloworld_GreeterStreamingServiceProtocol
+            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
             package typealias ServiceProtocol = Helloworld_GreeterServiceProtocol
+            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
             package typealias ClientProtocol = Helloworld_GreeterClientProtocol
+            @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
             package typealias Client = Helloworld_GreeterClient
           }
         }
@@ -280,6 +293,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// Conformance to `GRPCCore.RegistrableRPCService`.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         extension Helloworld.Greeter.StreamingServiceProtocol {
           @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
           package func registerMethods(with router: inout GRPCCore.RPCRouter) {
@@ -295,12 +309,14 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         package protocol Helloworld_GreeterServiceProtocol: Helloworld.Greeter.StreamingServiceProtocol {
           /// Sends a greeting.
           func sayHello(request: ServerRequest.Single<Helloworld.Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Single<Helloworld.Greeter.Method.SayHello.Output>
         }
 
         /// Partial conformance to `Helloworld_GreeterStreamingServiceProtocol`.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         extension Helloworld.Greeter.ServiceProtocol {
           package func sayHello(request: ServerRequest.Stream<Helloworld.Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Stream<Helloworld.Greeter.Method.SayHello.Output> {
             let response = try await self.sayHello(request: ServerRequest.Single(stream: request))
@@ -309,6 +325,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
         }
 
         /// The greeting service definition.
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         package protocol Helloworld_GreeterClientProtocol: Sendable {
           /// Sends a greeting.
           func sayHello<R>(
@@ -319,6 +336,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
           ) async throws -> R where R: Sendable
         }
 
+        @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
         extension Helloworld.Greeter.ClientProtocol {
           package func sayHello<R>(
             request: ClientRequest.Single<Helloworld.Greeter.Method.SayHello.Input>,