New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support throwing errors from within @Test
attributes
#166
Comments
The Does that help at all? |
I didn't know that - great!
Wouldn't it be easy to allow
we could write
I have not spent any time with macros in Swift, so there may be a limitation I am not aware of. |
It is not hard to allow the developer to express A failure to generate an arguments collection for a test means we cannot fully instantiate that test as specified by the developer. We've been leaning toward saying that we should instead instantiate a monomorphic
This would not be grammatically correct Swift, so you'd have to write something like |
@Test
attributes
Ok, that makes sense. Adding Thanks for your time! |
… run, and support throwing expressions Resolves #166 Resolves rdar://121531170
… run, and support throwing expressions Resolves #166 Resolves rdar://121531170
… run, and support throwing expressions Resolves #166 Resolves rdar://121531170
… run, and support throwing expressions (#366) This changes test declaration, discovery, planning, and running such that arguments to parameterized test functions are evaluated lazily, only after determining their test will run. It also adds support for throwing expressions in test arguments. ### Motivation: When defining parameterized test functions, it can be useful to call throwing or asynchronous APIs — for example, to fetch the arguments from an external source. Today, the `@Test` macro supports `async` expressions but not `throws`. More problematic still: the arguments of _all_ tests get evaluated, even for tests which don't actually run (which may happen for various reasons). Evaluating the arguments of a test which won't run wastes time and resources, so we should try to avoid this, and support `throws` expressions too for better flexibility. ### Modifications: - Modify the `@Test` macro and supporting library interfaces to surround test arguments in closures, so their evaluation can be lazy and deferred. - Modify how test case arguments are stored on each `Test` instance accordingly. - Modify the planning logic in `Runner.Plan` to defer evaluation of test cases until we determine whether each test will run. - Update tests. ### Result: Now, arguments to a parameterized test will only be evaluated if that test is actually going to run, and the expressions may include `try` and potentially throw an `Error`. ### 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. Resolves #166 Resolves rdar://121531170
Description
The argument parameter of
Test(_:_:arguments:)
is currently very limited.Adding a version of
Test(_:_:arguments: () async throws -> C)
would greatly improve the parameterisation possibilities (e.g. async loading of parameters from a file).Expected behavior
No response
Actual behavior
No response
Steps to reproduce
No response
swift-testing version/commit hash
No response
Swift & OS version (output of
swift --version && uname -a
)No response
The text was updated successfully, but these errors were encountered: