Skip to content

Commit b8926d4

Browse files
author
Sean Olszewski
committed
Address PR comments
1 parent eaf8439 commit b8926d4

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

Sources/XCTest/Public/XCTestCase.TearDownBlocksState.swift renamed to Sources/XCTest/Private/XCTestCase.TearDownBlocksState.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,33 @@
66
// See http://swift.org/LICENSE.txt for license information
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
9-
//
10-
// XCTestCase.ClosureType.swift
11-
// Extension on XCTestCase which encapsulates ClosureType
12-
//
13-
14-
/// XCTestCase.TeardownBlocksState
15-
/// A class which encapsulates teardown blocks which are registered via the `addTearDownBlock(_block:)` method.
16-
/// Supports async and sync throwing methods
9+
// XCTestCase.TeardownBlocksState
10+
// A class which encapsulates teardown blocks which are registered via the `addTearDownBlock(_block:)` method.
11+
// Supports async and sync throwing methods
1712

1813
extension XCTestCase {
1914
final class TeardownBlocksState {
20-
15+
2116
private var wasFinalized = false
2217
private var blocks: [() throws -> Void] = []
23-
18+
2419
@available(macOS 12, *)
25-
func append(_ block: @Sendable @escaping () async throws -> Void) {
20+
21+
// We don't want to overload append(_:) below because of how Swift will implicitly promote sync closures to async closures,
22+
// which can unexpectedly change their semantics in difficult to track down ways.
23+
//
24+
// Because of this, we chose the unusual decision to forgo overloading (which is a super sweet language feature <3) to prevent this issue from surprising any contributors to corelibs-xctest
25+
func appendAsync(_ block: @Sendable @escaping () async throws -> Void) {
2626
self.append {
2727
try awaitUsingExpectation { try await block() }
2828
}
2929
}
30-
30+
3131
func append(_ block: @escaping () throws -> Void) {
3232
XCTWaiter.subsystemQueue.sync {
3333
precondition(wasFinalized == false, "API violation -- attempting to add a teardown block after teardown blocks have been dequeued")
34-
blocks.append(block) }
34+
blocks.append(block)
35+
}
3536
}
3637

3738
func finalize() -> [() throws -> Void] {

Sources/XCTest/Public/XCTestCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ open class XCTestCase: XCTest {
206206
/// method ends.
207207
@available(macOS 12.0, *)
208208
open func addTeardownBlock(_ block: @Sendable @escaping () async throws -> Void) {
209-
teardownBlocksState.append(block)
209+
teardownBlocksState.appendAsync(block)
210210
}
211211

212212
private func performSetUpSequence() {

XCTest.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
AE63767D1D01ED17002C0EA8 /* TestListing.swift */,
139139
AE2FE1111CFE86E6003EF0D7 /* WallClockTimeMetric.swift */,
140140
AE2FE1131CFE86E6003EF0D7 /* XCTestCaseSuite.swift */,
141+
A53D646626EA8F0E00F48361 /* XCTestCase.TearDownBlocksState.swift */,
141142
AE2FE1141CFE86E6003EF0D7 /* XCTestInternalObservation.swift */,
142143
17B6C3EC210F53BE00A11ECC /* WaiterManager.swift */,
143144
17D5B67F211216EF00D93239 /* SourceLocation.swift */,
@@ -162,7 +163,6 @@
162163
AE2FE0F71CFE86DB003EF0D7 /* XCTestRun.swift */,
163164
AE2FE0F81CFE86DB003EF0D7 /* XCTestSuite.swift */,
164165
AE2FE0F91CFE86DB003EF0D7 /* XCTestSuiteRun.swift */,
165-
A53D646626EA8F0E00F48361 /* XCTestCase.TearDownBlocksState.swift */,
166166
);
167167
path = Public;
168168
sourceTree = "<group>";

0 commit comments

Comments
 (0)