From c2712f0b86bf8ad0f8f5d00468a91f86040f99c4 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Fri, 3 Jan 2025 13:36:56 +0000 Subject: [PATCH 1/7] Make empty generated source files descriptive Motivation: Sometimes protobuf definition files contain no gRPC services and result in an empty file. This is intentional but could be confusing. Modifications: Empty files now contain a comment indicating they are intentional. ``` // This file contained no services. ``` Result: More descriptive empty source files. --- Sources/GRPCCodeGen/SourceGenerator.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/GRPCCodeGen/SourceGenerator.swift b/Sources/GRPCCodeGen/SourceGenerator.swift index 454258bc6..709a96e9d 100644 --- a/Sources/GRPCCodeGen/SourceGenerator.swift +++ b/Sources/GRPCCodeGen/SourceGenerator.swift @@ -87,13 +87,21 @@ public struct SourceGenerator: Sendable { let translator = IDLToStructuredSwiftTranslator() let textRenderer = TextBasedRenderer(indentation: self.config.indentation) - let structuredSwiftRepresentation = try translator.translate( + var structuredSwiftRepresentation = try translator.translate( codeGenerationRequest: request, accessLevel: self.config.accessLevel, accessLevelOnImports: self.config.accessLevelOnImports, client: self.config.client, server: self.config.server ) + + if structuredSwiftRepresentation.file.contents.codeBlocks.isEmpty { + structuredSwiftRepresentation.file.contents.imports = [] + structuredSwiftRepresentation.file.contents.codeBlocks.append( + CodeBlock(comment: .inline("This file contained no services.")) + ) + } + let sourceFile = try textRenderer.render(structured: structuredSwiftRepresentation) return sourceFile From a968d3c0e6ed8c2717b8a33744f552d2ae91a8b9 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Mon, 6 Jan 2025 13:32:16 +0000 Subject: [PATCH 2/7] empty file notice via Translator, test --- .../IDLToStructuredSwiftTranslator.swift | 18 ++++++++++++++---- Sources/GRPCCodeGen/SourceGenerator.swift | 9 +-------- ...uredSwiftTranslatorSnippetBasedTests.swift | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift index 839ef0fa1..f29019dad 100644 --- a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift +++ b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift @@ -72,13 +72,23 @@ struct IDLToStructuredSwiftTranslator: Translator { } } - let fileDescription = FileDescription( - topComment: .preFormatted(codeGenerationRequest.leadingTrivia), - imports: try self.makeImports( + let imports: [ImportDescription] + if codeBlocks.isEmpty { + imports = [] + codeBlocks.append( + CodeBlock(comment: .inline("This file contained no services.")) + ) + } else { + imports = try self.makeImports( dependencies: codeGenerationRequest.dependencies, accessLevel: accessLevel, accessLevelOnImports: accessLevelOnImports - ), + ) + } + + let fileDescription = FileDescription( + topComment: .preFormatted(codeGenerationRequest.leadingTrivia), + imports: imports, codeBlocks: codeBlocks ) diff --git a/Sources/GRPCCodeGen/SourceGenerator.swift b/Sources/GRPCCodeGen/SourceGenerator.swift index 709a96e9d..5a7b68572 100644 --- a/Sources/GRPCCodeGen/SourceGenerator.swift +++ b/Sources/GRPCCodeGen/SourceGenerator.swift @@ -87,7 +87,7 @@ public struct SourceGenerator: Sendable { let translator = IDLToStructuredSwiftTranslator() let textRenderer = TextBasedRenderer(indentation: self.config.indentation) - var structuredSwiftRepresentation = try translator.translate( + let structuredSwiftRepresentation = try translator.translate( codeGenerationRequest: request, accessLevel: self.config.accessLevel, accessLevelOnImports: self.config.accessLevelOnImports, @@ -95,13 +95,6 @@ public struct SourceGenerator: Sendable { server: self.config.server ) - if structuredSwiftRepresentation.file.contents.codeBlocks.isEmpty { - structuredSwiftRepresentation.file.contents.imports = [] - structuredSwiftRepresentation.file.contents.codeBlocks.append( - CodeBlock(comment: .inline("This file contained no services.")) - ) - } - let sourceFile = try textRenderer.render(structured: structuredSwiftRepresentation) return sourceFile diff --git a/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift b/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift index a64fe0451..dfc09e84b 100644 --- a/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift @@ -298,6 +298,25 @@ final class IDLToStructuredSwiftTranslatorSnippetBasedTests: XCTestCase { ) } + func testEmptyFileGeneration() throws { + let expectedSwift = + """ + /// Some really exciting license header 2023. + + + // This file contained no services. + """ + try self.assertIDLToStructuredSwiftTranslation( + codeGenerationRequest: makeCodeGenerationRequest( + services: [], + dependencies: [] + ), + expectedSwift: expectedSwift, + accessLevel: .public, + server: true + ) + } + private func assertIDLToStructuredSwiftTranslation( codeGenerationRequest: CodeGenerationRequest, expectedSwift: String, From ec55cd51937195318146890665b9bcc24455932b Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Mon, 6 Jan 2025 14:55:50 +0000 Subject: [PATCH 3/7] test imports directly --- .../IDLToStructuredSwiftTranslator.swift | 2 +- .../StructuredSwift+ClientTests.swift | 2 +- .../StructuredSwift+ImportTests.swift | 200 ++++++++++++++++++ .../StructuredSwift+MetadataTests.swift | 2 +- .../StructuredSwift+ServerTests.swift | 2 +- .../Internal/StructuredSwiftTestHelpers.swift | 10 +- ...uredSwiftTranslatorSnippetBasedTests.swift | 158 -------------- 7 files changed, 212 insertions(+), 164 deletions(-) create mode 100644 Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift diff --git a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift index f29019dad..3e7c3d97f 100644 --- a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift +++ b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift @@ -97,7 +97,7 @@ struct IDLToStructuredSwiftTranslator: Translator { return StructuredSwiftRepresentation(file: file) } - private func makeImports( + internal func makeImports( dependencies: [Dependency], accessLevel: SourceGenerator.Config.AccessLevel, accessLevelOnImports: Bool diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ClientTests.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ClientTests.swift index 50d6f7ada..caa8c9bc5 100644 --- a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ClientTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ClientTests.swift @@ -18,7 +18,7 @@ import Testing @testable import GRPCCodeGen -extension StructuedSwiftTests { +extension StructuredSwiftTests { @Suite("Client") struct Client { @Test( diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift new file mode 100644 index 000000000..05926cfcb --- /dev/null +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift @@ -0,0 +1,200 @@ +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Testing + +@testable import GRPCCodeGen + +extension StructuredSwiftTests { + @Suite("Import") + struct Import { + static let translator = IDLToStructuredSwiftTranslator() + + static let allAccessLevels: [SourceGenerator.Config.AccessLevel] = [ + .internal, .public, .package, + ] + + @Test( + "import rendering", + arguments: allAccessLevels + ) + func imports(accessLevel: SourceGenerator.Config.AccessLevel) throws { + var dependencies = [Dependency]() + dependencies.append(Dependency(module: "Foo", accessLevel: .public)) + dependencies.append( + Dependency( + item: .init(kind: .typealias, name: "Bar"), + module: "Foo", + accessLevel: .internal + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .struct, name: "Baz"), + module: "Foo", + accessLevel: .package + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .class, name: "Bac"), + module: "Foo", + accessLevel: .package + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .enum, name: "Bap"), + module: "Foo", + accessLevel: .package + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .protocol, name: "Bat"), + module: "Foo", + accessLevel: .package + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .let, name: "Baq"), + module: "Foo", + accessLevel: .package + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .var, name: "Bag"), + module: "Foo", + accessLevel: .package + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .func, name: "Bak"), + module: "Foo", + accessLevel: .package + ) + ) + + let expected = + """ + \(accessLevel.level) import GRPCCore + public import Foo + internal import typealias Foo.Bar + package import struct Foo.Baz + package import class Foo.Bac + package import enum Foo.Bap + package import protocol Foo.Bat + package import let Foo.Baq + package import var Foo.Bag + package import func Foo.Bak + """ + + let imports = try StructuredSwiftTests.Import.translator.makeImports( + dependencies: dependencies, + accessLevel: accessLevel, + accessLevelOnImports: true + ) + + #expect(render(imports) == expected) + } + + @Test( + "preconcurrency import rendering" + ) + func preconcurrencyImports() throws { + var dependencies = [Dependency]() + dependencies.append( + Dependency( + module: "Foo", + preconcurrency: .required, + accessLevel: .internal + ) + ) + dependencies.append( + Dependency( + item: .init(kind: .enum, name: "Bar"), + module: "Foo", + preconcurrency: .required, + accessLevel: .internal + ) + ) + dependencies.append( + Dependency( + module: "Baz", + preconcurrency: .requiredOnOS(["Deq", "Der"]), + accessLevel: .internal + ) + ) + + let expected = + """ + public import GRPCCore + @preconcurrency internal import Foo + @preconcurrency internal import enum Foo.Bar + #if os(Deq) || os(Der) + @preconcurrency internal import Baz + #else + internal import Baz + #endif + """ + + let imports = try StructuredSwiftTests.Import.translator.makeImports( + dependencies: dependencies, + accessLevel: .public, + accessLevelOnImports: true + ) + + #expect(render(imports) == expected) + } + + @Test( + "SPI import rendering" + ) + func spiImports() throws { + var dependencies = [Dependency]() + dependencies.append( + Dependency(module: "Foo", spi: "Secret", accessLevel: .internal) + ) + dependencies.append( + Dependency( + item: .init(kind: .enum, name: "Bar"), + module: "Foo", + spi: "Secret", + accessLevel: .internal + ) + ) + + let expected = + """ + public import GRPCCore + @_spi(Secret) internal import Foo + @_spi(Secret) internal import enum Foo.Bar + """ + + let imports = try StructuredSwiftTests.Import.translator.makeImports( + dependencies: dependencies, + accessLevel: .public, + accessLevelOnImports: true + ) + + #expect(render(imports) == expected) + } + + } +} diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+MetadataTests.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+MetadataTests.swift index 8107b159c..1b8d9afd2 100644 --- a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+MetadataTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+MetadataTests.swift @@ -18,7 +18,7 @@ import Testing @testable import GRPCCodeGen -extension StructuedSwiftTests { +extension StructuredSwiftTests { @Suite("Metadata") struct Metadata { @Test("typealias Input = ", arguments: AccessModifier.allCases) diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ServerTests.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ServerTests.swift index 45567bafd..a415307a6 100644 --- a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ServerTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ServerTests.swift @@ -18,7 +18,7 @@ import Testing @testable import GRPCCodeGen -extension StructuedSwiftTests { +extension StructuredSwiftTests { @Suite("Server") struct Server { @Test( diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwiftTestHelpers.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwiftTestHelpers.swift index d364e843f..b2c0d2847 100644 --- a/Tests/GRPCCodeGenTests/Internal/StructuredSwiftTestHelpers.swift +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwiftTestHelpers.swift @@ -19,8 +19,8 @@ import Testing @testable import GRPCCodeGen // Used as a namespace for organising other structured swift tests. -@Suite("Structued Swift") -struct StructuedSwiftTests {} +@Suite("Structured Swift") +struct StructuredSwiftTests {} func render(_ declaration: Declaration) -> String { let renderer = TextBasedRenderer(indentation: 2) @@ -40,6 +40,12 @@ func render(_ blocks: [CodeBlock]) -> String { return renderer.renderedContents() } +func render(_ imports: [ImportDescription]) -> String { + let renderer = TextBasedRenderer(indentation: 2) + renderer.renderImports(imports) + return renderer.renderedContents() +} + enum RPCKind: Hashable, Sendable, CaseIterable { case unary case clientStreaming diff --git a/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift b/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift index dfc09e84b..d30fe8954 100644 --- a/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift @@ -21,164 +21,6 @@ import XCTest @testable import GRPCCodeGen final class IDLToStructuredSwiftTranslatorSnippetBasedTests: XCTestCase { - func testImports() throws { - var dependencies = [Dependency]() - dependencies.append(Dependency(module: "Foo", accessLevel: .public)) - dependencies.append( - Dependency( - item: .init(kind: .typealias, name: "Bar"), - module: "Foo", - accessLevel: .internal - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .struct, name: "Baz"), - module: "Foo", - accessLevel: .package - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .class, name: "Bac"), - module: "Foo", - accessLevel: .package - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .enum, name: "Bap"), - module: "Foo", - accessLevel: .package - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .protocol, name: "Bat"), - module: "Foo", - accessLevel: .package - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .let, name: "Baq"), - module: "Foo", - accessLevel: .package - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .var, name: "Bag"), - module: "Foo", - accessLevel: .package - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .func, name: "Bak"), - module: "Foo", - accessLevel: .package - ) - ) - - let expectedSwift = - """ - /// Some really exciting license header 2023. - - public import GRPCCore - public import Foo - internal import typealias Foo.Bar - package import struct Foo.Baz - package import class Foo.Bac - package import enum Foo.Bap - package import protocol Foo.Bat - package import let Foo.Baq - package import var Foo.Bag - package import func Foo.Bak - - """ - try self.assertIDLToStructuredSwiftTranslation( - codeGenerationRequest: makeCodeGenerationRequest(dependencies: dependencies), - expectedSwift: expectedSwift, - accessLevel: .public - ) - } - - func testPreconcurrencyImports() throws { - var dependencies = [Dependency]() - dependencies.append( - Dependency( - module: "Foo", - preconcurrency: .required, - accessLevel: .internal - ) - ) - dependencies.append( - Dependency( - item: .init(kind: .enum, name: "Bar"), - module: "Foo", - preconcurrency: .required, - accessLevel: .internal - ) - ) - dependencies.append( - Dependency( - module: "Baz", - preconcurrency: .requiredOnOS(["Deq", "Der"]), - accessLevel: .internal - ) - ) - let expectedSwift = - """ - /// Some really exciting license header 2023. - - public import GRPCCore - @preconcurrency internal import Foo - @preconcurrency internal import enum Foo.Bar - #if os(Deq) || os(Der) - @preconcurrency internal import Baz - #else - internal import Baz - #endif - - """ - try self.assertIDLToStructuredSwiftTranslation( - codeGenerationRequest: makeCodeGenerationRequest(dependencies: dependencies), - expectedSwift: expectedSwift, - accessLevel: .public - ) - } - - func testSPIImports() throws { - var dependencies = [Dependency]() - dependencies.append( - Dependency(module: "Foo", spi: "Secret", accessLevel: .internal) - ) - dependencies.append( - Dependency( - item: .init(kind: .enum, name: "Bar"), - module: "Foo", - spi: "Secret", - accessLevel: .internal - ) - ) - - let expectedSwift = - """ - /// Some really exciting license header 2023. - - public import GRPCCore - @_spi(Secret) internal import Foo - @_spi(Secret) internal import enum Foo.Bar - - """ - try self.assertIDLToStructuredSwiftTranslation( - codeGenerationRequest: makeCodeGenerationRequest(dependencies: dependencies), - expectedSwift: expectedSwift, - accessLevel: .public - ) - } - func testGeneration() throws { var dependencies = [Dependency]() dependencies.append( From 8385afb1b9a3e09557557744bd43cbeacd0e8627 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Mon, 6 Jan 2025 15:00:36 +0000 Subject: [PATCH 4/7] check codeGenerationRequest.services --- .../Internal/Translator/IDLToStructuredSwiftTranslator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift index 3e7c3d97f..9839cd392 100644 --- a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift +++ b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift @@ -73,7 +73,7 @@ struct IDLToStructuredSwiftTranslator: Translator { } let imports: [ImportDescription] - if codeBlocks.isEmpty { + if codeGenerationRequest.services.isEmpty { imports = [] codeBlocks.append( CodeBlock(comment: .inline("This file contained no services.")) From 087839820c0981254a271d2305e120a53718f730 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Mon, 6 Jan 2025 15:53:34 +0000 Subject: [PATCH 5/7] use package imports --- .../Internal/StructuredSwiftRepresentation.swift | 2 +- .../Translator/IDLToStructuredSwiftTranslator.swift | 6 ++++-- Sources/GRPCCodeGen/SourceGenerator.swift | 4 ++-- .../Internal/StructuredSwift+ImportTests.swift | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/GRPCCodeGen/Internal/StructuredSwiftRepresentation.swift b/Sources/GRPCCodeGen/Internal/StructuredSwiftRepresentation.swift index 3a0f1ee59..ddb340c66 100644 --- a/Sources/GRPCCodeGen/Internal/StructuredSwiftRepresentation.swift +++ b/Sources/GRPCCodeGen/Internal/StructuredSwiftRepresentation.swift @@ -30,7 +30,7 @@ /// A description of an import declaration. /// /// For example: `import Foo`. -struct ImportDescription: Equatable, Codable, Sendable { +package struct ImportDescription: Equatable, Codable, Sendable { /// The access level of the imported module. /// /// For example, the `public` in `public import Foo`. diff --git a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift index 9839cd392..612768cdd 100644 --- a/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift +++ b/Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift @@ -17,7 +17,9 @@ /// Creates a representation for the server and client code, as well as for the enums containing useful type aliases and properties. /// The representation is generated based on the ``CodeGenerationRequest`` object and user specifications, /// using types from ``StructuredSwiftRepresentation``. -struct IDLToStructuredSwiftTranslator: Translator { +package struct IDLToStructuredSwiftTranslator: Translator { + package init() {} + func translate( codeGenerationRequest: CodeGenerationRequest, accessLevel: SourceGenerator.Config.AccessLevel, @@ -97,7 +99,7 @@ struct IDLToStructuredSwiftTranslator: Translator { return StructuredSwiftRepresentation(file: file) } - internal func makeImports( + package func makeImports( dependencies: [Dependency], accessLevel: SourceGenerator.Config.AccessLevel, accessLevelOnImports: Bool diff --git a/Sources/GRPCCodeGen/SourceGenerator.swift b/Sources/GRPCCodeGen/SourceGenerator.swift index 5a7b68572..e8a92ec5f 100644 --- a/Sources/GRPCCodeGen/SourceGenerator.swift +++ b/Sources/GRPCCodeGen/SourceGenerator.swift @@ -61,8 +61,8 @@ public struct SourceGenerator: Sendable { /// The possible access levels for the generated code. public struct AccessLevel: Sendable, Hashable { - internal var level: Level - internal enum Level { + package var level: Level + package enum Level { case `internal` case `public` case `package` diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift index 05926cfcb..71d833ef8 100644 --- a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2024, gRPC Authors All rights reserved. + * Copyright 2025, gRPC Authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ import Testing -@testable import GRPCCodeGen +import GRPCCodeGen extension StructuredSwiftTests { @Suite("Import") From e4faa410137ba04ceb33432889e04f1fe4b58eff Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Mon, 6 Jan 2025 15:56:42 +0000 Subject: [PATCH 6/7] all tests use range of access levels --- .../Internal/StructuredSwift+ImportTests.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift index 71d833ef8..c904b4ff2 100644 --- a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift @@ -115,9 +115,10 @@ extension StructuredSwiftTests { } @Test( - "preconcurrency import rendering" + "preconcurrency import rendering", + arguments: allAccessLevels ) - func preconcurrencyImports() throws { + func preconcurrencyImports(accessLevel: SourceGenerator.Config.AccessLevel) throws { var dependencies = [Dependency]() dependencies.append( Dependency( @@ -144,7 +145,7 @@ extension StructuredSwiftTests { let expected = """ - public import GRPCCore + \(accessLevel.level) import GRPCCore @preconcurrency internal import Foo @preconcurrency internal import enum Foo.Bar #if os(Deq) || os(Der) @@ -156,7 +157,7 @@ extension StructuredSwiftTests { let imports = try StructuredSwiftTests.Import.translator.makeImports( dependencies: dependencies, - accessLevel: .public, + accessLevel: accessLevel, accessLevelOnImports: true ) @@ -164,9 +165,10 @@ extension StructuredSwiftTests { } @Test( - "SPI import rendering" + "SPI import rendering", + arguments: allAccessLevels ) - func spiImports() throws { + func spiImports(accessLevel: SourceGenerator.Config.AccessLevel) throws { var dependencies = [Dependency]() dependencies.append( Dependency(module: "Foo", spi: "Secret", accessLevel: .internal) @@ -182,14 +184,14 @@ extension StructuredSwiftTests { let expected = """ - public import GRPCCore + \(accessLevel.level) import GRPCCore @_spi(Secret) internal import Foo @_spi(Secret) internal import enum Foo.Bar """ let imports = try StructuredSwiftTests.Import.translator.makeImports( dependencies: dependencies, - accessLevel: .public, + accessLevel: accessLevel, accessLevelOnImports: true ) From 11f13a10794f384d5ec8af97fe12eec073b728a9 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Mon, 6 Jan 2025 15:58:20 +0000 Subject: [PATCH 7/7] formatting, of course --- .../Internal/StructuredSwift+ImportTests.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift index c904b4ff2..ff1d34dbe 100644 --- a/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift +++ b/Tests/GRPCCodeGenTests/Internal/StructuredSwift+ImportTests.swift @@ -14,9 +14,8 @@ * limitations under the License. */ -import Testing - import GRPCCodeGen +import Testing extension StructuredSwiftTests { @Suite("Import")