Browse Source

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