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

Improve swift-driver test cases to avoid fatal crash #1434

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Expand Up @@ -932,9 +932,9 @@ final class ExplicitModuleBuildTests: XCTestCase {
main.nativePathString(escaped: true)] + sdkArgumentsForTesting

let deps =
try! dependencyOracle.getImports(workingDirectory: path,
moduleAliases: ["Car": "Bar"],
commandLine: scannerCommand)
try dependencyOracle.getImports(workingDirectory: path,
moduleAliases: ["Car": "Bar"],
commandLine: scannerCommand)

XCTAssertTrue(deps.imports.contains("Bar"))
XCTAssertFalse(deps.imports.contains("Car"))
Expand Down Expand Up @@ -1192,8 +1192,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
scannerCommand.removeFirst()
}
let dependencyGraph =
try! dependencyOracle.getDependencies(workingDirectory: path,
commandLine: scannerCommand)
try dependencyOracle.getDependencies(workingDirectory: path,
commandLine: scannerCommand)

let fooDependencyInfo = try XCTUnwrap(dependencyGraph.modules[.swiftPrebuiltExternal("Foo")])
guard case .swiftPrebuiltExternal(let fooDetails) = fooDependencyInfo.details else {
Expand Down Expand Up @@ -1299,8 +1299,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
main.nativePathString(escaped: true)] + sdkArgumentsForTesting

let imports =
try! dependencyOracle.getImports(workingDirectory: path,
commandLine: scannerCommand)
try dependencyOracle.getImports(workingDirectory: path,
commandLine: scannerCommand)
let expectedImports = ["C", "E", "G", "Swift", "SwiftOnoneSupport"]
// Dependnig on how recent the platform we are running on, the _Concurrency module may or may not be present.
let expectedImports2 = ["C", "E", "G", "Swift", "SwiftOnoneSupport", "_Concurrency"]
Expand Down Expand Up @@ -1414,9 +1414,9 @@ final class ExplicitModuleBuildTests: XCTestCase {
scannerCommand.removeFirst()
}
let _ =
try! dependencyOracle.getDependencies(workingDirectory: path,
commandLine: scannerCommand)
let potentialDiags = try! dependencyOracle.getScannerDiagnostics()
try dependencyOracle.getDependencies(workingDirectory: path,
commandLine: scannerCommand)
let potentialDiags = try dependencyOracle.getScannerDiagnostics()
XCTAssertEqual(potentialDiags?.count, 5)
let diags = try XCTUnwrap(potentialDiags)
let error = diags[0]
Expand Down Expand Up @@ -1748,7 +1748,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
}

let firstScanGraph =
try! firstDependencyOracle.getDependencies(workingDirectory: path,
try firstDependencyOracle.getDependencies(workingDirectory: path,
commandLine: scannerCommand)
firstDependencyOracle.serializeScannerCache(to: cacheSavePath)

Expand All @@ -1762,8 +1762,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
}
XCTAssertFalse(secondDependencyOracle.loadScannerCache(from: cacheSavePath))
let secondScanGraph =
try! secondDependencyOracle.getDependencies(workingDirectory: path,
commandLine: scannerCommand)
try secondDependencyOracle.getDependencies(workingDirectory: path,
commandLine: scannerCommand)

XCTAssertTrue(firstScanGraph.modules.count == secondScanGraph.modules.count)
}
Expand Down
Expand Up @@ -101,7 +101,7 @@ class IncrementalBuildPerformanceTests: XCTestCase {
) throws -> (OutputFileMap, [SwiftSourceFile]) {
let workingDirectory = localFileSystem.currentWorkingDirectory!
let swiftDepsDirPath = try VirtualPath.init(path: swiftDepsDirectory).resolvedRelativePath(base: workingDirectory).absolutePath!
let withoutExtensions: ArraySlice<Substring> = try! localFileSystem.getDirectoryContents(swiftDepsDirPath)
let withoutExtensions: ArraySlice<Substring> = try localFileSystem.getDirectoryContents(swiftDepsDirPath)
.compactMap {
fileName -> Substring? in
guard let suffixRange = fileName.range(of: ".swiftdeps"),
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftDriverTests/IncrementalCompilationTests.swift
Expand Up @@ -151,12 +151,12 @@ extension IncrementalCompilationTests {
env["SWIFT_DRIVER_SWIFT_AUTOLINK_EXTRACT_EXEC"] = "/garbage/swift-autolink-extract"
env["SWIFT_DRIVER_DSYMUTIL_EXEC"] = "/garbage/dsymutil"

var driver = try! Driver(
var driver = try Driver(
args: commonArgs
+ ["-emit-library", "-target", "x86_64-unknown-linux"],
env: env)
let plannedJobs = try! driver.planBuild()
let autolinkExtractJob = try! XCTUnwrap(
let plannedJobs = try driver.planBuild()
let autolinkExtractJob = try XCTUnwrap(
plannedJobs
.filter { $0.kind == .autolinkExtract }
.first)
Expand Down
8 changes: 4 additions & 4 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Expand Up @@ -61,7 +61,7 @@ final class SwiftDriverTests: XCTestCase {
}
}

deinit {
override func tearDown() {
try? localFileSystem.removeFileTree(AbsolutePath(validating: self.ld.dirname))
}

Expand Down Expand Up @@ -1422,7 +1422,7 @@ final class SwiftDriverTests: XCTestCase {
guard let preserveCwd = localFileSystem.currentWorkingDirectory else {
fatalError()
}
try! localFileSystem.changeCurrentWorkingDirectory(to: path)
try localFileSystem.changeCurrentWorkingDirectory(to: path)
defer { try! localFileSystem.changeCurrentWorkingDirectory(to: preserveCwd) }

let diags = DiagnosticsEngine()
Expand Down Expand Up @@ -1451,7 +1451,7 @@ final class SwiftDriverTests: XCTestCase {
guard let preserveCwd = localFileSystem.currentWorkingDirectory else {
fatalError()
}
try! localFileSystem.changeCurrentWorkingDirectory(to: path)
try localFileSystem.changeCurrentWorkingDirectory(to: path)
defer { try! localFileSystem.changeCurrentWorkingDirectory(to: preserveCwd) }

try localFileSystem.createDirectory(path.appending(component: "subdir"))
Expand Down Expand Up @@ -5151,7 +5151,7 @@ final class SwiftDriverTests: XCTestCase {
let root = localFileSystem.currentWorkingDirectory!.appending(components: "build")

let errorOutputFile = path.appending(component: "dummy_error_stream")
TSCBasic.stderrStream = try! ThreadSafeOutputByteStream(LocalFileOutputByteStream(errorOutputFile))
TSCBasic.stderrStream = try ThreadSafeOutputByteStream(LocalFileOutputByteStream(errorOutputFile))

let libObj: AbsolutePath = root.appending(component: "lib.o")
let mainObj: AbsolutePath = root.appending(component: "main.o")
Expand Down