-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
2516cdb
commit dcce2c7
Showing
6 changed files
with
246 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.