@@ -25,8 +25,38 @@ struct ProtobufCodeGeneratorTests {
25
25
static let descriptorSetName = " test-service "
26
26
static let fileDescriptorName = " test-service "
27
27
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 {
30
60
var config = ProtobufCodeGenerator . Config. defaults
31
61
config. accessLevel = accessLevel
32
62
config. indentation = 2
@@ -44,10 +74,13 @@ struct ProtobufCodeGeneratorTests {
44
74
fatalError ( )
45
75
}
46
76
77
+ let expectedAvailability = availability. expected
78
+
47
79
let generated = try generator. generateCode (
48
80
fileDescriptor: Self . fileDescriptor,
49
81
protoFileModuleMappings: ProtoFileToModuleMappings ( ) ,
50
- extraModuleImports: [ ]
82
+ extraModuleImports: [ ] ,
83
+ availabilityOverrides: availability. override
51
84
)
52
85
53
86
let expected = """
@@ -70,7 +103,7 @@ struct ProtobufCodeGeneratorTests {
70
103
// MARK: - test.TestService
71
104
72
105
/// 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 ) , *)
74
107
\( access) enum Test_TestService {
75
108
/// Service descriptor for the " test.TestService " service.
76
109
\( access) static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: " test.TestService " )
@@ -134,15 +167,15 @@ struct ProtobufCodeGeneratorTests {
134
167
}
135
168
}
136
169
137
- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
170
+ @available( \( expectedAvailability ) , *)
138
171
extension GRPCCore.ServiceDescriptor {
139
172
/// Service descriptor for the " test.TestService " service.
140
173
\( access) static let test_TestService = GRPCCore.ServiceDescriptor(fullyQualifiedService: " test.TestService " )
141
174
}
142
175
143
176
// MARK: test.TestService (server)
144
177
145
- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
178
+ @available( \( expectedAvailability ) , *)
146
179
extension Test_TestService {
147
180
/// Streaming variant of the service protocol for the " test.TestService " service.
148
181
///
@@ -404,7 +437,7 @@ struct ProtobufCodeGeneratorTests {
404
437
}
405
438
406
439
// 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 ) , *)
408
441
extension Test_TestService.StreamingServiceProtocol {
409
442
\( access) func registerMethods<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
410
443
router.registerHandler(
@@ -455,7 +488,7 @@ struct ProtobufCodeGeneratorTests {
455
488
}
456
489
457
490
// 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 ) , *)
459
492
extension Test_TestService.ServiceProtocol {
460
493
\( access) func unary(
461
494
request: GRPCCore.StreamingServerRequest<Test_TestInput>,
@@ -492,7 +525,7 @@ struct ProtobufCodeGeneratorTests {
492
525
}
493
526
494
527
// 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 ) , *)
496
529
extension Test_TestService.SimpleServiceProtocol {
497
530
\( access) func unary(
498
531
request: GRPCCore.ServerRequest<Test_TestInput>,
@@ -557,7 +590,7 @@ struct ProtobufCodeGeneratorTests {
557
590
558
591
// MARK: test.TestService (client)
559
592
560
- @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0 , *)
593
+ @available( \( expectedAvailability ) , *)
561
594
extension Test_TestService {
562
595
/// Generated client protocol for the " test.TestService " service.
563
596
///
@@ -816,7 +849,7 @@ struct ProtobufCodeGeneratorTests {
816
849
}
817
850
818
851
// 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 ) , *)
820
853
extension Test_TestService.ClientProtocol {
821
854
/// Call the " Unary " method.
822
855
///
@@ -932,7 +965,7 @@ struct ProtobufCodeGeneratorTests {
932
965
}
933
966
934
967
// 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 ) , *)
936
969
extension Test_TestService.ClientProtocol {
937
970
/// Call the " Unary " method.
938
971
///
0 commit comments