Skip to content

Conversation

@briancroom
Copy link
Contributor

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:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

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.
@briancroom
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@grynspan grynspan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicks only.

let testSkipped = expectation(description: "Test was skipped")
var configuration = Configuration()
configuration.eventHandler = { event, _ in
if case .testSkipped(_) = event.kind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if case .testSkipped(_) = event.kind {
if case .testSkipped = event.kind {

}

// If the test is parameterized but has no cases, mark it as skipped.
if case .run = action, test.isParameterized, test.testCases?.lazy.first(where: { _ in true }) == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if case .run = action, test.isParameterized, test.testCases?.lazy.first(where: { _ in true }) == nil {
if case .run = action, test.isParameterized, test.testCases?.first(where: { _ in true }) == nil {

@briancroom
Copy link
Contributor Author

@swift-ci please test

}

// If the test is parameterized but has no cases, mark it as skipped.
if case .run = action, test.isParameterized, test.testCases?.first(where: { _ in true }) == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also express this as:

      if case .run = action, let testCases = test.testCases, testCases.first(where: { _ in true }) == nil {

Which might be slightly more efficient.

@briancroom
Copy link
Contributor Author

@swift-ci please test

@briancroom briancroom requested a review from grynspan July 24, 2024 14:39
@grynspan
Copy link
Contributor

Merging on Brian's behalf.

@grynspan grynspan merged commit c314907 into main Jul 24, 2024
@grynspan grynspan deleted the bcroom/skip-empty-parameterized-test branch July 24, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants