Skip to content

Commit 636ed43

Browse files
authored
IntegrationTests: fix AbsolutePath deprecation warnings (#6106)
For some reason these warnings were printed only in certain conditions, which may explain why these calls to a deprecated initializer of `AbsolutePath` persisted in the codebase for so long.
1 parent 895ac0e commit 636ed43

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

IntegrationTests/Tests/IntegrationTests/BasicTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class BasicTests: XCTestCase {
2828
XCTAssertMatch(build1Output, .contains("Build complete"))
2929

3030
// Verify that the app works.
31-
let dealerOutput = try sh(AbsolutePath(".build/debug/dealer", relativeTo: packagePath), "10").stdout
31+
let dealerOutput = try sh(AbsolutePath(validating: ".build/debug/dealer", relativeTo: packagePath), "10").stdout
3232
XCTAssertEqual(dealerOutput.filter(\.isPlayingCardSuit).count, 10)
3333

3434
// Verify that the 'git status' is clean after a build.

IntegrationTests/Tests/IntegrationTests/Helpers.swift

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import enum TSCUtility.Git
1717

1818
let sdkRoot: AbsolutePath? = {
1919
if let environmentPath = ProcessInfo.processInfo.environment["SDK_ROOT"] {
20-
return AbsolutePath(environmentPath)
20+
return try! AbsolutePath(validating: environmentPath)
2121
}
2222

2323
#if os(macOS)
2424
let result = try! Process.popen(arguments: ["xcrun", "--sdk", "macosx", "--show-sdk-path"])
25-
let sdkRoot = try! AbsolutePath(result.utf8Output().spm_chomp())
25+
let sdkRoot = try! AbsolutePath(validating: result.utf8Output().spm_chomp())
2626
return sdkRoot
2727
#else
2828
return nil
@@ -31,21 +31,21 @@ let sdkRoot: AbsolutePath? = {
3131

3232
let toolchainPath: AbsolutePath = {
3333
if let environmentPath = ProcessInfo.processInfo.environment["TOOLCHAIN_PATH"] {
34-
return AbsolutePath(environmentPath)
34+
return try! AbsolutePath(validating: environmentPath)
3535
}
3636

3737
#if os(macOS)
38-
let swiftcPath = try! AbsolutePath(sh("xcrun", "--find", "swift").stdout.spm_chomp())
38+
let swiftcPath = try! AbsolutePath(validating: sh("xcrun", "--find", "swift").stdout.spm_chomp())
3939
#else
40-
let swiftcPath = try! AbsolutePath(sh("which", "swift").stdout.spm_chomp())
40+
let swiftcPath = try! AbsolutePath(validating: sh("which", "swift").stdout.spm_chomp())
4141
#endif
4242
let toolchainPath = swiftcPath.parentDirectory.parentDirectory.parentDirectory
4343
return toolchainPath
4444
}()
4545

4646
let clang: AbsolutePath = {
4747
if let environmentPath = ProcessInfo.processInfo.environment["CLANG_PATH"] {
48-
return AbsolutePath(environmentPath)
48+
return try! AbsolutePath(validating: environmentPath)
4949
}
5050

5151
let clangPath = toolchainPath.appending(components: "usr", "bin", "clang")
@@ -54,7 +54,7 @@ let clang: AbsolutePath = {
5454

5555
let xcodebuild: AbsolutePath = {
5656
#if os(macOS)
57-
let xcodebuildPath = try! AbsolutePath(sh("xcrun", "--find", "xcodebuild").stdout.spm_chomp())
57+
let xcodebuildPath = try! AbsolutePath(validating: sh("xcrun", "--find", "xcodebuild").stdout.spm_chomp())
5858
return xcodebuildPath
5959
#else
6060
fatalError("should not be used on other platforms than macOS")
@@ -63,7 +63,7 @@ let xcodebuild: AbsolutePath = {
6363

6464
let swift: AbsolutePath = {
6565
if let environmentPath = ProcessInfo.processInfo.environment["SWIFT_PATH"] {
66-
return AbsolutePath(environmentPath)
66+
return try! AbsolutePath(validating: environmentPath)
6767
}
6868

6969
let swiftPath = toolchainPath.appending(components: "usr", "bin", "swift")
@@ -72,7 +72,7 @@ let swift: AbsolutePath = {
7272

7373
let swiftc: AbsolutePath = {
7474
if let environmentPath = ProcessInfo.processInfo.environment["SWIFTC_PATH"] {
75-
return AbsolutePath(environmentPath)
75+
return try! AbsolutePath(validating: environmentPath)
7676
}
7777

7878
let swiftcPath = toolchainPath.appending(components: "usr", "bin", "swiftc")
@@ -81,7 +81,7 @@ let swiftc: AbsolutePath = {
8181

8282
let lldb: AbsolutePath = {
8383
if let environmentPath = ProcessInfo.processInfo.environment["LLDB_PATH"] {
84-
return AbsolutePath(environmentPath)
84+
return try! AbsolutePath(validating: environmentPath)
8585
}
8686

8787
// We check if it exists because lldb doesn't exist in Xcode's default toolchain.
@@ -91,7 +91,7 @@ let lldb: AbsolutePath = {
9191
}
9292

9393
#if os(macOS)
94-
let lldbPath = try! AbsolutePath(sh("xcrun", "--find", "lldb").stdout.spm_chomp())
94+
let lldbPath = try! AbsolutePath(validating: sh("xcrun", "--find", "lldb").stdout.spm_chomp())
9595
return lldbPath
9696
#else
9797
fatalError("LLDB_PATH environment variable required")
@@ -100,7 +100,7 @@ let lldb: AbsolutePath = {
100100

101101
let swiftpmBinaryDirectory: AbsolutePath = {
102102
if let environmentPath = ProcessInfo.processInfo.environment["SWIFTPM_BIN_DIR"] {
103-
return AbsolutePath(environmentPath)
103+
return try! AbsolutePath(validating: environmentPath)
104104
}
105105

106106
return swift.parentDirectory
@@ -209,7 +209,10 @@ func fixture(
209209

210210
// Construct the expected path of the fixture.
211211
// FIXME: This seems quite hacky; we should provide some control over where fixtures are found.
212-
let fixtureDir = AbsolutePath("../../../Fixtures/\(name)", relativeTo: AbsolutePath(#file))
212+
let fixtureDir = try AbsolutePath(
213+
validating: "../../../Fixtures/\(name)",
214+
relativeTo: AbsolutePath(validating: #file)
215+
)
213216

214217
// Check that the fixture is really there.
215218
guard localFileSystem.isDirectory(fixtureDir) else {
@@ -317,7 +320,10 @@ func binaryTargetsFixture(_ closure: (AbsolutePath) throws -> Void) throws {
317320
let subpath = inputsPath.appending(component: "SwiftFramework")
318321
let projectPath = subpath.appending(component: "SwiftFramework.xcodeproj")
319322
try sh(xcodebuild, "-project", projectPath, "-scheme", "SwiftFramework", "-derivedDataPath", tmpDir, "COMPILER_INDEX_STORE_ENABLE=NO")
320-
let frameworkPath = AbsolutePath("Build/Products/Debug/SwiftFramework.framework", relativeTo: tmpDir)
323+
let frameworkPath = try AbsolutePath(
324+
validating: "Build/Products/Debug/SwiftFramework.framework",
325+
relativeTo: tmpDir
326+
)
321327
let xcframeworkPath = packagePath.appending(component: "SwiftFramework.xcframework")
322328
try sh(xcodebuild, "-create-xcframework", "-framework", frameworkPath, "-output", xcframeworkPath)
323329
}

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,30 @@ final class SwiftPMTests: XCTestCase {
6262
for entry in try localFileSystem.getDirectoryContents(packagePath.appending(components: "Sources", "foo")) {
6363
try localFileSystem.removeFileTree(packagePath.appending(components: "Sources", "foo", entry))
6464
}
65-
try localFileSystem.writeFileContents(AbsolutePath("Sources/foo/main.m", relativeTo: packagePath)) {
65+
try localFileSystem.writeFileContents(AbsolutePath(validating: "Sources/foo/main.m", relativeTo: packagePath)) {
6666
$0 <<< "int main() {}"
6767
}
6868
let archs = ["x86_64", "arm64"]
6969

7070
for arch in archs {
7171
try sh(swiftBuild, "--package-path", packagePath, "--arch", arch)
72-
let fooPath = AbsolutePath(".build/\(arch)-apple-macosx/debug/foo", relativeTo: packagePath)
72+
let fooPath = try AbsolutePath(
73+
validating: ".build/\(arch)-apple-macosx/debug/foo",
74+
relativeTo: packagePath
75+
)
7376
XCTAssertFileExists(fooPath)
7477
}
7578

7679
let args = [swiftBuild.pathString, "--package-path", packagePath.pathString] + archs.flatMap{ ["--arch", $0] }
7780
try _sh(args)
7881

79-
let fooPath = AbsolutePath(".build/apple/Products/Debug/foo", relativeTo: packagePath)
82+
let fooPath = try AbsolutePath(validating: ".build/apple/Products/Debug/foo", relativeTo: packagePath)
8083
XCTAssertFileExists(fooPath)
8184

82-
let objectsDir = AbsolutePath(".build/apple/Intermediates.noindex/foo.build/Debug/foo.build/Objects-normal", relativeTo: packagePath)
85+
let objectsDir = try AbsolutePath(
86+
validating: ".build/apple/Intermediates.noindex/foo.build/Debug/foo.build/Objects-normal",
87+
relativeTo: packagePath
88+
)
8389
for arch in archs {
8490
XCTAssertDirectoryExists(objectsDir.appending(component: arch))
8591
}

0 commit comments

Comments
 (0)