11
11
// Base class for test cases
12
12
//
13
13
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
+
14
19
/// This is a compound type used by `XCTMain` to represent tests to run. It combines an
15
20
/// `XCTestCase` subclass type with the list of test case methods to invoke on the class.
16
21
/// This type is intended to be produced by the `testCase` helper function.
17
22
/// - seealso: `testCase`
18
23
/// - seealso: `XCTMain`
19
- public typealias XCTestCaseEntry = ( testCaseClass: XCTestCase . Type , allTests: [ ( String , ( XCTestCase ) throws -> Void ) ] )
24
+ public typealias XCTestCaseEntry = ( testCaseClass: XCTestCase . Type , allTests: [ ( String , XCTestCaseClosure ) ] )
20
25
21
26
// A global pointer to the currently running test case. This is required in
22
27
// order for XCTAssert functions to report failures.
@@ -27,7 +32,7 @@ internal var XCTCurrentTestCase: XCTestCase?
27
32
/// methods containing the tests to run.
28
33
/// - seealso: `XCTMain`
29
34
open class XCTestCase : XCTest {
30
- private let testClosure : ( XCTestCase ) throws -> Void
35
+ private let testClosure : XCTestCaseClosure
31
36
32
37
/// The name of the test case, consisting of its class name and the method
33
38
/// name it will run.
@@ -68,7 +73,7 @@ open class XCTestCase: XCTest {
68
73
/// - Note: Like the designated initializer for Apple XCTest's XCTestCase,
69
74
/// `-[XCTestCase initWithInvocation:]`, it's rare for anyone outside of
70
75
/// 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 ) {
72
77
_name = " \( type ( of: self ) ) . \( name) "
73
78
self . testClosure = testClosure
74
79
}
@@ -144,18 +149,18 @@ open class XCTestCase: XCTest {
144
149
/// the signature required by `XCTMain`
145
150
/// - seealso: `XCTMain`
146
151
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 ) ) }
148
153
return ( T . self, tests)
149
154
}
150
155
151
156
/// Wrapper function for the non-throwing variant of tests.
152
157
/// - seealso: `XCTMain`
153
158
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 ) ) }
155
160
return ( T . self, tests)
156
161
}
157
162
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 {
159
164
return { testCaseType in
160
165
guard let testCase = testCaseType as? T else {
161
166
fatalError ( " Attempt to invoke test on class \( T . self) with incompatible instance type \( type ( of: testCaseType) ) " )
0 commit comments