Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 62 additions & 62 deletions Sources/SPMTestSupport/InMemoryGitRepository.swift

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Sources/SPMTestSupport/ManifestExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import PackageModel
import struct TSCUtility.Version

extension Manifest {
public static func createRootManifest(
package static func createRootManifest(
displayName: String,
path: AbsolutePath = .root,
defaultLocalization: String? = nil,
Expand Down Expand Up @@ -53,7 +53,7 @@ extension Manifest {
)
}

public static func createFileSystemManifest(
package static func createFileSystemManifest(
displayName: String,
path: AbsolutePath,
defaultLocalization: String? = nil,
Expand Down Expand Up @@ -89,7 +89,7 @@ extension Manifest {
)
}

public static func createLocalSourceControlManifest(
package static func createLocalSourceControlManifest(
displayName: String,
path: AbsolutePath,
defaultLocalization: String? = nil,
Expand Down Expand Up @@ -125,7 +125,7 @@ extension Manifest {
)
}

public static func createRemoteSourceControlManifest(
package static func createRemoteSourceControlManifest(
displayName: String,
url: SourceControlURL,
path: AbsolutePath,
Expand Down Expand Up @@ -162,7 +162,7 @@ extension Manifest {
)
}

public static func createRegistryManifest(
package static func createRegistryManifest(
displayName: String,
identity: PackageIdentity,
path: AbsolutePath = .root,
Expand Down Expand Up @@ -199,7 +199,7 @@ extension Manifest {
)
}

public static func createManifest(
package static func createManifest(
displayName: String,
path: AbsolutePath = .root,
packageKind: PackageReference.Kind,
Expand Down Expand Up @@ -238,7 +238,7 @@ extension Manifest {
)
}

public func with(location: String) -> Manifest {
package func with(location: String) -> Manifest {
Manifest(
displayName: self.displayName,
path: self.path,
Expand Down
12 changes: 6 additions & 6 deletions Sources/SPMTestSupport/MockArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ package class MockArchiver: Archiver {
package typealias ValidationHandler = (MockArchiver, AbsolutePath, (Result<Bool, Error>) -> Void) throws -> Void

package struct Extraction: Equatable {
public let archivePath: AbsolutePath
public let destinationPath: AbsolutePath
package let archivePath: AbsolutePath
package let destinationPath: AbsolutePath

public init(archivePath: AbsolutePath, destinationPath: AbsolutePath) {
package init(archivePath: AbsolutePath, destinationPath: AbsolutePath) {
self.archivePath = archivePath
self.destinationPath = destinationPath
}
}

package struct Compression: Equatable {
public let directory: AbsolutePath
public let destinationPath: AbsolutePath
package let directory: AbsolutePath
package let destinationPath: AbsolutePath

public init(directory: AbsolutePath, destinationPath: AbsolutePath) {
package init(directory: AbsolutePath, destinationPath: AbsolutePath) {
self.directory = directory
self.destinationPath = destinationPath
}
Expand Down
84 changes: 42 additions & 42 deletions Sources/SPMTestSupport/MockBuildTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,59 @@ import SPMBuildCore
import TSCUtility
import XCTest

public struct MockToolchain: PackageModel.Toolchain {
package struct MockToolchain: PackageModel.Toolchain {
#if os(Windows)
public let librarianPath = AbsolutePath("/fake/path/to/link.exe")
package let librarianPath = AbsolutePath("/fake/path/to/link.exe")
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
public let librarianPath = AbsolutePath("/fake/path/to/libtool")
package let librarianPath = AbsolutePath("/fake/path/to/libtool")
#else
public let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
package let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
#endif
public let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
public let includeSearchPaths = [AbsolutePath]()
public let librarySearchPaths = [AbsolutePath]()
public let swiftResourcesPath: AbsolutePath? = nil
public let swiftStaticResourcesPath: AbsolutePath? = nil
public let isSwiftDevelopmentToolchain = false
public let sdkRootPath: AbsolutePath? = nil
public let swiftPluginServerPath: AbsolutePath? = nil
public let extraFlags = PackageModel.BuildFlags()
public let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default
public let providedLibraries = [LibraryMetadata]()

public func getClangCompiler() throws -> AbsolutePath {
package let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
package let includeSearchPaths = [AbsolutePath]()
package let librarySearchPaths = [AbsolutePath]()
package let swiftResourcesPath: AbsolutePath? = nil
package let swiftStaticResourcesPath: AbsolutePath? = nil
package let isSwiftDevelopmentToolchain = false
package let sdkRootPath: AbsolutePath? = nil
package let swiftPluginServerPath: AbsolutePath? = nil
package let extraFlags = PackageModel.BuildFlags()
package let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default
package let providedLibraries = [LibraryMetadata]()

package func getClangCompiler() throws -> AbsolutePath {
"/fake/path/to/clang"
}

public func _isClangCompilerVendorApple() throws -> Bool? {
package func _isClangCompilerVendorApple() throws -> Bool? {
#if os(macOS)
return true
#else
return false
#endif
}

public init() {}
package init() {}
}

extension Basics.Triple {
public static let x86_64MacOS = try! Self("x86_64-apple-macosx")
public static let x86_64Linux = try! Self("x86_64-unknown-linux-gnu")
public static let arm64Linux = try! Self("aarch64-unknown-linux-gnu")
public static let arm64Android = try! Self("aarch64-unknown-linux-android")
public static let windows = try! Self("x86_64-unknown-windows-msvc")
public static let wasi = try! Self("wasm32-unknown-wasi")
public static let arm64iOS = try! Self("arm64-apple-ios")
package static let x86_64MacOS = try! Self("x86_64-apple-macosx")
package static let x86_64Linux = try! Self("x86_64-unknown-linux-gnu")
package static let arm64Linux = try! Self("aarch64-unknown-linux-gnu")
package static let arm64Android = try! Self("aarch64-unknown-linux-android")
package static let windows = try! Self("x86_64-unknown-windows-msvc")
package static let wasi = try! Self("wasm32-unknown-wasi")
package static let arm64iOS = try! Self("arm64-apple-ios")
}

public let hostTriple = try! UserToolchain.default.targetTriple
package let hostTriple = try! UserToolchain.default.targetTriple
#if os(macOS)
public let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.13")
package let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.13")
#else
public let defaultTargetTriple: String = hostTriple.tripleString
package let defaultTargetTriple: String = hostTriple.tripleString
#endif

public func mockBuildParameters(
package func mockBuildParameters(
buildPath: AbsolutePath = "/path/to/build",
config: BuildConfiguration = .debug,
toolchain: PackageModel.Toolchain = MockToolchain(),
Expand Down Expand Up @@ -114,7 +114,7 @@ public func mockBuildParameters(
)
}

public func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters {
package func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters {
let triple: Basics.Triple
switch environment.platform {
case .macOS:
Expand All @@ -136,12 +136,12 @@ enum BuildError: Swift.Error {
case error(String)
}

public struct BuildPlanResult {
public let plan: Build.BuildPlan
public let targetMap: [String: TargetBuildDescription]
public let productMap: [String: Build.ProductBuildDescription]
package struct BuildPlanResult {
package let plan: Build.BuildPlan
package let targetMap: [String: TargetBuildDescription]
package let productMap: [String: Build.ProductBuildDescription]

public init(plan: Build.BuildPlan) throws {
package init(plan: Build.BuildPlan) throws {
self.plan = plan
self.productMap = try Dictionary(
throwingUniqueKeysWithValues: plan.buildProducts
Expand All @@ -161,22 +161,22 @@ public struct BuildPlanResult {
)
}

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

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

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

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

extension TargetBuildDescription {
public func swiftTarget() throws -> SwiftTargetBuildDescription {
package func swiftTarget() throws -> SwiftTargetBuildDescription {
switch self {
case .swift(let target):
return target
Expand All @@ -195,7 +195,7 @@ extension TargetBuildDescription {
}
}

public func clangTarget() throws -> ClangTargetBuildDescription {
package func clangTarget() throws -> ClangTargetBuildDescription {
switch self {
case .clang(let target):
return target
Expand Down
32 changes: 16 additions & 16 deletions Sources/SPMTestSupport/MockDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ import Foundation
import PackageLoading
import PackageModel

public typealias SourceControlRequirement = PackageDependency.SourceControl.Requirement
public typealias RegistryRequirement = PackageDependency.Registry.Requirement
package typealias SourceControlRequirement = PackageDependency.SourceControl.Requirement
package typealias RegistryRequirement = PackageDependency.Registry.Requirement

public struct MockDependency {
public let deprecatedName: String?
public let location: Location
public let products: ProductFilter
package struct MockDependency {
package let deprecatedName: String?
package let location: Location
package let products: ProductFilter

init(deprecatedName: String? = nil, location: Location, products: ProductFilter = .everything) {
self.deprecatedName = deprecatedName
self.location = location
self.products = products
}

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

}

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

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

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

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

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

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

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

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

public enum Location {
package enum Location {
case fileSystem(path: RelativePath)
case localSourceControl(path: RelativePath, requirement: SourceControlRequirement)
case remoteSourceControl(url: SourceControlURL, requirement: SourceControlRequirement)
Expand Down
14 changes: 7 additions & 7 deletions Sources/SPMTestSupport/MockDependencyGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import PackageModel

import struct TSCUtility.Version

public struct MockDependencyGraph {
public let name: String
public let constraints: [MockPackageContainer.Constraint]
public let containers: [MockPackageContainer]
public let result: [PackageReference: Version]
package struct MockDependencyGraph {
package let name: String
package let constraints: [MockPackageContainer.Constraint]
package let containers: [MockPackageContainer]
package let result: [PackageReference: Version]

public init(name: String, constraints: [MockPackageContainer.Constraint], containers: [MockPackageContainer], result: [PackageReference : Version]) {
package init(name: String, constraints: [MockPackageContainer.Constraint], containers: [MockPackageContainer], result: [PackageReference : Version]) {
self.name = name
self.constraints = constraints
self.containers = containers
self.result = result
}

public func checkResult(
package func checkResult(
_ output: [(container: PackageReference, version: Version)],
file: StaticString = #file,
line: UInt = #line
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/MockHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import Basics

extension LegacyHTTPClient {
public static func mock(fileSystem: FileSystem) -> LegacyHTTPClient {
package static func mock(fileSystem: FileSystem) -> LegacyHTTPClient {
let handler: LegacyHTTPClient.Handler = { request, _, completion in
switch request.kind {
case.generic:
Expand Down
10 changes: 5 additions & 5 deletions Sources/SPMTestSupport/MockHashAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import Basics
import struct TSCBasic.ByteString
import protocol TSCBasic.HashAlgorithm

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

public let hashes = ThreadSafeArrayStore<ByteString>()
package let hashes = ThreadSafeArrayStore<ByteString>()
private let handler: Handler?

public init(handler: Handler? = nil) {
package init(handler: Handler? = nil) {
self.handler = handler
}

public func hash(_ hash: ByteString) -> ByteString {
package func hash(_ hash: ByteString) -> ByteString {
if let handler = self.handler {
return handler(hash)
} else {
Expand Down
Loading