Skip to content

Commit 2922f02

Browse files
committed
Change to tuple for return value
1 parent e0e3a82 commit 2922f02

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

Sources/Testing/Traits/ConditionTrait.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@
1919
/// - ``Trait/disabled(if:_:sourceLocation:)``
2020
/// - ``Trait/disabled(_:sourceLocation:_:)``
2121
public struct ConditionTrait: TestTrait, SuiteTrait {
22-
/// An enumeration identifying the result of evaluating the condition.
23-
public enum Evaluation: Sendable {
24-
/// The condition succeeded.
25-
case success
26-
/// The condition failed, potentially returning a `Comment`.
27-
case failure(Comment?)
28-
}
22+
/// The result of evaluating the condition.
23+
public typealias Evaluation = (Bool, comment: Comment?)
2924

3025
/// An enumeration describing the kinds of conditions that can be represented
3126
/// by an instance of this type.
@@ -38,7 +33,7 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
3833
/// `false` and a comment is also returned, it is used in place of the
3934
/// value of the associated trait's ``ConditionTrait/comment`` property.
4035
/// If this function returns `true`, the returned comment is ignored.
41-
case conditional(_ body: @Sendable () async throws -> (Bool, comment: Comment?))
36+
case conditional(_ body: @Sendable () async throws -> Evaluation)
4237

4338
/// Create an instance of this type associated with a trait that is
4439
/// conditional on the result of calling a function.
@@ -49,7 +44,7 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
4944
///
5045
/// - Returns: An instance of this type.
5146
static func conditional(_ body: @escaping @Sendable () async throws -> Bool) -> Self {
52-
conditional { () -> (Bool, comment: Comment?) in
47+
conditional { () -> Evaluation in
5348
return (try await body(), nil)
5449
}
5550
}
@@ -89,24 +84,20 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
8984
public var sourceLocation: SourceLocation
9085

9186
/// Returns the result of evaluating the condition.
87+
@_spi(Experimental)
9288
public func evaluate() async throws -> Evaluation {
9389
switch kind {
9490
case let .conditional(condition):
95-
switch try await condition() {
96-
case (true, _):
97-
.success
98-
case (false, let comment):
99-
.failure(comment)
100-
}
91+
try await condition()
10192
case let .unconditional(unconditionalValue):
102-
unconditionalValue ? .success : .failure(nil)
93+
(unconditionalValue, nil)
10394
}
10495
}
10596

10697
public func prepare(for test: Test) async throws {
107-
let result = try await evaluate()
98+
let (isEnabled, commentOverride) = try await evaluate()
10899

109-
if case let .failure(commentOverride) = result {
100+
if !isEnabled {
110101
// We don't need to consider including a backtrace here because it will
111102
// primarily contain frames in the testing library, not user code. If an
112103
// error was thrown by a condition evaluated above, the caller _should_

0 commit comments

Comments
 (0)