Skip to content

Commit 1c7fb28

Browse files
author
Tiago Martinho
committed
Define XCTestCaseClosure typealias
1 parent d8ad0e1 commit 1c7fb28

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Sources/XCTest/Public/XCTestCase.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
// Base class for test cases
1212
//
1313

14+
/// A block with the test code to be invoked when the test runs.
15+
///
16+
/// - Parameter testCase: the test case associated with the current test code.
17+
public typealias XCTestCaseClosure = (XCTestCase) throws -> Void
18+
1419
/// This is a compound type used by `XCTMain` to represent tests to run. It combines an
1520
/// `XCTestCase` subclass type with the list of test case methods to invoke on the class.
1621
/// This type is intended to be produced by the `testCase` helper function.
1722
/// - seealso: `testCase`
1823
/// - seealso: `XCTMain`
19-
public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(String, (XCTestCase) throws -> Void)])
24+
public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(String, XCTestCaseClosure)])
2025

2126
// A global pointer to the currently running test case. This is required in
2227
// order for XCTAssert functions to report failures.
@@ -27,7 +32,7 @@ internal var XCTCurrentTestCase: XCTestCase?
2732
/// methods containing the tests to run.
2833
/// - seealso: `XCTMain`
2934
open class XCTestCase: XCTest {
30-
private let testClosure: (XCTestCase) throws -> Void
35+
private let testClosure: XCTestCaseClosure
3136

3237
/// The name of the test case, consisting of its class name and the method
3338
/// name it will run.
@@ -68,7 +73,7 @@ open class XCTestCase: XCTest {
6873
/// - Note: Like the designated initializer for Apple XCTest's XCTestCase,
6974
/// `-[XCTestCase initWithInvocation:]`, it's rare for anyone outside of
7075
/// XCTest itself to call this initializer.
71-
public required init(name: String, testClosure: @escaping (XCTestCase) throws -> Void) {
76+
public required init(name: String, testClosure: @escaping XCTestCaseClosure) {
7277
_name = "\(type(of: self)).\(name)"
7378
self.testClosure = testClosure
7479
}
@@ -144,18 +149,18 @@ open class XCTestCase: XCTest {
144149
/// the signature required by `XCTMain`
145150
/// - seealso: `XCTMain`
146151
public func testCase<T: XCTestCase>(_ allTests: [(String, (T) -> () throws -> Void)]) -> XCTestCaseEntry {
147-
let tests: [(String, (XCTestCase) throws -> Void)] = allTests.map { ($0.0, test($0.1)) }
152+
let tests: [(String, XCTestCaseClosure)] = allTests.map { ($0.0, test($0.1)) }
148153
return (T.self, tests)
149154
}
150155

151156
/// Wrapper function for the non-throwing variant of tests.
152157
/// - seealso: `XCTMain`
153158
public func testCase<T: XCTestCase>(_ allTests: [(String, (T) -> () -> Void)]) -> XCTestCaseEntry {
154-
let tests: [(String, (XCTestCase) throws -> Void)] = allTests.map { ($0.0, test($0.1)) }
159+
let tests: [(String, XCTestCaseClosure)] = allTests.map { ($0.0, test($0.1)) }
155160
return (T.self, tests)
156161
}
157162

158-
private func test<T: XCTestCase>(_ testFunc: @escaping (T) -> () throws -> Void) -> (XCTestCase) throws -> Void {
163+
private func test<T: XCTestCase>(_ testFunc: @escaping (T) -> () throws -> Void) -> XCTestCaseClosure {
159164
return { testCaseType in
160165
guard let testCase = testCaseType as? T else {
161166
fatalError("Attempt to invoke test on class \(T.self) with incompatible instance type \(type(of: testCaseType))")

0 commit comments

Comments
 (0)