Skip to content

Commit 5436c62

Browse files
committed
Add an XCTestCase class, renaming the protocol to XCTestCaseType
1 parent e2a5e1e commit 5436c62

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

Sources/XCTest/XCTestCase.swift

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@
1111
// Base protocol (and extension with default methods) for test cases
1212
//
1313

14-
public protocol XCTestCase : XCTestCaseProvider {
15-
func setUp()
16-
func tearDown()
17-
}
14+
public class XCTestCase {
15+
16+
public init() {
17+
}
18+
19+
public func setUp() {
20+
}
21+
22+
public func tearDown() {
23+
}
24+
25+
public var allTests : [(String, () throws -> Void)] {
26+
return [("missingTests", throwMissingAllTestsOverride)]
27+
}
1828

19-
extension XCTestCase {
20-
2129
public var continueAfterFailure: Bool {
2230
get {
2331
return true
@@ -26,7 +34,30 @@ extension XCTestCase {
2634
// TODO: When using the Objective-C runtime, XCTest is able to throw an exception from an assert and then catch it at the frame above the test method. This enables the framework to effectively stop all execution in the current test. There is no such facility in Swift. Until we figure out how to get a compatible behavior, we have decided to hard-code the value of 'true' for continue after failure.
2735
}
2836
}
29-
37+
}
38+
39+
// MARK: Error Reporting
40+
extension XCTestCase {
41+
42+
public enum Error: ErrorType, CustomStringConvertible {
43+
case MissingAllTestsOverride
44+
45+
public var description: String {
46+
switch self {
47+
case .MissingAllTestsOverride:
48+
return "XCTestCase subclasses must override the `allTests` property to list the individual tests they provide"
49+
}
50+
}
51+
}
52+
53+
func throwMissingAllTestsOverride() throws {
54+
throw Error.MissingAllTestsOverride
55+
}
56+
}
57+
58+
// MARK: Running Tests
59+
extension XCTestCase {
60+
3061
public func invokeTest() {
3162
let tests = self.allTests
3263
var totalDuration = 0.0
@@ -90,12 +121,4 @@ extension XCTestCase {
90121

91122
print("Executed \(tests.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(unexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) (\(printableStringForTimeInterval(overallDuration))) seconds")
92123
}
93-
94-
public func setUp() {
95-
96-
}
97-
98-
public func tearDown() {
99-
100-
}
101124
}

0 commit comments

Comments
 (0)