You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lazily evaluate test arguments only after determining their test will 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
0 commit comments