Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Replace uses of deprecated AbsolutePath initializers with throwing variant #1420

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 10 additions & 10 deletions Tests/SwiftDriverTests/APIDigesterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class APIDigesterTests: XCTestCase {
"-output-file-map", ofmPath.pathString,
])
let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .generateABIBaseline })
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/path/to/baseline.abi.json")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(try .init(validating: "/path/to/baseline.abi.json")))]))
}
}
do {
Expand All @@ -136,7 +136,7 @@ class APIDigesterTests: XCTestCase {
"-output-file-map", ofmPath.pathString,
])
let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .generateABIBaseline })
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/path/to/sourceinfo.abi.json")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(try .init(validating: "/path/to/sourceinfo.abi.json")))]))
}
}
}
Expand All @@ -149,8 +149,8 @@ class APIDigesterTests: XCTestCase {
XCTAssertTrue(digesterJob.commandLine.contains("-dump-sdk"))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-module", "foo"]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.relative(.init(".")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/path/to/sdk")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init("/some/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(try .init(validating: "/path/to/sdk")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(try .init(validating: "/some/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-F", .path(.relative(.init("framework/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.relative(.init("foo.api.json")))]))

Expand All @@ -165,8 +165,8 @@ class APIDigesterTests: XCTestCase {
XCTAssertTrue(digesterJob.commandLine.contains("-dump-sdk"))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-module", "foo"]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.relative(.init(".")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/path/to/sdk")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init("/some/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(try .init(validating: "/path/to/sdk")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(try .init(validating: "/some/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-F", .path(.relative(.init("framework/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.relative(.init("foo.abi.json")))]))

Expand Down Expand Up @@ -238,10 +238,10 @@ class APIDigesterTests: XCTestCase {
let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .compareAPIBaseline })
XCTAssertTrue(digesterJob.commandLine.contains("-diagnose-sdk"))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-module", "foo"]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-baseline-path", .path(.absolute(.init("/baseline/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-baseline-path", .path(.absolute(try .init(validating: "/baseline/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.relative(.init(".")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/path/to/sdk")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init("/some/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(try .init(validating: "/path/to/sdk")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(try .init(validating: "/some/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-F", .path(.relative(.init("framework/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-breakage-allowlist-path",
.path(.relative(.init("allowlist/path")))]))
Expand All @@ -257,7 +257,7 @@ class APIDigesterTests: XCTestCase {
"-digester-breakage-allowlist-path", "allowlist/path"])
let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .compareABIBaseline })
XCTAssertTrue(digesterJob.commandLine.contains("-diagnose-sdk"))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-input-paths", .path(.absolute(.init("/baseline/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-input-paths", .path(.absolute(try .init(validating: "/baseline/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-breakage-allowlist-path",
.path(.relative(.init("allowlist/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains("-abi"))
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDriverTests/CachingBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import XCTest
import TestUtilities

private var testInputsPath: AbsolutePath = {
var root: AbsolutePath = AbsolutePath(#file)
var root: AbsolutePath = try! AbsolutePath(validating: #file)
while root.basename != "Tests" {
root = root.parentDirectory
}
Expand Down
20 changes: 11 additions & 9 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import XCTest
import TestUtilities

private var testInputsPath: AbsolutePath = {
var root: AbsolutePath = AbsolutePath(#file)
var root: AbsolutePath = try! AbsolutePath(validating: #file)
while root.basename != "Tests" {
root = root.parentDirectory
}
Expand Down Expand Up @@ -199,13 +199,14 @@ final class ExplicitModuleBuildTests: XCTestCase {

func testModuleDependencyBuildCommandGenerationWithExternalFramework() throws {
do {
let externalDetails: ExternalTargetModuleDetailsMap =
[.swiftPrebuiltExternal("A"): ExternalTargetModuleDetails(path: AbsolutePath("/tmp/A.swiftmodule"),
isFramework: true),
.swiftPrebuiltExternal("K"): ExternalTargetModuleDetails(path: AbsolutePath("/tmp/K.swiftmodule"),
isFramework: true),
.swiftPrebuiltExternal("simpleTestModule"): ExternalTargetModuleDetails(path: AbsolutePath("/tmp/simpleTestModule.swiftmodule"),
isFramework: true)]
let externalDetails: ExternalTargetModuleDetailsMap = [
.swiftPrebuiltExternal("A"): ExternalTargetModuleDetails(path: try AbsolutePath(validating: "/tmp/A.swiftmodule"),
isFramework: true),
.swiftPrebuiltExternal("K"): ExternalTargetModuleDetails(path: try AbsolutePath(validating: "/tmp/K.swiftmodule"),
isFramework: true),
.swiftPrebuiltExternal("simpleTestModule"): ExternalTargetModuleDetails(path: try AbsolutePath(validating: "/tmp/simpleTestModule.swiftmodule"),
isFramework: true)
]
var driver = try Driver(args: ["swiftc", "-explicit-module-build",
"-module-name", "simpleTestModule",
"test.swift"])
Expand Down Expand Up @@ -1240,7 +1241,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
env: ProcessEnv.vars)
let sdkPath = try executor.checkNonZeroExit(
args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp()
let stdLibPath = AbsolutePath(sdkPath).appending(component: "usr")
let stdLibPath = try AbsolutePath(validating: sdkPath)
.appending(component: "usr")
.appending(component: "lib")
.appending(component: "swift")
return (stdLibPath, stdLibPath.appending(component: "shims"))
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftDriverTests/IncrementalCompilationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import TestUtilities
// MARK: - Instance variables and initialization
final class IncrementalCompilationTests: XCTestCase {

var tempDir: AbsolutePath = AbsolutePath("/tmp")
var explicitModuleCacheDir: AbsolutePath = AbsolutePath("/tmp/ModuleCache")
var tempDir: AbsolutePath = { try! AbsolutePath(validating: "/tmp") }()
var explicitModuleCacheDir: AbsolutePath = { try! AbsolutePath(validating: "/tmp/ModuleCache") }()

var derivedDataDir: AbsolutePath {
tempDir.appending(component: "derivedData")
Expand Down
12 changes: 7 additions & 5 deletions Tests/SwiftDriverTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import TSCBasic
#if os(macOS)
internal func bundleRoot() -> AbsolutePath {
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return AbsolutePath(bundle.bundlePath).parentDirectory
return try! AbsolutePath(validating: bundle.bundlePath).parentDirectory
}
fatalError()
}

private let packageDirectory = AbsolutePath(#file).parentDirectory.parentDirectory.parentDirectory
private let packageDirectory = {
try! AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory
}()

// The "default" here means lit.py will be invoked as an executable, while otherwise let's use
// python 3 explicitly.
Expand Down Expand Up @@ -95,7 +97,7 @@ final class IntegrationTests: IntegrationTestCase {
environment: ProcessEnv.vars.merging(extraEnv) { $1 }
)

XCTAssertTrue(localFileSystem.isExecutableFile(AbsolutePath("debug/swift-driver", relativeTo: buildPath)), result)
XCTAssertTrue(localFileSystem.isExecutableFile(try AbsolutePath(validating: "debug/swift-driver", relativeTo: buildPath)), result)
}
#endif
}
Expand Down Expand Up @@ -173,8 +175,8 @@ final class IntegrationTests: IntegrationTestCase {
// you've cloned this package into a Swift compiler working directory,
// that means it'll be the directory with build/, llvm/, swift/, and
// swift-driver/ in it.
let litConfigDir = AbsolutePath(
litConfigPathString,
let litConfigDir = try AbsolutePath(
validating: litConfigPathString,
relativeTo: swiftRootDir
)

Expand Down
32 changes: 16 additions & 16 deletions Tests/SwiftDriverTests/JobExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ extension DarwinToolchain {
args: "xcrun", "-sdk", "macosx", "--show-sdk-path",
environment: env
).spm_chomp()
return AbsolutePath(result)
return try AbsolutePath(validating: result)
}
}

/// macOS resource directory, for testing only.
var resourcesDirectory: Result<AbsolutePath, Swift.Error> {
return Result {
try AbsolutePath("../../lib/swift/macosx", relativeTo: getToolPath(.swiftCompiler))
try AbsolutePath(validating: "../../lib/swift/macosx", relativeTo: getToolPath(.swiftCompiler))
}
}

var clangRT: Result<AbsolutePath, Error> {
resourcesDirectory.map { AbsolutePath("../clang/lib/darwin/libclang_rt.osx.a", relativeTo: $0) }
resourcesDirectory.map { try! AbsolutePath(validating: "../clang/lib/darwin/libclang_rt.osx.a", relativeTo: $0) }
}

var compatibility50: Result<AbsolutePath, Error> {
Expand Down Expand Up @@ -202,9 +202,9 @@ final class JobExecutorTests: XCTestCase {
XCTAssertEqual(delegate.started.count, 3)

let fooObject = try resolver.resolve(.path(.temporary(RelativePath("foo.o"))))
XCTAssertTrue(localFileSystem.exists(AbsolutePath(fooObject)), "expected foo.o to be present in the temporary directory")
XCTAssertTrue(localFileSystem.exists(try AbsolutePath(validating: fooObject)), "expected foo.o to be present in the temporary directory")
try resolver.removeTemporaryDirectory()
XCTAssertFalse(localFileSystem.exists(AbsolutePath(fooObject)), "expected foo.o to be removed from the temporary directory")
XCTAssertFalse(localFileSystem.exists(try AbsolutePath(validating: fooObject)), "expected foo.o to be removed from the temporary directory")
}
#endif
}
Expand Down Expand Up @@ -291,7 +291,7 @@ final class JobExecutorTests: XCTestCase {
let job = Job(
moduleName: "main",
kind: .compile,
tool: ResolvedTool(path: AbsolutePath("/usr/bin/swift"), supportsResponseFiles: false),
tool: ResolvedTool(path: try AbsolutePath(validating: "/usr/bin/swift"), supportsResponseFiles: false),
commandLine: [.flag("something")],
inputs: [],
primaryInputs: [],
Expand Down Expand Up @@ -329,7 +329,7 @@ final class JobExecutorTests: XCTestCase {

env[envVarName] = dummyPath
let overriddenSwiftPath = try DarwinToolchain(env: env, executor: executor).getToolPath(.swiftCompiler)
XCTAssertEqual(overriddenSwiftPath, AbsolutePath(dummyPath))
XCTAssertEqual(overriddenSwiftPath, try AbsolutePath(validating: dummyPath))

// GenericUnixToolchain
env.removeValue(forKey: envVarName)
Expand All @@ -339,7 +339,7 @@ final class JobExecutorTests: XCTestCase {

env[envVarName] = dummyPath
let unixOverriddenSwiftPath = try GenericUnixToolchain(env: env, executor: executor).getToolPath(.swiftCompiler)
XCTAssertEqual(unixOverriddenSwiftPath, AbsolutePath(dummyPath))
XCTAssertEqual(unixOverriddenSwiftPath, try AbsolutePath(validating: dummyPath))
}

func testInputModifiedDuringSingleJobBuild() throws {
Expand Down Expand Up @@ -378,10 +378,10 @@ final class JobExecutorTests: XCTestCase {
let job = Job(moduleName: "Module",
kind: .compile,
tool: ResolvedTool(
path: AbsolutePath("/path/to/the tool"),
path: try AbsolutePath(validating: "/path/to/the tool"),
supportsResponseFiles: false),
commandLine: [.path(.absolute(.init("/with space"))),
.path(.absolute(.init("/withoutspace")))],
commandLine: [.path(.absolute(try .init(validating: "/with space"))),
.path(.absolute(try .init(validating: "/withoutspace")))],
inputs: [], primaryInputs: [], outputs: [])
#if os(Windows)
XCTAssertEqual(try executor.description(of: job, forceResponseFiles: false),
Expand Down Expand Up @@ -509,9 +509,9 @@ final class JobExecutorTests: XCTestCase {
XCTAssertTrue(localFileSystem.exists(outputPath))
// -save-temps wasn't passed, so ensure the temporary file was removed.
XCTAssertFalse(
localFileSystem.exists(.init(try executor.resolver.resolve(.path(driver.allSourcesFileList!))))
localFileSystem.exists(try .init(validating: executor.resolver.resolve(.path(driver.allSourcesFileList!))))
)
XCTAssertFalse(localFileSystem.exists(.init(try executor.resolver.resolve(.path(compileOutput)))))
XCTAssertFalse(localFileSystem.exists(try .init(validating: executor.resolver.resolve(.path(compileOutput)))))
}
}

Expand Down Expand Up @@ -547,9 +547,9 @@ final class JobExecutorTests: XCTestCase {
XCTAssertTrue(localFileSystem.exists(outputPath))
// -save-temps was passed, so ensure the temporary file was not removed.
XCTAssertTrue(
localFileSystem.exists(.init(try executor.resolver.resolve(.path(driver.allSourcesFileList!))))
localFileSystem.exists(try .init(validating: executor.resolver.resolve(.path(driver.allSourcesFileList!))))
)
XCTAssertTrue(localFileSystem.exists(.init(try executor.resolver.resolve(.path(compileOutput)))))
XCTAssertTrue(localFileSystem.exists(try .init(validating: executor.resolver.resolve(.path(compileOutput)))))
}
}

Expand Down Expand Up @@ -584,7 +584,7 @@ final class JobExecutorTests: XCTestCase {
try? driver.run(jobs: jobs)
// A job crashed, so ensure any temporary files written so far are preserved.
XCTAssertTrue(
localFileSystem.exists(.init(try executor.resolver.resolve(.path(driver.allSourcesFileList!))))
localFileSystem.exists(try .init(validating: executor.resolver.resolve(.path(driver.allSourcesFileList!))))
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ extension Job {
type: .swift)
try! self.init(moduleName: "nothing",
kind: .compile,
tool: ResolvedTool(path: AbsolutePath("/dummy"), supportsResponseFiles: false),
tool: ResolvedTool(path: AbsolutePath(validating: "/dummy"), supportsResponseFiles: false),
commandLine: [],
inputs: [input],
primaryInputs: [input],
Expand Down
Loading