Skip to content

Commit f949445

Browse files
authored
Remove extraneous @escaping and @sendable attributes from CustomExecutionTrait.execute(...) SPI (#726)
This refines the `CustomExecutionTrait` SPI protocol by removing two unnecessary attributes from the signature of its `execute(_:for:testCase:)` method requirement: 1. The `@escaping` attribute on the `function` parameter was needed originally to avoid a warning, but `function` should _not_ actually be considered escaping and part of the contract of this interface is that the implementor must call it before returning. The compiler no longer complains about this, so we can enforce this requirement by removing the unnecessary `@escaping` attribute now. 2. The outer `@Sendable` was necessary when this SPI was first written to avoid a Swift concurrency warning, since a reference to the function is taken elsewhere in the codebase, but this is no longer needed in recent Swift compilers. ### 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 9356239 commit f949445

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: Sources/Testing/Traits/Trait.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ public protocol CustomExecutionTrait: Trait {
110110
///
111111
/// - Note: If a test function or test suite is skipped, this function does
112112
/// not get invoked by the runner.
113-
@Sendable func execute(_ function: @escaping @Sendable () async throws -> Void, for test: Test, testCase: Test.Case?) async throws
113+
func execute(_ function: @Sendable () async throws -> Void, for test: Test, testCase: Test.Case?) async throws
114114
}

Diff for: Tests/TestingTests/Traits/CustomExecutionTraitTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct CustomExecutionTraitTests {
6868
private struct CustomTrait: CustomExecutionTrait, TestTrait {
6969
var before: Confirmation
7070
var after: Confirmation
71-
func execute(_ function: @escaping @Sendable () async throws -> Void, for test: Test, testCase: Test.Case?) async throws {
71+
func execute(_ function: @Sendable () async throws -> Void, for test: Test, testCase: Test.Case?) async throws {
7272
before()
7373
defer {
7474
after()
@@ -80,15 +80,15 @@ private struct CustomTrait: CustomExecutionTrait, TestTrait {
8080
private struct CustomThrowingErrorTrait: CustomExecutionTrait, TestTrait {
8181
fileprivate struct CustomTraitError: Error {}
8282

83-
func execute(_ function: @escaping @Sendable () async throws -> Void, for test: Test, testCase: Test.Case?) async throws {
83+
func execute(_ function: @Sendable () async throws -> Void, for test: Test, testCase: Test.Case?) async throws {
8484
throw CustomTraitError()
8585
}
8686
}
8787

8888
struct DoSomethingBeforeAndAfterTrait: CustomExecutionTrait, SuiteTrait, TestTrait {
8989
static let state = Locked(rawValue: 0)
9090

91-
func execute(_ function: @escaping @Sendable () async throws -> Void, for test: Testing.Test, testCase: Testing.Test.Case?) async throws {
91+
func execute(_ function: @Sendable () async throws -> Void, for test: Testing.Test, testCase: Testing.Test.Case?) async throws {
9292
#expect(Self.state.increment() == 1)
9393

9494
try await function()

0 commit comments

Comments
 (0)