Skip to content

Commit

Permalink
Merge pull request #1434 from cachemeifyoucan/eng/swift-driver-tests-…
Browse files Browse the repository at this point in the history
…fatal-errors

Improve swift-driver test cases to avoid fatal crash
  • Loading branch information
cachemeifyoucan authored Sep 6, 2023
2 parents 1444a8b + feeec17 commit 03f3539
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
26 changes: 13 additions & 13 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 03f3539

Please sign in to comment.