Skip to content

Commit 8546020

Browse files
authored
Make swift test --show-code-cov-path work with swift-testing (#7094)
This PR ensures that the aforementioned option behaves correctly when `--enable-experimental-swift-testing` is passed. As it stands, `--show-code-cov-path` is implemented as a subcommand but behaves like an option; this PR removes the subcommand so that it "just works" without regard for other options. A longer-term solution could be to make it into a proper subcommand (e.g. `swift test show-path code-coverage`.) That would ensure that we would get appropriate output from Swift Argument Parser when mixing it with other (nonsensical) options.
1 parent 9c22c6c commit 8546020

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

Sources/Commands/SwiftTestTool.swift

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ public struct SwiftTestTool: SwiftCommand {
346346
}
347347

348348
if self.options.shouldPrintCodeCovPath {
349-
let command = try PrintCodeCovPath.parse()
350-
try command.run(swiftTool)
349+
try printCodeCovPath(swiftTool)
351350
} else if self.options._deprecated_shouldListTests {
352351
// backward compatibility 6/2022 for deprecation of flag into a subcommand
353352
let command = try List.parse()
@@ -542,36 +541,21 @@ public struct SwiftTestTool: SwiftCommand {
542541
}
543542

544543
extension SwiftTestTool {
545-
struct PrintCodeCovPath: SwiftCommand {
546-
static let configuration = CommandConfiguration(
547-
commandName: "show-codecov-path",
548-
abstract: "Print the path of the exported code coverage JSON file"
549-
)
550-
551-
@OptionGroup(visibility: .hidden)
552-
var globalOptions: GlobalOptions
553-
554-
// for deprecated passthrough from SwiftTestTool (parse will fail otherwise)
555-
556-
@Flag(name: [.customLong("show-codecov-path"), .customLong("show-code-coverage-path"), .customLong("show-coverage-path")], help: .hidden)
557-
var _deprecated_passthrough: Bool = false
558-
559-
func run(_ swiftTool: SwiftTool) throws {
560-
let workspace = try swiftTool.getActiveWorkspace()
561-
let root = try swiftTool.getWorkspaceRoot()
562-
let rootManifests = try temp_await {
563-
workspace.loadRootManifests(
564-
packages: root.packages,
565-
observabilityScope: swiftTool.observabilityScope,
566-
completion: $0
567-
)
568-
}
569-
guard let rootManifest = rootManifests.values.first else {
570-
throw StringError("invalid manifests at \(root.packages)")
571-
}
572-
let buildParameters = try swiftTool.buildParametersForTest(enableCodeCoverage: true, library: .xctest)
573-
print(buildParameters.codeCovAsJSONPath(packageName: rootManifest.displayName))
574-
}
544+
func printCodeCovPath(_ swiftTool: SwiftTool) throws {
545+
let workspace = try swiftTool.getActiveWorkspace()
546+
let root = try swiftTool.getWorkspaceRoot()
547+
let rootManifests = try temp_await {
548+
workspace.loadRootManifests(
549+
packages: root.packages,
550+
observabilityScope: swiftTool.observabilityScope,
551+
completion: $0
552+
)
553+
}
554+
guard let rootManifest = rootManifests.values.first else {
555+
throw StringError("invalid manifests at \(root.packages)")
556+
}
557+
let buildParameters = try swiftTool.buildParametersForTest(enableCodeCoverage: true, library: .xctest)
558+
print(buildParameters.codeCovAsJSONPath(packageName: rootManifest.displayName))
575559
}
576560
}
577561

0 commit comments

Comments
 (0)