19
19
/// - ``Trait/disabled(if:_:sourceLocation:)``
20
20
/// - ``Trait/disabled(_:sourceLocation:_:)``
21
21
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 ? )
29
24
30
25
/// An enumeration describing the kinds of conditions that can be represented
31
26
/// by an instance of this type.
@@ -38,7 +33,7 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
38
33
/// `false` and a comment is also returned, it is used in place of the
39
34
/// value of the associated trait's ``ConditionTrait/comment`` property.
40
35
/// 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 )
42
37
43
38
/// Create an instance of this type associated with a trait that is
44
39
/// conditional on the result of calling a function.
@@ -49,7 +44,7 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
49
44
///
50
45
/// - Returns: An instance of this type.
51
46
static func conditional( _ body: @escaping @Sendable ( ) async throws -> Bool ) -> Self {
52
- conditional { ( ) -> ( Bool , comment : Comment ? ) in
47
+ conditional { ( ) -> Evaluation in
53
48
return ( try await body ( ) , nil )
54
49
}
55
50
}
@@ -89,24 +84,20 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
89
84
public var sourceLocation : SourceLocation
90
85
91
86
/// Returns the result of evaluating the condition.
87
+ @_spi ( Experimental)
92
88
public func evaluate( ) async throws -> Evaluation {
93
89
switch kind {
94
90
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 ( )
101
92
case let . unconditional( unconditionalValue) :
102
- unconditionalValue ? . success : . failure ( nil )
93
+ ( unconditionalValue, nil )
103
94
}
104
95
}
105
96
106
97
public func prepare( for test: Test ) async throws {
107
- let result = try await evaluate ( )
98
+ let ( isEnabled , commentOverride ) = try await evaluate ( )
108
99
109
- if case let . failure ( commentOverride ) = result {
100
+ if !isEnabled {
110
101
// We don't need to consider including a backtrace here because it will
111
102
// primarily contain frames in the testing library, not user code. If an
112
103
// error was thrown by a condition evaluated above, the caller _should_
0 commit comments