@@ -25,8 +25,38 @@ struct ProtobufCodeGeneratorTests {
2525 static let descriptorSetName = " test-service "
2626 static let fileDescriptorName = " test-service "
2727
28- @Test ( " Generate " , arguments: [ CodeGenerator . Config. AccessLevel. internal] )
29- func generate( accessLevel: GRPCCodeGen . CodeGenerator . Config . AccessLevel ) throws {
28+ enum Availability {
29+ case `default`
30+ case fooOS
31+
32+ var override : [ ( String , String ) ] {
33+ switch self {
34+ case . default:
35+ return [ ]
36+ case . fooOS:
37+ return [ ( " fooOS " , " 42.0 " ) ]
38+ }
39+ }
40+
41+ var expected : String {
42+ switch self {
43+ case . default:
44+ return " macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 "
45+ case . fooOS:
46+ return " fooOS 42.0 "
47+ }
48+ }
49+ }
50+
51+ @Test (
52+ " Generate " ,
53+ arguments: [ CodeGenerator . Config. AccessLevel. internal] ,
54+ [ Availability . default, Availability . fooOS]
55+ )
56+ func generate(
57+ accessLevel: GRPCCodeGen . CodeGenerator . Config . AccessLevel ,
58+ availability: Availability
59+ ) throws {
3060 var config = ProtobufCodeGenerator . Config. defaults
3161 config. accessLevel = accessLevel
3262 config. indentation = 2
@@ -44,10 +74,13 @@ struct ProtobufCodeGeneratorTests {
4474 fatalError ( )
4575 }
4676
77+ let expectedAvailability = availability. expected
78+
4779 let generated = try generator. generateCode (
4880 fileDescriptor: Self . fileDescriptor,
4981 protoFileModuleMappings: ProtoFileToModuleMappings ( ) ,
50- extraModuleImports: [ ]
82+ extraModuleImports: [ ] ,
83+ availabilityOverrides: availability. override
5184 )
5285
5386 let expected = """
@@ -70,7 +103,7 @@ struct ProtobufCodeGeneratorTests {
70103 // MARK: - test.TestService
71104
72105 /// Namespace containing generated types for the " test.TestService " service.
73- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
106+ @available( \( expectedAvailability ) , *)
74107 \( access) enum Test_TestService {
75108 /// Service descriptor for the " test.TestService " service.
76109 \( access) static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: " test.TestService " )
@@ -134,15 +167,15 @@ struct ProtobufCodeGeneratorTests {
134167 }
135168 }
136169
137- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
170+ @available( \( expectedAvailability ) , *)
138171 extension GRPCCore.ServiceDescriptor {
139172 /// Service descriptor for the " test.TestService " service.
140173 \( access) static let test_TestService = GRPCCore.ServiceDescriptor(fullyQualifiedService: " test.TestService " )
141174 }
142175
143176 // MARK: test.TestService (server)
144177
145- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
178+ @available( \( expectedAvailability ) , *)
146179 extension Test_TestService {
147180 /// Streaming variant of the service protocol for the " test.TestService " service.
148181 ///
@@ -404,7 +437,7 @@ struct ProtobufCodeGeneratorTests {
404437 }
405438
406439 // Default implementation of 'registerMethods(with:)'.
407- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
440+ @available( \( expectedAvailability ) , *)
408441 extension Test_TestService.StreamingServiceProtocol {
409442 \( access) func registerMethods<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
410443 router.registerHandler(
@@ -455,7 +488,7 @@ struct ProtobufCodeGeneratorTests {
455488 }
456489
457490 // Default implementation of streaming methods from 'StreamingServiceProtocol'.
458- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
491+ @available( \( expectedAvailability ) , *)
459492 extension Test_TestService.ServiceProtocol {
460493 \( access) func unary(
461494 request: GRPCCore.StreamingServerRequest<Test_TestInput>,
@@ -492,7 +525,7 @@ struct ProtobufCodeGeneratorTests {
492525 }
493526
494527 // Default implementation of methods from 'ServiceProtocol'.
495- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
528+ @available( \( expectedAvailability ) , *)
496529 extension Test_TestService.SimpleServiceProtocol {
497530 \( access) func unary(
498531 request: GRPCCore.ServerRequest<Test_TestInput>,
@@ -557,7 +590,7 @@ struct ProtobufCodeGeneratorTests {
557590
558591 // MARK: test.TestService (client)
559592
560- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
593+ @available( \( expectedAvailability ) , *)
561594 extension Test_TestService {
562595 /// Generated client protocol for the " test.TestService " service.
563596 ///
@@ -816,7 +849,7 @@ struct ProtobufCodeGeneratorTests {
816849 }
817850
818851 // Helpers providing default arguments to 'ClientProtocol' methods.
819- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
852+ @available( \( expectedAvailability ) , *)
820853 extension Test_TestService.ClientProtocol {
821854 /// Call the " Unary " method.
822855 ///
@@ -932,7 +965,7 @@ struct ProtobufCodeGeneratorTests {
932965 }
933966
934967 // Helpers providing sugared APIs for 'ClientProtocol' methods.
935- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
968+ @available( \( expectedAvailability ) , *)
936969 extension Test_TestService.ClientProtocol {
937970 /// Call the " Unary " method.
938971 ///
0 commit comments