Skip to content

Commit 2cd7852

Browse files
authored
[6.0] Don't log "no matching tests" diagnostic when running XCTest only. (#7804)
**Explanation:** Fixes a logic error in deciding when to log the "no matching test cases were run" diagnostic if `--disable-swift-testing` is passed. **Scope:** Bug fix in `swift test`. **Issue:** N/A (noticed locally, opened PR) **Original PR:** #7803 **Risk:** Low **Testing:** Added unit test. **Reviewer:** @MaxDesiatov @bnbarham
1 parent 547f649 commit 2cd7852

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Sources/Commands/SwiftTestCommand.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
276276
swiftCommandState: swiftCommandState,
277277
library: .xctest
278278
)
279-
if result == .success && testCount == 0 {
279+
if result == .success, let testCount, testCount == 0 {
280280
results.append(.noMatchingTests)
281281
} else {
282282
results.append(result)
@@ -357,13 +357,13 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
357357
}
358358
}
359359

360-
private func xctestArgs(for testProducts: [BuiltTestProduct], swiftCommandState: SwiftCommandState) throws -> (arguments: [String], testCount: Int) {
360+
private func xctestArgs(for testProducts: [BuiltTestProduct], swiftCommandState: SwiftCommandState) throws -> (arguments: [String], testCount: Int?) {
361361
switch options.testCaseSpecifier {
362362
case .none:
363363
if case .skip = options.skippedTests(fileSystem: swiftCommandState.fileSystem) {
364364
fallthrough
365365
} else {
366-
return ([], 0)
366+
return ([], nil)
367367
}
368368

369369
case .regex, .specific, .skip:

Tests/CommandsTests/TestCommandTests.swift

+7
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,11 @@ final class TestCommandTests: CommandsTestCase {
307307
await XCTAssertAsyncNoThrow(try await SwiftPM.Test.execute(packagePath: fixturePath))
308308
}
309309
}
310+
311+
func testXCTestOnlyDoesNotLogAboutNoMatchingTests() async throws {
312+
try await fixture(name: "Miscellaneous/TestDiscovery/Simple") { fixturePath in
313+
let (_, stderr) = try await SwiftPM.Test.execute(["--disable-swift-testing"], packagePath: fixturePath)
314+
XCTAssertNoMatch(stderr, .contains("No matching test cases were run"))
315+
}
316+
}
310317
}

0 commit comments

Comments
 (0)