Skip to content

Commit 1a08ed3

Browse files
committed
Draft proposal
1 parent 6c84190 commit 1a08ed3

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Public API to evaluate ConditionTrait
2+
3+
* Proposal: [SWT-NNNN](NNNN-evaluate-condition.md)
4+
* Authors: [David Catmull](https://github.com/Uncommon)
5+
* Status: **Awaiting review**
6+
* Implementation: [swiftlang/swift-testing#909](https://github.com/swiftlang/swift-testing/pull/909)
7+
* Review: ([pitch](https://forums.swift.org/...))
8+
9+
## Introduction
10+
11+
This adds an `evaluate()` method to `ConditionTrait` to evaluate the condition
12+
without requiring a `Test` instance.
13+
14+
## Motivation
15+
16+
Currently, the only way a `ConditionTrait` is evaluated is inside the
17+
`prepare(for:)` method. This makes it difficult for third-party libraries to
18+
utilize these traits because evaluating a condition would require creating a
19+
dummy `Test` to pass to that method.
20+
21+
## Proposed solution
22+
23+
The proposal is to add a `ConditionTrait.evaluate()` method which returns the
24+
result of the evaluation. The existing `prepare(for:)` method is updated to call
25+
`evaluate()` so that the logic is not duplicated.
26+
27+
## Detailed design
28+
29+
The signature is `evaluate() async throws -> Evaluation`, where `Evaluation` is
30+
a `typealias` for the tuple already used for the callback in `Kind.conditional`,
31+
containing a boolean result and an optional comment.
32+
33+
## Source compatibility
34+
35+
This change is purely additive.
36+
37+
## Integration with supporting tools
38+
39+
This change allows third-party libraries to apply condition traits at other
40+
levels than suites or whole test functions, for example if tests are broken up
41+
into smaller sections.
42+
43+
## Future directions
44+
45+
This change seems sufficient for third party libraries to make use of
46+
`ConditionTrait`. Changes for other traits can be tackled in separate proposals.
47+
48+
## Alternatives considered
49+
50+
Exposing `ConditionTrait.Kind` and `.kind` was also considered, but it seemed
51+
unnecessary to go that far, and it would encourage duplicating the logic that
52+
already exists in `prepare(for:)`.
53+
54+
In the first draft implementation, the `Evaluation` type was an enum that only
55+
contained the comment in the failure case. It was changed to match the existing
56+
tuple to allow for potentially including comments for the success case without
57+
requiring a change to the API.

0 commit comments

Comments
 (0)