Skip to content

Commit 2c60dd6

Browse files
authored
Remove unused "override comment" from ConditionTrait implementation (#1036)
This removes a mechanism in the implementation of `ConditionTrait` for a condition closure to provide an "override" comment. ### Motivation: While reviewing a draft evolution proposal for `ConditionTrait` (swiftlang/swift-evolution#2740) I realized that we don't use this "comment override" mechanism anywhere in the testing library. I believe we did back when it was first added, but it's no longer used. Removing this would allow the public API being proposed above to be simplified: the `evaluate()` method could return `Bool` instead of a tuple. ### 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.
1 parent ee700e2 commit 2c60dd6

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

Sources/Testing/Traits/ConditionTrait.swift

+6-27
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,8 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
2626
///
2727
/// - Parameters:
2828
/// - body: The function to call. The result of this function determines
29-
/// if the condition is satisfied or not. If this function returns
30-
/// `false` and a comment is also returned, it is used in place of the
31-
/// value of the associated trait's ``ConditionTrait/comment`` property.
32-
/// If this function returns `true`, the returned comment is ignored.
33-
case conditional(_ body: @Sendable () async throws -> (Bool, comment: Comment?))
34-
35-
/// Create an instance of this type associated with a trait that is
36-
/// conditional on the result of calling a function.
37-
///
38-
/// - Parameters:
39-
/// - body: The function to call. The result of this function determines
40-
/// whether or not the condition was met.
41-
///
42-
/// - Returns: A trait that marks a test's enabled status as the result of
43-
/// calling a function.
44-
static func conditional(_ body: @escaping @Sendable () async throws -> Bool) -> Self {
45-
conditional { () -> (Bool, comment: Comment?) in
46-
return (try await body(), nil)
47-
}
48-
}
29+
/// if the condition is satisfied or not.
30+
case conditional(_ body: @Sendable () async throws -> Bool)
4931

5032
/// The trait is unconditional and always has the same result.
5133
///
@@ -82,14 +64,11 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
8264
public var sourceLocation: SourceLocation
8365

8466
public func prepare(for test: Test) async throws {
85-
let result: Bool
86-
var commentOverride: Comment?
87-
88-
switch kind {
67+
let result = switch kind {
8968
case let .conditional(condition):
90-
(result, commentOverride) = try await condition()
69+
try await condition()
9170
case let .unconditional(unconditionalValue):
92-
result = unconditionalValue
71+
unconditionalValue
9372
}
9473

9574
if !result {
@@ -99,7 +78,7 @@ public struct ConditionTrait: TestTrait, SuiteTrait {
9978
// attempt to get the backtrace of the caught error when creating an issue
10079
// for it, however.
10180
let sourceContext = SourceContext(backtrace: nil, sourceLocation: sourceLocation)
102-
throw SkipInfo(comment: commentOverride ?? comments.first, sourceContext: sourceContext)
81+
throw SkipInfo(comment: comments.first, sourceContext: sourceContext)
10382
}
10483
}
10584

0 commit comments

Comments
 (0)