Skip to content

Commit 2e89e0c

Browse files
committed
Implement swift test list for swift-testing
1 parent 8538197 commit 2e89e0c

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

Sources/Commands/SwiftTestTool.swift

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ extension SwiftTestTool {
615615
// MARK: - XCTest
616616

617617
private func xctestRun(_ swiftTool: SwiftTool) throws {
618-
let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool, library: .xctest)
618+
let buildParameters = try swiftTool.buildParametersForTest(enableCodeCoverage: false, shouldSkipBuilding: sharedOptions.shouldSkipBuilding, library: .xctest)
619+
let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool, buildParameters: buildParameters)
619620
let testSuites = try TestingSupport.getTestSuites(
620621
in: testProducts,
621622
swiftTool: swiftTool,
@@ -634,7 +635,35 @@ extension SwiftTestTool {
634635
// MARK: - swift-testing
635636

636637
private func swiftTestingRun(_ swiftTool: SwiftTool) throws {
637-
throw StringError("swift test list is not yet implemented for swift-testing")
638+
let buildParameters = try swiftTool.buildParametersForTest(enableCodeCoverage: false, shouldSkipBuilding: sharedOptions.shouldSkipBuilding, library: .swiftTesting)
639+
let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool, buildParameters: buildParameters)
640+
641+
let toolchain = try swiftTool.getTargetToolchain()
642+
let testEnv = try TestingSupport.constructTestEnvironment(
643+
toolchain: toolchain,
644+
buildParameters: buildParameters,
645+
sanitizers: globalOptions.build.sanitizers
646+
)
647+
648+
let runner = TestRunner(
649+
bundlePaths: testProducts.map(\.binaryPath),
650+
additionalArguments: ["--list-tests"],
651+
cancellator: swiftTool.cancellator,
652+
toolchain: toolchain,
653+
testEnv: testEnv,
654+
observabilityScope: swiftTool.observabilityScope,
655+
library: .swiftTesting
656+
)
657+
658+
// Finally, run the tests.
659+
let ranSuccessfully = runner.test(outputHandler: {
660+
// command's result output goes on stdout
661+
// ie "swift test" should output to stdout
662+
print($0)
663+
})
664+
if !ranSuccessfully {
665+
swiftTool.executionStatus = .failure
666+
}
638667
}
639668

640669
// MARK: - Common implementation
@@ -648,8 +677,7 @@ extension SwiftTestTool {
648677
}
649678
}
650679

651-
private func buildTestsIfNeeded(swiftTool: SwiftTool, library: BuildParameters.Testing.Library) throws -> [BuiltTestProduct] {
652-
let buildParameters = try swiftTool.buildParametersForTest(enableCodeCoverage: false, shouldSkipBuilding: sharedOptions.shouldSkipBuilding, library: library)
680+
private func buildTestsIfNeeded(swiftTool: SwiftTool, buildParameters: BuildParameters) throws -> [BuiltTestProduct] {
653681
return try Commands.buildTestsIfNeeded(swiftTool: swiftTool, buildParameters: buildParameters, testProduct: self.sharedOptions.testProduct)
654682
}
655683
}

0 commit comments

Comments
 (0)