Skip to content

Add a property to Test.Case to get the values of its arguments. - #1350

Open
grynspan wants to merge 3 commits into
mainfrom
jgrynspan/arguments-property
Open

grynspan wants to merge 3 commits into
mainfrom
jgrynspan/arguments-property

Conversation

@grynspan

@grynspan grynspan commented Oct 3, 2025 •

Copy link
Copy Markdown
Contributor

This PR adds an experimental property to Test.Case to allow callers to get the test case's arguments as a type-erased array. For example:

if let testCase = Test.Case.current {
  for value in testCase.argumentValues {
    print("\(value): \(type(of: value))")
  }
}

We already have an arguments property of a type that we do not intend to make API, so the new property is named argumentValues pending any SPI renaming.

Resolves #1889.

Checklist:

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

This PR adds an experimental property to `Test.Case` to allow callers to get the
test case's arguments as a type-erased array. For example:

```swift
if let testCase = Test.Case.current {
  for value in testCase.argumentValues {
    print("\(value): \(type(of: value))")
  }
}
```

We already have an `arguments` property of a type that we do not intend to make
API, so the new property is named `argumentValues` pending any of SPI renaming.
@grynspan grynspan added this to the Swift 6.x (main) milestone Oct 3, 2025
@grynspan grynspan self-assigned this Oct 3, 2025
@grynspan grynspan added enhancement New feature or request public-api Affects public API traits Issues and PRs related to the trait subsystem or built-in traits parameterized-testing Related to parameterized testing functionality labels Oct 3, 2025
@stmontgomery

Copy link
Copy Markdown
Contributor

I know this is just an SPI at the moment but assuming the intention is to advance it to a public API, I'm interested in discussing the merits of exposing just this one property vs. exposing the backing Test.Case.Argument type and an array of argument instances. Having a richer type to represent an argument could have some advantages worth weighing.

Of course, nothing prevents us from pursuing both; they could complement each other. Said a different way, I'm not certain yet whether I agree with this statement from the PR description (emphasis mine):

We already have an arguments property of a type that we do not intend to make API, so the new property is named argumentValues pending any SPI renaming.

I think we should consider both ideas, and that could take place during an API pitch thread.

@grynspan

Copy link
Copy Markdown
Contributor Author

I think we should consider both ideas, and that could take place during an API pitch thread.

The comment is more to the point that I couldn't go and name the new property arguments because it'd break against the existing property, and any renaming would need discussion. So I think you're just agreeing with me. :)

@grynspan

Copy link
Copy Markdown
Contributor Author

In any event I'm also fine leaving this specific PR on the table. I think there's value in allowing these values to be accessible but I don't feel too strongly about the precise shape of the API we would add.

Fortunately the values are all constrained to Sendable & Copyable so we can do this without hurting ourselves too much.

@grynspan
grynspan requested a review from stmontgomery November 1, 2026 00:23
@grynspan

grynspan commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Reviving this PR as Span and the new Iterable protocol will allow us to support ~Copyable arguments in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request parameterized-testing Related to parameterized testing functionality public-api Affects public API traits Issues and PRs related to the trait subsystem or built-in traits

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose Test.Case.arguments as public API in Swift Testing

3 participants