Skip to content

Commit 686f176

Browse files
committed
Don't stomp on xUnit output from XCTest when running Swift Testing. (#7796)
This PR forces Swift Testing to write its xUnit output to a different path from what the user specifies. In the future, we should have the two testing libraries collate their XML output into a single file, but that requires the ability to parse and reformat XML output and that's a little beyond the capabilities of this feature right now. Since we expect most uses of xUnit output right now are existing ones with existing XCTest-based tests, moving Swift Testing aside seems like the right call. (If XCTest is explicitly disabled, the exact specified path is used.)
1 parent 081cb28 commit 686f176

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Sources/Commands/SwiftTestCommand.swift

+23-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,29 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
452452
// Pass through all arguments from the command line to Swift Testing.
453453
var additionalArguments = additionalArguments
454454
if library == .swiftTesting {
455-
additionalArguments += CommandLine.arguments.dropFirst()
455+
// Reconstruct the arguments list. If an xUnit path was specified, remove it.
456+
var commandLineArguments = [String]()
457+
var originalCommandLineArguments = CommandLine.arguments.dropFirst().makeIterator()
458+
while let arg = originalCommandLineArguments.next() {
459+
if arg == "--xunit-output" {
460+
_ = originalCommandLineArguments.next()
461+
} else {
462+
commandLineArguments.append(arg)
463+
}
464+
}
465+
additionalArguments += commandLineArguments
466+
467+
if var xunitPath = options.xUnitOutput, options.testLibraryOptions.isEnabled(.xctest) {
468+
// We are running Swift Testing, XCTest is also running in this session, and an xUnit path
469+
// was specified. Make sure we don't stomp on XCTest's XML output by having Swift Testing
470+
// write to a different path.
471+
var xunitFileName = "\(xunitPath.basenameWithoutExt)-swift-testing"
472+
if let ext = xunitPath.extension {
473+
xunitFileName = "\(xunitFileName).\(ext)"
474+
}
475+
xunitPath = xunitPath.parentDirectory.appending(xunitFileName)
476+
additionalArguments += ["--xunit-output", xunitPath.pathString]
477+
}
456478
}
457479

458480
let toolchain = try swiftCommandState.getTargetToolchain()

0 commit comments

Comments
 (0)