Skip to content

Commit c487b3d

Browse files
committed
Make SKCoreTests build in Swift 6 mode
1 parent 544388f commit c487b3d

File tree

3 files changed

+60
-27
lines changed

3 files changed

+60
-27
lines changed

Sources/SKTestSupport/WrappedSemaphore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import Dispatch
1717
///
1818
/// This should only be used for tests that test priority escalation and thus cannot await a `Task` (which would cause
1919
/// priority elevations).
20-
public struct WrappedSemaphore {
21-
let semaphore = DispatchSemaphore(value: 0)
20+
public struct WrappedSemaphore: Sendable {
21+
private let semaphore = DispatchSemaphore(value: 0)
2222

2323
public init() {}
2424

Tests/SKCoreTests/BuildServerBuildSystemTests.swift

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,57 @@ import SKTestSupport
2020
import TSCBasic
2121
import XCTest
2222

23-
final class BuildServerBuildSystemTests: XCTestCase {
24-
/// The path to the INPUTS directory of shared test projects.
25-
private static var skTestSupportInputsDirectory: URL = {
26-
#if os(macOS)
27-
// FIXME: Use Bundle.module.resourceURL once the fix for SR-12912 is released.
28-
29-
var resources = XCTestCase.productsDirectory
30-
.appendingPathComponent("SourceKitLSP_SKTestSupport.bundle")
31-
.appendingPathComponent("Contents")
32-
.appendingPathComponent("Resources")
33-
if !FileManager.default.fileExists(atPath: resources.path) {
34-
// Xcode and command-line swiftpm differ about the path.
35-
resources.deleteLastPathComponent()
36-
resources.deleteLastPathComponent()
37-
}
38-
#else
39-
let resources = XCTestCase.productsDirectory
40-
.appendingPathComponent("SourceKitLSP_SKTestSupport.resources")
41-
#endif
42-
guard FileManager.default.fileExists(atPath: resources.path) else {
43-
fatalError("missing resources \(resources.path)")
44-
}
45-
return resources.appendingPathComponent("INPUTS", isDirectory: true).standardizedFileURL
46-
}()
23+
/// The bundle of the currently executing test.
24+
private let testBundle: Bundle = {
25+
#if os(macOS)
26+
if let bundle = Bundle.allBundles.first(where: { $0.bundlePath.hasSuffix(".xctest") }) {
27+
return bundle
28+
}
29+
fatalError("couldn't find the test bundle")
30+
#else
31+
return Bundle.main
32+
#endif
33+
}()
34+
35+
/// The path to the built products directory.
36+
private let productsDirectory: URL = {
37+
#if os(macOS)
38+
return testBundle.bundleURL.deletingLastPathComponent()
39+
#else
40+
return testBundle.bundleURL
41+
#endif
42+
}()
43+
44+
/// The path to the INPUTS directory of shared test projects.
45+
private let skTestSupportInputsDirectory: URL = {
46+
#if os(macOS)
47+
// FIXME: Use Bundle.module.resourceURL once the fix for SR-12912 is released.
48+
49+
var resources =
50+
productsDirectory
51+
.appendingPathComponent("SourceKitLSP_SKTestSupport.bundle")
52+
.appendingPathComponent("Contents")
53+
.appendingPathComponent("Resources")
54+
if !FileManager.default.fileExists(atPath: resources.path) {
55+
// Xcode and command-line swiftpm differ about the path.
56+
resources.deleteLastPathComponent()
57+
resources.deleteLastPathComponent()
58+
}
59+
#else
60+
let resources = XCTestCase.productsDirectory
61+
.appendingPathComponent("SourceKitLSP_SKTestSupport.resources")
62+
#endif
63+
guard FileManager.default.fileExists(atPath: resources.path) else {
64+
fatalError("missing resources \(resources.path)")
65+
}
66+
return resources.appendingPathComponent("INPUTS", isDirectory: true).standardizedFileURL
67+
}()
4768

69+
final class BuildServerBuildSystemTests: XCTestCase {
4870
private var root: AbsolutePath {
4971
try! AbsolutePath(
50-
validating: Self.skTestSupportInputsDirectory
72+
validating:
73+
skTestSupportInputsDirectory
5174
.appendingPathComponent(testDirectoryName, isDirectory: true).path
5275
)
5376
}

Tests/SKCoreTests/BuildSystemManagerTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ final class BuildSystemManagerTests: XCTestCase {
8888
await assertEqual(bsm._cachedMainFile(for: d), nil)
8989
}
9090

91+
@MainActor
9192
func testSettingsMainFile() async throws {
9293
let a = try DocumentURI(string: "bsm:a.swift")
9394
let mainFiles = ManualMainFilesProvider([a: [a]])
@@ -112,6 +113,7 @@ final class BuildSystemManagerTests: XCTestCase {
112113
try await fulfillmentOfOrThrow([changed])
113114
}
114115

116+
@MainActor
115117
func testSettingsMainFileInitialNil() async throws {
116118
let a = try DocumentURI(string: "bsm:a.swift")
117119
let mainFiles = ManualMainFilesProvider([a: [a]])
@@ -134,6 +136,7 @@ final class BuildSystemManagerTests: XCTestCase {
134136
try await fulfillmentOfOrThrow([changed])
135137
}
136138

139+
@MainActor
137140
func testSettingsMainFileWithFallback() async throws {
138141
let a = try DocumentURI(string: "bsm:a.swift")
139142
let mainFiles = ManualMainFilesProvider([a: [a]])
@@ -164,6 +167,7 @@ final class BuildSystemManagerTests: XCTestCase {
164167
try await fulfillmentOfOrThrow([revert])
165168
}
166169

170+
@MainActor
167171
func testSettingsMainFileInitialIntersect() async throws {
168172
let a = try DocumentURI(string: "bsm:a.swift")
169173
let b = try DocumentURI(string: "bsm:b.swift")
@@ -205,6 +209,7 @@ final class BuildSystemManagerTests: XCTestCase {
205209
try await fulfillmentOfOrThrow([changedBothA, changedBothB])
206210
}
207211

212+
@MainActor
208213
func testSettingsMainFileUnchanged() async throws {
209214
let a = try DocumentURI(string: "bsm:a.swift")
210215
let b = try DocumentURI(string: "bsm:b.swift")
@@ -236,6 +241,7 @@ final class BuildSystemManagerTests: XCTestCase {
236241
try await fulfillmentOfOrThrow([changed])
237242
}
238243

244+
@MainActor
239245
func testSettingsHeaderChangeMainFile() async throws {
240246
let h = try DocumentURI(string: "bsm:header.h")
241247
let cpp1 = try DocumentURI(string: "bsm:main.cpp")
@@ -292,6 +298,7 @@ final class BuildSystemManagerTests: XCTestCase {
292298
try await fulfillmentOfOrThrow([changed4])
293299
}
294300

301+
@MainActor
295302
func testSettingsOneMainTwoHeader() async throws {
296303
let h1 = try DocumentURI(string: "bsm:header1.h")
297304
let h2 = try DocumentURI(string: "bsm:header2.h")
@@ -340,6 +347,7 @@ final class BuildSystemManagerTests: XCTestCase {
340347
try await fulfillmentOfOrThrow([changed1, changed2])
341348
}
342349

350+
@MainActor
343351
func testSettingsChangedAfterUnregister() async throws {
344352
let a = try DocumentURI(string: "bsm:a.swift")
345353
let b = try DocumentURI(string: "bsm:b.swift")
@@ -384,6 +392,7 @@ final class BuildSystemManagerTests: XCTestCase {
384392
try await fulfillmentOfOrThrow([changedB])
385393
}
386394

395+
@MainActor
387396
func testDependenciesUpdated() async throws {
388397
let a = try DocumentURI(string: "bsm:a.swift")
389398
let mainFiles = ManualMainFilesProvider([a: [a]])
@@ -434,6 +443,7 @@ private final actor ManualMainFilesProvider: MainFilesProvider {
434443
}
435444

436445
/// A simple `BuildSystem` that wraps a dictionary, for testing.
446+
@MainActor
437447
class ManualBuildSystem: BuildSystem {
438448
var projectRoot = try! AbsolutePath(validating: "/")
439449

0 commit comments

Comments
 (0)