Skip to content

Commit c314907

Browse files
authored
Report a skipped event for parameterized tests with no cases (#572)
When a parameterized test's argument list is empty, a "skip" event is a better reflection of the fact that the test function doesn't actually get executed. With this change, a `.testSkipped` event will get posted for such tests, instead of a `.testStarted` + `.testEnded` event pair. This also means that the following tests will be reported very similarly (with just a different comment on the `SkipInfo`): ``` @test(arguments: Array<Int>()) func t1(x: Int) {} @test(.disabled(), arguments: [1]) func t2(x: Int) {} ``` ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent d2dfc3f commit c314907

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Sources/Testing/Running/Runner.Plan.swift

+5
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ extension Runner.Plan {
263263
}
264264
}
265265

266+
// If the test is parameterized but has no cases, mark it as skipped.
267+
if case .run = action, let testCases = test.testCases, testCases.first(where: { _ in true }) == nil {
268+
action = .skip(SkipInfo(comment: "No test cases found."))
269+
}
270+
266271
actionGraph.updateValue(action, at: keyPath)
267272

268273
return test

Tests/TestingTests/RunnerTests.swift

+18
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ final class RunnerTests: XCTestCase {
201201
await fulfillment(of: [testSkipped], timeout: 0.0)
202202
}
203203

204+
func testParameterizedTestWithNoCasesIsSkipped() async throws {
205+
let testSkipped = expectation(description: "Test was skipped")
206+
var configuration = Configuration()
207+
configuration.eventHandler = { event, _ in
208+
if case .testSkipped = event.kind {
209+
testSkipped.fulfill()
210+
}
211+
if case .testStarted = event.kind {
212+
XCTFail("The test should not be reported as started.")
213+
}
214+
}
215+
let runner = await Runner(testing: [
216+
Test(arguments: Array<Int>(), parameters: [.init(index: 0, firstName: "i", type: Int.self)]) { _ in },
217+
], configuration: configuration)
218+
await runner.run()
219+
await fulfillment(of: [testSkipped], timeout: 0.0)
220+
}
221+
204222
func testTestIsSkippedWithBlockingEnabledIfTrait() async throws {
205223
let testSkipped = expectation(description: "Test was skipped")
206224
testSkipped.expectedFulfillmentCount = 4

0 commit comments

Comments
 (0)