Skip to content

Commit f8407b9

Browse files
committed
Make DiagnoseTests build in Swift 6 mode
1 parent fff4dc4 commit f8407b9

File tree

5 files changed

+68
-32
lines changed

5 files changed

+68
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ default.profraw
33
Package.resolved
44
/.build
55
/.index-build
6+
/.linux-build
67
/Packages
78
/*.xcodeproj
89
/*.sublime-project
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 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+
import class TSCBasic.Process
14+
15+
#if !os(macOS)
16+
import Foundation
17+
#endif
18+
19+
private func xcrunMacOSSDKPath() -> String? {
20+
guard var path = try? Process.checkNonZeroExit(arguments: ["/usr/bin/xcrun", "--show-sdk-path", "--sdk", "macosx"])
21+
else {
22+
return nil
23+
}
24+
if path.last == "\n" {
25+
path = String(path.dropLast())
26+
}
27+
return path
28+
}
29+
30+
/// The default sdk path to use.
31+
public let defaultSDKPath: String? = {
32+
#if os(macOS)
33+
return xcrunMacOSSDKPath()
34+
#else
35+
return ProcessInfo.processInfo.environment["SDKROOT"]
36+
#endif
37+
}()

Sources/SKTestSupport/IndexedSingleSwiftFileTestProject.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Foundation
14-
import ISDBTibs
1514
import LanguageServerProtocol
1615
@_spi(Testing) import SKCore
1716
import SourceKitLSP
@@ -66,7 +65,7 @@ public struct IndexedSingleSwiftFileTestProject {
6665
compilerArguments.append("-index-ignore-system-modules")
6766
}
6867

69-
if let sdk = TibsBuilder.defaultSDKPath {
68+
if let sdk = defaultSDKPath {
7069
compilerArguments += ["-sdk", sdk]
7170

7271
// The following are needed so we can import XCTest

Sources/SKTestSupport/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public func testScratchDir(testName: String = #function) throws -> URL {
7070
/// The temporary directory will be deleted at the end of `directory` unless the
7171
/// `SOURCEKITLSP_KEEP_TEST_SCRATCH_DIR` environment variable is set.
7272
public func withTestScratchDir<T>(
73-
_ body: (AbsolutePath) async throws -> T,
73+
_ body: @Sendable (AbsolutePath) async throws -> T,
7474
testName: String = #function
7575
) async throws -> T {
7676
let scratchDirectory = try testScratchDir(testName: testName)

Tests/DiagnoseTests/DiagnoseTests.swift

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,31 @@ import SKTestSupport
1919
import SourceKitD
2020
import XCTest
2121

22-
import class ISDBTibs.TibsBuilder
2322
import struct TSCBasic.AbsolutePath
2423

25-
final class DiagnoseTests: XCTestCase {
26-
/// If a default SDK is present on the test machine, return the `-sdk` argument that can be placed in the request
27-
/// YAML. Otherwise, return an empty string.
28-
private var sdkArg: String {
29-
if let sdk = TibsBuilder.defaultSDKPath {
30-
return """
31-
"-sdk", "\(sdk)",
32-
"""
33-
} else {
34-
return ""
35-
}
24+
/// If a default SDK is present on the test machine, return the `-sdk` argument that can be placed in the request
25+
/// YAML. Otherwise, return an empty string.
26+
private let sdkArg: String = {
27+
if let sdk = defaultSDKPath {
28+
return """
29+
"-sdk", "\(sdk)",
30+
"""
31+
} else {
32+
return ""
3633
}
37-
38-
/// If a default SDK is present on the test machine, return the `-sdk` argument that can be placed in the request
39-
/// YAML. Otherwise, return an empty string.
40-
private var sdkArgs: [String] {
41-
if let sdk = TibsBuilder.defaultSDKPath {
42-
return ["-sdk", "\(sdk)"]
43-
} else {
44-
return []
45-
}
34+
}()
35+
36+
/// If a default SDK is present on the test machine, return the `-sdk` argument that can be placed in the request
37+
/// YAML. Otherwise, return an empty string.
38+
private let sdkArgs: [String] = {
39+
if let sdk = defaultSDKPath {
40+
return ["-sdk", "\(sdk)"]
41+
} else {
42+
return []
4643
}
44+
}()
4745

46+
final class DiagnoseTests: XCTestCase {
4847
func testRemoveCodeItemsAndMembers() async throws {
4948
// We consider the test case reproducing if cursor info returns the two ambiguous results including their doc
5049
// comments.
@@ -232,25 +231,25 @@ final class DiagnoseTests: XCTestCase {
232231
private func assertReduceSourceKitD(
233232
_ markedFileContents: String,
234233
request: String,
235-
reproducerPredicate: @escaping (String) -> Bool,
234+
reproducerPredicate: @Sendable @escaping (String) -> Bool,
236235
expectedReducedFileContents: String,
237-
file: StaticString = #file,
236+
file: StaticString = #filePath,
238237
line: UInt = #line
239238
) async throws {
240239
let (markers, fileContents) = extractMarkers(markedFileContents)
241240

242241
let toolchain = try await unwrap(ToolchainRegistry.forTesting.default)
243242
logger.debug("Using \(toolchain.path?.pathString ?? "<nil>") to reduce source file")
244-
let requestExecutor = try InProcessSourceKitRequestExecutor(
245-
toolchain: toolchain,
246-
reproducerPredicate: NSPredicate(block: { (requestResponse, _) -> Bool in
247-
reproducerPredicate(requestResponse as! String)
248-
})
249-
)
250243

251244
let markerOffset = try XCTUnwrap(markers["1️⃣"], "Failed to find position marker 1️⃣ in file contents")
252245

253246
try await withTestScratchDir { scratchDir in
247+
let requestExecutor = try InProcessSourceKitRequestExecutor(
248+
toolchain: toolchain,
249+
reproducerPredicate: NSPredicate(block: { (requestResponse, _) -> Bool in
250+
reproducerPredicate(requestResponse as! String)
251+
})
252+
)
254253
let testFilePath = scratchDir.appending(component: "test.swift").pathString
255254
try fileContents.write(toFile: testFilePath, atomically: false, encoding: .utf8)
256255

0 commit comments

Comments
 (0)