Skip to content

Don't stomp on xUnit output from XCTest when running Swift Testing. #7796

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 3 commits into from
Jul 19, 2024
Merged
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
24 changes: 23 additions & 1 deletion Sources/Commands/SwiftTestCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,29 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
// Pass through all arguments from the command line to Swift Testing.
var additionalArguments = additionalArguments
if library == .swiftTesting {
additionalArguments += CommandLine.arguments.dropFirst()
// Reconstruct the arguments list. If an xUnit path was specified, remove it.
var commandLineArguments = [String]()
var originalCommandLineArguments = CommandLine.arguments.dropFirst().makeIterator()
while let arg = originalCommandLineArguments.next() {
if arg == "--xunit-output" {
_ = originalCommandLineArguments.next()
} else {
commandLineArguments.append(arg)
}
}
additionalArguments += commandLineArguments

if var xunitPath = options.xUnitOutput, options.testLibraryOptions.isEnabled(.xctest) {
// We are running Swift Testing, XCTest is also running in this session, and an xUnit path
// was specified. Make sure we don't stomp on XCTest's XML output by having Swift Testing
// write to a different path.
var xunitFileName = "\(xunitPath.basenameWithoutExt)-swift-testing"
if let ext = xunitPath.extension {
xunitFileName = "\(xunitFileName).\(ext)"
}
xunitPath = xunitPath.parentDirectory.appending(xunitFileName)
additionalArguments += ["--xunit-output", xunitPath.pathString]
}
}

let toolchain = try swiftCommandState.getTargetToolchain()
Expand Down