Skip to content

Revert "Avoid using temp_await in SwiftTestTool.swift" #7196

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

Merged
merged 1 commit into from
Dec 13, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 28 additions & 46 deletions Sources/Commands/SwiftTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public enum TestOutput: String, ExpressibleByArgument {
}

/// swift-test tool namespace
public struct SwiftTestTool: AsyncSwiftCommand {
public struct SwiftTestTool: SwiftCommand {
public static var configuration = CommandConfiguration(
commandName: "test",
_superCommandName: "swift",
Expand All @@ -206,7 +206,7 @@ public struct SwiftTestTool: AsyncSwiftCommand {

// MARK: - XCTest

private func xctestRun(_ swiftTool: SwiftTool) async throws {
private func xctestRun(_ swiftTool: SwiftTool) throws {
// validate XCTest available on darwin based systems
let toolchain = try swiftTool.getTargetToolchain()
let isHostTestingAvailable = try swiftTool.getHostToolchain().swiftSDK.supportsTesting
Expand All @@ -224,13 +224,7 @@ public struct SwiftTestTool: AsyncSwiftCommand {
let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool, library: .xctest)
if !self.options.shouldRunInParallel {
let xctestArgs = try xctestArgs(for: testProducts, swiftTool: swiftTool)
try await runTestProducts(
testProducts,
additionalArguments: xctestArgs,
buildParameters: buildParameters,
swiftTool: swiftTool,
library: .xctest
)
try runTestProducts(testProducts, additionalArguments: xctestArgs, buildParameters: buildParameters, swiftTool: swiftTool, library: .xctest)
} else {
let testSuites = try TestingSupport.getTestSuites(
in: testProducts,
Expand Down Expand Up @@ -275,7 +269,7 @@ public struct SwiftTestTool: AsyncSwiftCommand {

// process code Coverage if request
if self.options.enableCodeCoverage, runner.ranSuccessfully {
try await processCodeCoverage(testProducts, swiftTool: swiftTool, library: .xctest)
try processCodeCoverage(testProducts, swiftTool: swiftTool, library: .xctest)
}

if !runner.ranSuccessfully {
Expand Down Expand Up @@ -340,22 +334,16 @@ public struct SwiftTestTool: AsyncSwiftCommand {

// MARK: - swift-testing

private func swiftTestingRun(_ swiftTool: SwiftTool) async throws {
private func swiftTestingRun(_ swiftTool: SwiftTool) throws {
let buildParameters = try swiftTool.buildParametersForTest(options: self.options, library: .swiftTesting)
let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool, library: .swiftTesting)
let additionalArguments = Array(CommandLine.arguments.dropFirst())
try await runTestProducts(
testProducts,
additionalArguments: additionalArguments,
buildParameters: buildParameters,
swiftTool: swiftTool,
library: .swiftTesting
)
try runTestProducts(testProducts, additionalArguments: additionalArguments, buildParameters: buildParameters, swiftTool: swiftTool, library: .swiftTesting)
}

// MARK: - Common implementation

public func run(_ swiftTool: SwiftTool) async throws {
public func run(_ swiftTool: SwiftTool) throws {
do {
// Validate commands arguments
try self.validateArguments(observabilityScope: swiftTool.observabilityScope)
Expand All @@ -365,28 +353,22 @@ public struct SwiftTestTool: AsyncSwiftCommand {
}

if self.options.shouldPrintCodeCovPath {
try await printCodeCovPath(swiftTool)
try printCodeCovPath(swiftTool)
} else if self.options._deprecated_shouldListTests {
// backward compatibility 6/2022 for deprecation of flag into a subcommand
let command = try List.parse()
try command.run(swiftTool)
} else {
if options.sharedOptions.enableSwiftTestingLibrarySupport {
try await swiftTestingRun(swiftTool)
try swiftTestingRun(swiftTool)
}
if options.sharedOptions.enableXCTestSupport {
try await xctestRun(swiftTool)
try xctestRun(swiftTool)
}
}
}

private func runTestProducts(
_ testProducts: [BuiltTestProduct],
additionalArguments: [String],
buildParameters: BuildParameters,
swiftTool: SwiftTool,
library: BuildParameters.Testing.Library
) async throws {
private func runTestProducts(_ testProducts: [BuiltTestProduct], additionalArguments: [String], buildParameters: BuildParameters, swiftTool: SwiftTool, library: BuildParameters.Testing.Library) throws {
// Clean out the code coverage directory that may contain stale
// profraw files from a previous run of the code coverage tool.
if self.options.enableCodeCoverage {
Expand Down Expand Up @@ -421,7 +403,7 @@ public struct SwiftTestTool: AsyncSwiftCommand {
}

if self.options.enableCodeCoverage, ranSuccessfully {
try await processCodeCoverage(testProducts, swiftTool: swiftTool, library: library)
try processCodeCoverage(testProducts, swiftTool: swiftTool, library: library)
}

if self.options.enableExperimentalTestOutput, !ranSuccessfully {
Expand Down Expand Up @@ -461,18 +443,16 @@ public struct SwiftTestTool: AsyncSwiftCommand {
}

/// Processes the code coverage data and emits a json.
private func processCodeCoverage(
_ testProducts: [BuiltTestProduct],
swiftTool: SwiftTool,
library: BuildParameters.Testing.Library
) async throws {
private func processCodeCoverage(_ testProducts: [BuiltTestProduct], swiftTool: SwiftTool, library: BuildParameters.Testing.Library) throws {
let workspace = try swiftTool.getActiveWorkspace()
let root = try swiftTool.getWorkspaceRoot()
let rootManifests = try await workspace.loadRootManifests(
packages: root.packages,
observabilityScope: swiftTool.observabilityScope
)

let rootManifests = try temp_await {
workspace.loadRootManifests(
packages: root.packages,
observabilityScope: swiftTool.observabilityScope,
completion: $0
)
}
guard let rootManifest = rootManifests.values.first else {
throw StringError("invalid manifests at \(root.packages)")
}
Expand Down Expand Up @@ -568,14 +548,16 @@ public struct SwiftTestTool: AsyncSwiftCommand {
}

extension SwiftTestTool {
func printCodeCovPath(_ swiftTool: SwiftTool) async throws {
func printCodeCovPath(_ swiftTool: SwiftTool) throws {
let workspace = try swiftTool.getActiveWorkspace()
let root = try swiftTool.getWorkspaceRoot()
let rootManifests = try await workspace.loadRootManifests(
packages: root.packages,
observabilityScope: swiftTool.observabilityScope
)

let rootManifests = try temp_await {
workspace.loadRootManifests(
packages: root.packages,
observabilityScope: swiftTool.observabilityScope,
completion: $0
)
}
guard let rootManifest = rootManifests.values.first else {
throw StringError("invalid manifests at \(root.packages)")
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-package-manager/SwiftPM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct SwiftPM {
case "swift-experimental-sdk":
await SwiftSDKTool.main()
case "swift-test":
await SwiftTestTool.main()
SwiftTestTool.main()
case "swift-run":
SwiftRunTool.main()
case "swift-package-collection":
Expand Down
5 changes: 1 addition & 4 deletions Sources/swift-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_executable(swift-test
Entrypoint.swift)
main.swift)
target_link_libraries(swift-test PRIVATE
Commands)

target_compile_options(swift-test PRIVATE
-parse-as-library)

install(TARGETS swift-test
RUNTIME DESTINATION bin)
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@

import Commands

@main
struct Entrypoint {
static func main() async {
await SwiftTestTool.main()
}
}
SwiftTestTool.main()