Skip to content

Commit b9fc53b

Browse files
authored
Adopt package in the test support module (swiftlang#7372)
All of the declarations in this module are never supposed to leak outside of the SwiftPM package.
1 parent 92d65bf commit b9fc53b

29 files changed

+507
-511
lines changed

Sources/SPMTestSupport/InMemoryGitRepository.swift

+62-62
Large diffs are not rendered by default.

Sources/SPMTestSupport/ManifestExtensions.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import PackageModel
1717
import struct TSCUtility.Version
1818

1919
extension Manifest {
20-
public static func createRootManifest(
20+
package static func createRootManifest(
2121
displayName: String,
2222
path: AbsolutePath = .root,
2323
defaultLocalization: String? = nil,
@@ -53,7 +53,7 @@ extension Manifest {
5353
)
5454
}
5555

56-
public static func createFileSystemManifest(
56+
package static func createFileSystemManifest(
5757
displayName: String,
5858
path: AbsolutePath,
5959
defaultLocalization: String? = nil,
@@ -89,7 +89,7 @@ extension Manifest {
8989
)
9090
}
9191

92-
public static func createLocalSourceControlManifest(
92+
package static func createLocalSourceControlManifest(
9393
displayName: String,
9494
path: AbsolutePath,
9595
defaultLocalization: String? = nil,
@@ -125,7 +125,7 @@ extension Manifest {
125125
)
126126
}
127127

128-
public static func createRemoteSourceControlManifest(
128+
package static func createRemoteSourceControlManifest(
129129
displayName: String,
130130
url: SourceControlURL,
131131
path: AbsolutePath,
@@ -162,7 +162,7 @@ extension Manifest {
162162
)
163163
}
164164

165-
public static func createRegistryManifest(
165+
package static func createRegistryManifest(
166166
displayName: String,
167167
identity: PackageIdentity,
168168
path: AbsolutePath = .root,
@@ -199,7 +199,7 @@ extension Manifest {
199199
)
200200
}
201201

202-
public static func createManifest(
202+
package static func createManifest(
203203
displayName: String,
204204
path: AbsolutePath = .root,
205205
packageKind: PackageReference.Kind,
@@ -238,7 +238,7 @@ extension Manifest {
238238
)
239239
}
240240

241-
public func with(location: String) -> Manifest {
241+
package func with(location: String) -> Manifest {
242242
Manifest(
243243
displayName: self.displayName,
244244
path: self.path,

Sources/SPMTestSupport/MockArchiver.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ package class MockArchiver: Archiver {
2828
package typealias ValidationHandler = (MockArchiver, AbsolutePath, (Result<Bool, Error>) -> Void) throws -> Void
2929

3030
package struct Extraction: Equatable {
31-
public let archivePath: AbsolutePath
32-
public let destinationPath: AbsolutePath
31+
package let archivePath: AbsolutePath
32+
package let destinationPath: AbsolutePath
3333

34-
public init(archivePath: AbsolutePath, destinationPath: AbsolutePath) {
34+
package init(archivePath: AbsolutePath, destinationPath: AbsolutePath) {
3535
self.archivePath = archivePath
3636
self.destinationPath = destinationPath
3737
}
3838
}
3939

4040
package struct Compression: Equatable {
41-
public let directory: AbsolutePath
42-
public let destinationPath: AbsolutePath
41+
package let directory: AbsolutePath
42+
package let destinationPath: AbsolutePath
4343

44-
public init(directory: AbsolutePath, destinationPath: AbsolutePath) {
44+
package init(directory: AbsolutePath, destinationPath: AbsolutePath) {
4545
self.directory = directory
4646
self.destinationPath = destinationPath
4747
}

Sources/SPMTestSupport/MockBuildTestHelper.swift

+42-42
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,59 @@ import SPMBuildCore
2020
import TSCUtility
2121
import XCTest
2222

23-
public struct MockToolchain: PackageModel.Toolchain {
23+
package struct MockToolchain: PackageModel.Toolchain {
2424
#if os(Windows)
25-
public let librarianPath = AbsolutePath("/fake/path/to/link.exe")
25+
package let librarianPath = AbsolutePath("/fake/path/to/link.exe")
2626
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
27-
public let librarianPath = AbsolutePath("/fake/path/to/libtool")
27+
package let librarianPath = AbsolutePath("/fake/path/to/libtool")
2828
#else
29-
public let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
29+
package let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
3030
#endif
31-
public let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
32-
public let includeSearchPaths = [AbsolutePath]()
33-
public let librarySearchPaths = [AbsolutePath]()
34-
public let swiftResourcesPath: AbsolutePath? = nil
35-
public let swiftStaticResourcesPath: AbsolutePath? = nil
36-
public let isSwiftDevelopmentToolchain = false
37-
public let sdkRootPath: AbsolutePath? = nil
38-
public let swiftPluginServerPath: AbsolutePath? = nil
39-
public let extraFlags = PackageModel.BuildFlags()
40-
public let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default
41-
public let providedLibraries = [LibraryMetadata]()
42-
43-
public func getClangCompiler() throws -> AbsolutePath {
31+
package let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
32+
package let includeSearchPaths = [AbsolutePath]()
33+
package let librarySearchPaths = [AbsolutePath]()
34+
package let swiftResourcesPath: AbsolutePath? = nil
35+
package let swiftStaticResourcesPath: AbsolutePath? = nil
36+
package let isSwiftDevelopmentToolchain = false
37+
package let sdkRootPath: AbsolutePath? = nil
38+
package let swiftPluginServerPath: AbsolutePath? = nil
39+
package let extraFlags = PackageModel.BuildFlags()
40+
package let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default
41+
package let providedLibraries = [LibraryMetadata]()
42+
43+
package func getClangCompiler() throws -> AbsolutePath {
4444
"/fake/path/to/clang"
4545
}
4646

47-
public func _isClangCompilerVendorApple() throws -> Bool? {
47+
package func _isClangCompilerVendorApple() throws -> Bool? {
4848
#if os(macOS)
4949
return true
5050
#else
5151
return false
5252
#endif
5353
}
5454

55-
public init() {}
55+
package init() {}
5656
}
5757

5858
extension Basics.Triple {
59-
public static let x86_64MacOS = try! Self("x86_64-apple-macosx")
60-
public static let x86_64Linux = try! Self("x86_64-unknown-linux-gnu")
61-
public static let arm64Linux = try! Self("aarch64-unknown-linux-gnu")
62-
public static let arm64Android = try! Self("aarch64-unknown-linux-android")
63-
public static let windows = try! Self("x86_64-unknown-windows-msvc")
64-
public static let wasi = try! Self("wasm32-unknown-wasi")
65-
public static let arm64iOS = try! Self("arm64-apple-ios")
59+
package static let x86_64MacOS = try! Self("x86_64-apple-macosx")
60+
package static let x86_64Linux = try! Self("x86_64-unknown-linux-gnu")
61+
package static let arm64Linux = try! Self("aarch64-unknown-linux-gnu")
62+
package static let arm64Android = try! Self("aarch64-unknown-linux-android")
63+
package static let windows = try! Self("x86_64-unknown-windows-msvc")
64+
package static let wasi = try! Self("wasm32-unknown-wasi")
65+
package static let arm64iOS = try! Self("arm64-apple-ios")
6666
}
6767

68-
public let hostTriple = try! UserToolchain.default.targetTriple
68+
package let hostTriple = try! UserToolchain.default.targetTriple
6969
#if os(macOS)
70-
public let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.13")
70+
package let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.13")
7171
#else
72-
public let defaultTargetTriple: String = hostTriple.tripleString
72+
package let defaultTargetTriple: String = hostTriple.tripleString
7373
#endif
7474

75-
public func mockBuildParameters(
75+
package func mockBuildParameters(
7676
buildPath: AbsolutePath = "/path/to/build",
7777
config: BuildConfiguration = .debug,
7878
toolchain: PackageModel.Toolchain = MockToolchain(),
@@ -114,7 +114,7 @@ public func mockBuildParameters(
114114
)
115115
}
116116

117-
public func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters {
117+
package func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters {
118118
let triple: Basics.Triple
119119
switch environment.platform {
120120
case .macOS:
@@ -136,12 +136,12 @@ enum BuildError: Swift.Error {
136136
case error(String)
137137
}
138138

139-
public struct BuildPlanResult {
140-
public let plan: Build.BuildPlan
141-
public let targetMap: [String: TargetBuildDescription]
142-
public let productMap: [String: Build.ProductBuildDescription]
139+
package struct BuildPlanResult {
140+
package let plan: Build.BuildPlan
141+
package let targetMap: [String: TargetBuildDescription]
142+
package let productMap: [String: Build.ProductBuildDescription]
143143

144-
public init(plan: Build.BuildPlan) throws {
144+
package init(plan: Build.BuildPlan) throws {
145145
self.plan = plan
146146
self.productMap = try Dictionary(
147147
throwingUniqueKeysWithValues: plan.buildProducts
@@ -161,22 +161,22 @@ public struct BuildPlanResult {
161161
)
162162
}
163163

164-
public func checkTargetsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) {
164+
package func checkTargetsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) {
165165
XCTAssertEqual(self.plan.targetMap.count, count, file: file, line: line)
166166
}
167167

168-
public func checkProductsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) {
168+
package func checkProductsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) {
169169
XCTAssertEqual(self.plan.productMap.count, count, file: file, line: line)
170170
}
171171

172-
public func target(for name: String) throws -> TargetBuildDescription {
172+
package func target(for name: String) throws -> TargetBuildDescription {
173173
guard let target = targetMap[name] else {
174174
throw BuildError.error("Target \(name) not found.")
175175
}
176176
return target
177177
}
178178

179-
public func buildProduct(for name: String) throws -> Build.ProductBuildDescription {
179+
package func buildProduct(for name: String) throws -> Build.ProductBuildDescription {
180180
guard let product = productMap[name] else {
181181
// <rdar://problem/30162871> Display the thrown error on macOS
182182
throw BuildError.error("Product \(name) not found.")
@@ -186,7 +186,7 @@ public struct BuildPlanResult {
186186
}
187187

188188
extension TargetBuildDescription {
189-
public func swiftTarget() throws -> SwiftTargetBuildDescription {
189+
package func swiftTarget() throws -> SwiftTargetBuildDescription {
190190
switch self {
191191
case .swift(let target):
192192
return target
@@ -195,7 +195,7 @@ extension TargetBuildDescription {
195195
}
196196
}
197197

198-
public func clangTarget() throws -> ClangTargetBuildDescription {
198+
package func clangTarget() throws -> ClangTargetBuildDescription {
199199
switch self {
200200
case .clang(let target):
201201
return target

Sources/SPMTestSupport/MockDependency.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ import Foundation
1515
import PackageLoading
1616
import PackageModel
1717

18-
public typealias SourceControlRequirement = PackageDependency.SourceControl.Requirement
19-
public typealias RegistryRequirement = PackageDependency.Registry.Requirement
18+
package typealias SourceControlRequirement = PackageDependency.SourceControl.Requirement
19+
package typealias RegistryRequirement = PackageDependency.Registry.Requirement
2020

21-
public struct MockDependency {
22-
public let deprecatedName: String?
23-
public let location: Location
24-
public let products: ProductFilter
21+
package struct MockDependency {
22+
package let deprecatedName: String?
23+
package let location: Location
24+
package let products: ProductFilter
2525

2626
init(deprecatedName: String? = nil, location: Location, products: ProductFilter = .everything) {
2727
self.deprecatedName = deprecatedName
2828
self.location = location
2929
self.products = products
3030
}
3131

32-
public func convert(baseURL: AbsolutePath, identityResolver: IdentityResolver) throws -> PackageDependency {
32+
package func convert(baseURL: AbsolutePath, identityResolver: IdentityResolver) throws -> PackageDependency {
3333
switch self.location {
3434
case .fileSystem(let path):
3535
let absolutePath = baseURL.appending(path)
@@ -119,39 +119,39 @@ public struct MockDependency {
119119

120120
}
121121

122-
public static func fileSystem(path: String, products: ProductFilter = .everything) -> MockDependency {
122+
package static func fileSystem(path: String, products: ProductFilter = .everything) -> MockDependency {
123123
try! MockDependency(location: .fileSystem(path: RelativePath(validating: path)), products: products)
124124
}
125125

126-
public static func sourceControl(path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
126+
package static func sourceControl(path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
127127
try! .sourceControl(path: RelativePath(validating: path), requirement: requirement, products: products)
128128
}
129129

130-
public static func sourceControl(path: RelativePath, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
130+
package static func sourceControl(path: RelativePath, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
131131
MockDependency(location: .localSourceControl(path: path, requirement: requirement), products: products)
132132
}
133133

134-
public static func sourceControlWithDeprecatedName(name: String, path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
134+
package static func sourceControlWithDeprecatedName(name: String, path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
135135
try! MockDependency(deprecatedName: name, location: .localSourceControl(path: RelativePath(validating: path), requirement: requirement), products: products)
136136
}
137137

138-
public static func sourceControl(url: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
138+
package static func sourceControl(url: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
139139
.sourceControl(url: SourceControlURL(url), requirement: requirement, products: products)
140140
}
141141

142-
public static func sourceControl(url: SourceControlURL, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
142+
package static func sourceControl(url: SourceControlURL, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency {
143143
MockDependency(location: .remoteSourceControl(url: url, requirement: requirement), products: products)
144144
}
145145

146-
public static func registry(identity: String, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency {
146+
package static func registry(identity: String, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency {
147147
.registry(identity: .plain(identity), requirement: requirement)
148148
}
149149

150-
public static func registry(identity: PackageIdentity, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency {
150+
package static func registry(identity: PackageIdentity, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency {
151151
MockDependency(location: .registry(identity: identity, requirement: requirement), products: products)
152152
}
153153

154-
public enum Location {
154+
package enum Location {
155155
case fileSystem(path: RelativePath)
156156
case localSourceControl(path: RelativePath, requirement: SourceControlRequirement)
157157
case remoteSourceControl(url: SourceControlURL, requirement: SourceControlRequirement)

Sources/SPMTestSupport/MockDependencyGraph.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import PackageModel
1616

1717
import struct TSCUtility.Version
1818

19-
public struct MockDependencyGraph {
20-
public let name: String
21-
public let constraints: [MockPackageContainer.Constraint]
22-
public let containers: [MockPackageContainer]
23-
public let result: [PackageReference: Version]
19+
package struct MockDependencyGraph {
20+
package let name: String
21+
package let constraints: [MockPackageContainer.Constraint]
22+
package let containers: [MockPackageContainer]
23+
package let result: [PackageReference: Version]
2424

25-
public init(name: String, constraints: [MockPackageContainer.Constraint], containers: [MockPackageContainer], result: [PackageReference : Version]) {
25+
package init(name: String, constraints: [MockPackageContainer.Constraint], containers: [MockPackageContainer], result: [PackageReference : Version]) {
2626
self.name = name
2727
self.constraints = constraints
2828
self.containers = containers
2929
self.result = result
3030
}
3131

32-
public func checkResult(
32+
package func checkResult(
3333
_ output: [(container: PackageReference, version: Version)],
3434
file: StaticString = #file,
3535
line: UInt = #line

Sources/SPMTestSupport/MockHTTPClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Basics
1414

1515
extension LegacyHTTPClient {
16-
public static func mock(fileSystem: FileSystem) -> LegacyHTTPClient {
16+
package static func mock(fileSystem: FileSystem) -> LegacyHTTPClient {
1717
let handler: LegacyHTTPClient.Handler = { request, _, completion in
1818
switch request.kind {
1919
case.generic:

Sources/SPMTestSupport/MockHashAlgorithm.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import Basics
1515
import struct TSCBasic.ByteString
1616
import protocol TSCBasic.HashAlgorithm
1717

18-
public final class MockHashAlgorithm {
19-
public typealias Handler = @Sendable (ByteString) -> ByteString
18+
package final class MockHashAlgorithm {
19+
package typealias Handler = @Sendable (ByteString) -> ByteString
2020

21-
public let hashes = ThreadSafeArrayStore<ByteString>()
21+
package let hashes = ThreadSafeArrayStore<ByteString>()
2222
private let handler: Handler?
2323

24-
public init(handler: Handler? = nil) {
24+
package init(handler: Handler? = nil) {
2525
self.handler = handler
2626
}
2727

28-
public func hash(_ hash: ByteString) -> ByteString {
28+
package func hash(_ hash: ByteString) -> ByteString {
2929
if let handler = self.handler {
3030
return handler(hash)
3131
} else {

0 commit comments

Comments
 (0)