Skip to content
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
4 changes: 4 additions & 0 deletions Fixtures/Miscellaneous/EmptyTestsPkg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
14 changes: 14 additions & 0 deletions Fixtures/Miscellaneous/EmptyTestsPkg/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version:4.2
import PackageDescription

let package = Package(
name: "EmptyTestsPkg",
targets: [
.target(
name: "EmptyTestsPkg",
dependencies: []),
.testTarget(
name: "EmptyTestsPkgTests",
dependencies: ["EmptyTestsPkg"]),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct EmptyTests {

var text = "Hello, World!"
var bool = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import XCTest
@testable import EmptyTestsPkg
23 changes: 15 additions & 8 deletions Sources/Commands/SwiftTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public struct SwiftTestTool: SwiftCommand {
// If there were no matches, emit a warning and exit.
if tests.isEmpty {
swiftTool.observabilityScope.emit(.noMatchingTests)
try generateXUnitOutputIfRequested(for: [], swiftTool: swiftTool)
return
}

Expand All @@ -264,14 +265,7 @@ public struct SwiftTestTool: SwiftCommand {

let testResults = try runner.run(tests)

// Generate xUnit file if requested
if let xUnitOutput = options.xUnitOutput {
let generator = XUnitGenerator(
fileSystem: swiftTool.fileSystem,
results: testResults
)
try generator.generate(at: xUnitOutput)
}
try generateXUnitOutputIfRequested(for: testResults, swiftTool: swiftTool)

// process code Coverage if request
if self.options.enableCodeCoverage, runner.ranSuccessfully {
Expand Down Expand Up @@ -325,6 +319,19 @@ public struct SwiftTestTool: SwiftCommand {
}
}

/// Generate xUnit file if requested.
private func generateXUnitOutputIfRequested(for testResults: [ParallelTestRunner.TestResult], swiftTool: SwiftTool) throws {
guard let xUnitOutput = options.xUnitOutput else {
return
}

let generator = XUnitGenerator(
fileSystem: swiftTool.fileSystem,
results: testResults
)
try generator.generate(at: xUnitOutput)
}

// MARK: - swift-testing

private func swiftTestingRun(_ swiftTool: SwiftTool) throws {
Expand Down
16 changes: 16 additions & 0 deletions Tests/CommandsTests/TestToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ final class TestToolTests: CommandsTestCase {
}
}

func testSwiftTestXMLOutputWhenEmpty() throws {
try fixture(name: "Miscellaneous/EmptyTestsPkg") { fixturePath in
let xUnitOutput = fixturePath.appending("result.xml")
// Run tests in parallel with verbose output.
let stdout = try SwiftPM.Test.execute(["--parallel", "--verbose", "--xunit-output", xUnitOutput.pathString], packagePath: fixturePath).stdout
// in "swift test" test output goes to stdout
XCTAssertNoMatch(stdout, .contains("passed"))
XCTAssertNoMatch(stdout, .contains("failed"))

// Check the xUnit output.
XCTAssertFileExists(xUnitOutput)
let contents: String = try localFileSystem.readFileContents(xUnitOutput)
XCTAssertMatch(contents, .contains("tests=\"0\" failures=\"0\""))
}
}

func testSwiftTestFilter() throws {
try fixture(name: "Miscellaneous/SkipTests") { fixturePath in
let (stdout, _) = try SwiftPM.Test.execute(["--filter", ".*1"], packagePath: fixturePath)
Expand Down