Skip to content

Commit dfd9189

Browse files
authored
Merge pull request #2176 from owenv/owenv/swift-testing
Port SwiftPMBuildSystemTests to Swift Testing
2 parents 6143d26 + dd5800c commit dfd9189

File tree

3 files changed

+185
-135
lines changed

3 files changed

+185
-135
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
public import Testing
14+
15+
public func expectThrowsError<T>(
16+
_ expression: @autoclosure () async throws -> T,
17+
_ message: @autoclosure () -> String = "",
18+
sourceLocation: SourceLocation = #_sourceLocation,
19+
errorHandler: (_ error: Error) -> Void = { _ in }
20+
) async {
21+
do {
22+
_ = try await expression()
23+
Issue.record("Expression was expected to throw but did not throw", sourceLocation: sourceLocation)
24+
} catch {
25+
errorHandler(error)
26+
}
27+
}

Sources/SKTestSupport/PluginPaths.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ import Foundation
1414
package import SourceKitD
1515
import ToolchainRegistry
1616

17+
// Anchor class to lookup the testing bundle when swiftpm-testing-helper is used.
18+
private final class TestingAnchor {}
19+
1720
/// The path to the `SwiftSourceKitPluginTests` test bundle. This gives us a hook into the the build directory.
1821
private let xctestBundle: URL = {
1922
#if canImport(Darwin)
2023
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
2124
return bundle.bundleURL
2225
}
26+
let bundle = Bundle(for: TestingAnchor.self)
27+
if bundle.bundlePath.hasSuffix(".xctest") {
28+
return bundle.bundleURL
29+
}
2330
preconditionFailure("Failed to find xctest bundle")
2431
#else
2532
return URL(

0 commit comments

Comments
 (0)