Skip to content

Commit 9227fd6

Browse files
committed
Add utility to check if LLDB is present, to skip tests that rely on LLDB
The driver very well may be built and tested in environments that do not have LLDB. We should skip tests that rely on LLDB being present in such environments.
1 parent b1b6f06 commit 9227fd6

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ import XCTest
1818

1919
final class SwiftDriverTests: XCTestCase {
2020

21+
/// Determine if the test's execution environment has LLDB
22+
/// Used to skip tests that rely on LLDB in such environments.
23+
private func testEnvHasLLDB() throws -> Bool {
24+
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(),
25+
processSet: ProcessSet(),
26+
fileSystem: localFileSystem,
27+
env: ProcessEnv.vars)
28+
let toolchain: Toolchain
29+
#if os(macOS)
30+
toolchain = DarwinToolchain(env: ProcessEnv.vars, executor: executor)
31+
#else
32+
toolchain = GenericUnixToolchain(env: ProcessEnv.vars, executor: executor)
33+
#endif
34+
do {
35+
_ = try toolchain.getToolPath(.lldb)
36+
} catch ToolchainError.unableToFind {
37+
return false
38+
}
39+
return true
40+
}
41+
2142
func testInvocationRunModes() throws {
2243

2344
let driver1 = try Driver.invocationRunMode(forArgs: ["swift"])
@@ -1631,20 +1652,8 @@ final class SwiftDriverTests: XCTestCase {
16311652

16321653
func testRepl() throws {
16331654
// Do not run this test if no LLDB is found in the toolchain.
1634-
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(),
1635-
processSet: ProcessSet(),
1636-
fileSystem: localFileSystem,
1637-
env: ProcessEnv.vars)
1638-
var toolchain: Toolchain
1639-
#if os(macOS)
1640-
toolchain = DarwinToolchain(env: ProcessEnv.vars, executor: executor)
1641-
#else
1642-
toolchain = GenericUnixToolchain(env: ProcessEnv.vars, executor: executor)
1643-
#endif
1644-
do {
1645-
_ = try toolchain.getToolPath(.lldb)
1646-
} catch ToolchainError.unableToFind {
1647-
return
1655+
if try !testEnvHasLLDB() {
1656+
throw XCTSkip()
16481657
}
16491658

16501659
func isLLDBREPLFlag(_ arg: Job.ArgTemplate) -> Bool {
@@ -2618,9 +2627,12 @@ final class SwiftDriverTests: XCTestCase {
26182627
}
26192628

26202629
func testNoInputs() throws {
2621-
do {
2622-
var driver = try Driver(args: ["swift"])
2623-
XCTAssertNoThrow(try driver.planBuild())
2630+
// A plain `swift` invocation requires lldb to be present
2631+
if try testEnvHasLLDB() {
2632+
do {
2633+
var driver = try Driver(args: ["swift"])
2634+
XCTAssertNoThrow(try driver.planBuild())
2635+
}
26242636
}
26252637
do {
26262638
var driver = try Driver(args: ["swiftc"])

0 commit comments

Comments
 (0)