Skip to content

Commit 10d2098

Browse files
authored
Don't stomp on xUnit output from XCTest when running Swift Testing. (swiftlang#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 ee95ea8 commit 10d2098

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Sources/Commands/SwiftTestCommand.swift

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

460482
let toolchain = try swiftCommandState.getTargetToolchain()

0 commit comments

Comments
 (0)