Skip to content

Commit a11d359

Browse files
committed
A few minor edits for style, whitespace, and documentation cleanup
1 parent bdafb49 commit a11d359

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

Sources/XCTest/Private/XCTestCase.TearDownBlocksState.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@
55
//
66
// See http://swift.org/LICENSE.txt for license information
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8-
//
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
128

139
extension XCTestCase {
10+
11+
/// A class which encapsulates teardown blocks which are registered via the `addTeardownBlock(_:)` method.
12+
/// Supports async and sync throwing methods.
1413
final class TeardownBlocksState {
1514

1615
private var wasFinalized = false
1716
private var blocks: [() throws -> Void] = []
1817

19-
@available(macOS 12, *)
20-
2118
// We don't want to overload append(_:) below because of how Swift will implicitly promote sync closures to async closures,
2219
// which can unexpectedly change their semantics in difficult to track down ways.
2320
//
2421
// 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
22+
@available(macOS 12.0, *)
2523
func appendAsync(_ block: @Sendable @escaping () async throws -> Void) {
2624
self.append {
2725
try awaitUsingExpectation { try await block() }

Sources/XCTest/Public/XCAbstractTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ open class XCTest {
5252
perform(testRun!)
5353
}
5454

55-
/// Async setup method called before the invocation of `setUp` for each test method in the class.
55+
/// Async setup method called before the invocation of `setUpWithError` for each test method in the class.
5656
@available(macOS 12.0, *)
5757
open func setUp() async throws {}
5858

Sources/XCTest/Public/XCTestCase.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ open class XCTestCase: XCTest {
3535
private let testClosure: XCTestCaseClosure
3636

3737
private var skip: XCTSkip?
38-
private let teardownBlocksState = TeardownBlocksState()
3938

4039
/// The name of the test case, consisting of its class name and the method
4140
/// name it will run.
@@ -195,13 +194,15 @@ open class XCTestCase: XCTest {
195194
/// Teardown method called after the invocation of every test method in the
196195
/// class.
197196
open class func tearDown() {}
198-
197+
198+
private let teardownBlocksState = TeardownBlocksState()
199+
199200
/// Registers a block of teardown code to be run after the current test
200201
/// method ends.
201202
open func addTeardownBlock(_ block: @escaping () -> Void) {
202203
teardownBlocksState.append(block)
203204
}
204-
205+
205206
/// Registers a block of teardown code to be run after the current test
206207
/// method ends.
207208
@available(macOS 12.0, *)
@@ -212,7 +213,7 @@ open class XCTestCase: XCTest {
212213
private func performSetUpSequence() {
213214
func handleErrorDuringSetUp(_ error: Error) {
214215
if error.xct_shouldRecordAsTestFailure {
215-
self.recordFailure(for: error)
216+
recordFailure(for: error)
216217
}
217218

218219
if error.xct_shouldSkipTestInvocation {
@@ -235,22 +236,21 @@ open class XCTestCase: XCTest {
235236
}
236237

237238
do {
238-
try self.setUpWithError()
239+
try setUpWithError()
239240
} catch {
240241
handleErrorDuringSetUp(error)
241242
}
242243

243-
self.setUp()
244+
setUp()
244245
}
245-
246-
246+
247247
private func performTearDownSequence() {
248248
func handleErrorDuringTearDown(_ error: Error) {
249249
if error.xct_shouldRecordAsTestFailure {
250250
recordFailure(for: error)
251251
}
252252
}
253-
253+
254254
func runTeardownBlocks() {
255255
for block in self.teardownBlocksState.finalize().reversed() {
256256
do {
@@ -260,7 +260,7 @@ open class XCTestCase: XCTest {
260260
}
261261
}
262262
}
263-
263+
264264
runTeardownBlocks()
265265

266266
tearDown()

0 commit comments

Comments
 (0)