-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[ST-0010] Add ConditionTrait.evaluate() #2740
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e8dbf7
Proposal for ConditionTrait.evaluate(), moved from swift-testing
Uncommon d617bd7
Include "extension ConditionTrait" in code exerpts
Uncommon 9299eba
Remove mentions of EvaluationResult, since it now uses Bool
Uncommon 9b0c062
Add myself as review manager
stmontgomery 6b5eb54
Note the associated issue
stmontgomery 7f98165
Assign proposal ST number 0010 and update state to Active Review
stmontgomery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Public API to evaluate ConditionTrait | ||
|
||
* Proposal: [SWT-NNNN](NNNN-evaluate-condition.md) | ||
* Authors: [David Catmull](https://github.com/Uncommon) | ||
* Review Manager: [Stuart Montgomery](https://github.com/stmontgomery) | ||
* Status: **Awaiting review** | ||
* Bug: [swiftlang/swift-testing#903](https://github.com/swiftlang/swift-testing/issues/903) | ||
* Implementation: [swiftlang/swift-testing#909](https://github.com/swiftlang/swift-testing/pull/909) | ||
* Review: ([pitch](https://forums.swift.org/t/pitch-introduce-conditiontrait-evaluate/77242)) | ||
|
||
## Introduction | ||
|
||
This adds an `evaluate()` method to `ConditionTrait` to evaluate the condition | ||
without requiring a `Test` instance. | ||
|
||
## Motivation | ||
|
||
Currently, the only way a `ConditionTrait` is evaluated is inside the | ||
`prepare(for:)` method. This makes it difficult for third-party libraries to | ||
utilize these traits because evaluating a condition would require creating a | ||
dummy `Test` to pass to that method. | ||
|
||
## Proposed solution | ||
|
||
The proposal is to add a `ConditionTrait.evaluate()` method which returns the | ||
result of the evaluation. The existing `prepare(for:)` method is updated to call | ||
`evaluate()` so that the logic is not duplicated. | ||
|
||
## Detailed design | ||
|
||
The `evaluate()` method is as follows, containing essentially the same logic | ||
as was in `prepare(for:)`: | ||
|
||
```swift | ||
extension ConditionTrait { | ||
/// Evaluate this instance's underlying condition. | ||
/// | ||
/// - Returns: The result of evaluating this instance's underlying condition. | ||
/// | ||
/// The evaluation is performed each time this function is called, and is not | ||
/// cached. | ||
public func evaluate() async throws -> Bool | ||
} | ||
``` | ||
|
||
## Source compatibility | ||
|
||
This change is purely additive. | ||
|
||
## Integration with supporting tools | ||
|
||
This change allows third-party libraries to apply condition traits at other | ||
levels than suites or whole test functions, for example if tests are broken up | ||
into smaller sections. | ||
|
||
## Future directions | ||
|
||
This change seems sufficient for third party libraries to make use of | ||
`ConditionTrait`. Changes for other traits can be tackled in separate proposals. | ||
|
||
## Alternatives considered | ||
|
||
Exposing `ConditionTrait.Kind` and `.kind` was also considered, but it seemed | ||
unnecessary to go that far, and it would encourage duplicating the logic that | ||
already exists in `prepare(for:)`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.