Skip to content

Commit 947392e

Browse files
authored
Don't log "no matching tests" diagnostic when running XCTest only. (#7803)
Fixes a logic error in deciding when to log the "no matching test cases were run" diagnostic if `--disable-swift-testing` is passed.
1 parent 43fd240 commit 947392e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Sources/Commands/SwiftTestCommand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
278278
swiftCommandState: swiftCommandState,
279279
library: .xctest
280280
)
281-
if result == .success && testCount == 0 {
281+
if result == .success, let testCount, testCount == 0 {
282282
results.append(.noMatchingTests)
283283
} else {
284284
results.append(result)
@@ -359,13 +359,13 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
359359
}
360360
}
361361

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

371371
case .regex, .specific, .skip:

Tests/CommandsTests/TestCommandTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,11 @@ final class TestCommandTests: CommandsTestCase {
317317
await XCTAssertAsyncNoThrow(try await SwiftPM.Test.execute(packagePath: fixturePath))
318318
}
319319
}
320+
321+
func testXCTestOnlyDoesNotLogAboutNoMatchingTests() async throws {
322+
try await fixture(name: "Miscellaneous/TestDiscovery/Simple") { fixturePath in
323+
let (_, stderr) = try await SwiftPM.Test.execute(["--disable-swift-testing"], packagePath: fixturePath)
324+
XCTAssertNoMatch(stderr, .contains("No matching test cases were run"))
325+
}
326+
}
320327
}

0 commit comments

Comments
 (0)