Skip to content

Commit 03f3539

Browse files
Merge pull request #1434 from cachemeifyoucan/eng/swift-driver-tests-fatal-errors
Improve swift-driver test cases to avoid fatal crash
2 parents 1444a8b + feeec17 commit 03f3539

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,9 @@ final class ExplicitModuleBuildTests: XCTestCase {
932932
main.nativePathString(escaped: true)] + sdkArgumentsForTesting
933933

934934
let deps =
935-
try! dependencyOracle.getImports(workingDirectory: path,
936-
moduleAliases: ["Car": "Bar"],
937-
commandLine: scannerCommand)
935+
try dependencyOracle.getImports(workingDirectory: path,
936+
moduleAliases: ["Car": "Bar"],
937+
commandLine: scannerCommand)
938938

939939
XCTAssertTrue(deps.imports.contains("Bar"))
940940
XCTAssertFalse(deps.imports.contains("Car"))
@@ -1192,8 +1192,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
11921192
scannerCommand.removeFirst()
11931193
}
11941194
let dependencyGraph =
1195-
try! dependencyOracle.getDependencies(workingDirectory: path,
1196-
commandLine: scannerCommand)
1195+
try dependencyOracle.getDependencies(workingDirectory: path,
1196+
commandLine: scannerCommand)
11971197

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

13011301
let imports =
1302-
try! dependencyOracle.getImports(workingDirectory: path,
1303-
commandLine: scannerCommand)
1302+
try dependencyOracle.getImports(workingDirectory: path,
1303+
commandLine: scannerCommand)
13041304
let expectedImports = ["C", "E", "G", "Swift", "SwiftOnoneSupport"]
13051305
// Dependnig on how recent the platform we are running on, the _Concurrency module may or may not be present.
13061306
let expectedImports2 = ["C", "E", "G", "Swift", "SwiftOnoneSupport", "_Concurrency"]
@@ -1414,9 +1414,9 @@ final class ExplicitModuleBuildTests: XCTestCase {
14141414
scannerCommand.removeFirst()
14151415
}
14161416
let _ =
1417-
try! dependencyOracle.getDependencies(workingDirectory: path,
1418-
commandLine: scannerCommand)
1419-
let potentialDiags = try! dependencyOracle.getScannerDiagnostics()
1417+
try dependencyOracle.getDependencies(workingDirectory: path,
1418+
commandLine: scannerCommand)
1419+
let potentialDiags = try dependencyOracle.getScannerDiagnostics()
14201420
XCTAssertEqual(potentialDiags?.count, 5)
14211421
let diags = try XCTUnwrap(potentialDiags)
14221422
let error = diags[0]
@@ -1748,7 +1748,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
17481748
}
17491749

17501750
let firstScanGraph =
1751-
try! firstDependencyOracle.getDependencies(workingDirectory: path,
1751+
try firstDependencyOracle.getDependencies(workingDirectory: path,
17521752
commandLine: scannerCommand)
17531753
firstDependencyOracle.serializeScannerCache(to: cacheSavePath)
17541754

@@ -1762,8 +1762,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
17621762
}
17631763
XCTAssertFalse(secondDependencyOracle.loadScannerCache(from: cacheSavePath))
17641764
let secondScanGraph =
1765-
try! secondDependencyOracle.getDependencies(workingDirectory: path,
1766-
commandLine: scannerCommand)
1765+
try secondDependencyOracle.getDependencies(workingDirectory: path,
1766+
commandLine: scannerCommand)
17671767

17681768
XCTAssertTrue(firstScanGraph.modules.count == secondScanGraph.modules.count)
17691769
}

Tests/SwiftDriverTests/IncrementalBuildPerformanceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class IncrementalBuildPerformanceTests: XCTestCase {
101101
) throws -> (OutputFileMap, [SwiftSourceFile]) {
102102
let workingDirectory = localFileSystem.currentWorkingDirectory!
103103
let swiftDepsDirPath = try VirtualPath.init(path: swiftDepsDirectory).resolvedRelativePath(base: workingDirectory).absolutePath!
104-
let withoutExtensions: ArraySlice<Substring> = try! localFileSystem.getDirectoryContents(swiftDepsDirPath)
104+
let withoutExtensions: ArraySlice<Substring> = try localFileSystem.getDirectoryContents(swiftDepsDirPath)
105105
.compactMap {
106106
fileName -> Substring? in
107107
guard let suffixRange = fileName.range(of: ".swiftdeps"),

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ extension IncrementalCompilationTests {
151151
env["SWIFT_DRIVER_SWIFT_AUTOLINK_EXTRACT_EXEC"] = "/garbage/swift-autolink-extract"
152152
env["SWIFT_DRIVER_DSYMUTIL_EXEC"] = "/garbage/dsymutil"
153153

154-
var driver = try! Driver(
154+
var driver = try Driver(
155155
args: commonArgs
156156
+ ["-emit-library", "-target", "x86_64-unknown-linux"],
157157
env: env)
158-
let plannedJobs = try! driver.planBuild()
159-
let autolinkExtractJob = try! XCTUnwrap(
158+
let plannedJobs = try driver.planBuild()
159+
let autolinkExtractJob = try XCTUnwrap(
160160
plannedJobs
161161
.filter { $0.kind == .autolinkExtract }
162162
.first)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ final class SwiftDriverTests: XCTestCase {
6161
}
6262
}
6363

64-
deinit {
64+
override func tearDown() {
6565
try? localFileSystem.removeFileTree(AbsolutePath(validating: self.ld.dirname))
6666
}
6767

@@ -1422,7 +1422,7 @@ final class SwiftDriverTests: XCTestCase {
14221422
guard let preserveCwd = localFileSystem.currentWorkingDirectory else {
14231423
fatalError()
14241424
}
1425-
try! localFileSystem.changeCurrentWorkingDirectory(to: path)
1425+
try localFileSystem.changeCurrentWorkingDirectory(to: path)
14261426
defer { try! localFileSystem.changeCurrentWorkingDirectory(to: preserveCwd) }
14271427

14281428
let diags = DiagnosticsEngine()
@@ -1451,7 +1451,7 @@ final class SwiftDriverTests: XCTestCase {
14511451
guard let preserveCwd = localFileSystem.currentWorkingDirectory else {
14521452
fatalError()
14531453
}
1454-
try! localFileSystem.changeCurrentWorkingDirectory(to: path)
1454+
try localFileSystem.changeCurrentWorkingDirectory(to: path)
14551455
defer { try! localFileSystem.changeCurrentWorkingDirectory(to: preserveCwd) }
14561456

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

51535153
let errorOutputFile = path.appending(component: "dummy_error_stream")
5154-
TSCBasic.stderrStream = try! ThreadSafeOutputByteStream(LocalFileOutputByteStream(errorOutputFile))
5154+
TSCBasic.stderrStream = try ThreadSafeOutputByteStream(LocalFileOutputByteStream(errorOutputFile))
51555155

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

0 commit comments

Comments
 (0)