Skip to content

Commit 500b964

Browse files
committed
Add name as a property on XCTestCase
1 parent 264d26b commit 500b964

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Sources/XCTest/XCTestCase.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(
2626

2727
public class XCTestCase {
2828

29+
/// The name of the test case, consisting of its class name and the method name it will run.
30+
/// - Note: FIXME: This property should be readonly, but currently has to be publicly settable due to a
31+
/// toolchain bug on Linux. To ensure compatibility of tests between
32+
/// swift-corelibs-xctest and Apple XCTest, this property should not be modified.
33+
public var name: String
34+
2935
public required init() {
36+
name = "\(self.dynamicType).<unknown>"
3037
}
3138

3239
public func setUp() {
@@ -78,19 +85,19 @@ extension XCTestCase {
7885
let overallDuration = measureTimeExecutingBlock {
7986
for (name, test) in tests {
8087
let testCase = self.init()
81-
let fullName = "\(testCase.dynamicType).\(name)"
88+
testCase.name = "\(testCase.dynamicType).\(name)"
8289

8390
var failures = [XCTFailure]()
8491
XCTFailureHandler = { failure in
8592
if !testCase.continueAfterFailure {
86-
failure.emit(fullName)
93+
failure.emit(testCase.name)
8794
fatalError("Terminating execution due to test failure", file: failure.file, line: failure.line)
8895
} else {
8996
failures.append(failure)
9097
}
9198
}
9299

93-
XCTPrint("Test Case '\(fullName)' started.")
100+
XCTPrint("Test Case '\(testCase.name)' started.")
94101

95102
testCase.setUp()
96103

@@ -111,16 +118,16 @@ extension XCTestCase {
111118

112119
var result = "passed"
113120
for failure in failures {
114-
failure.emit(fullName)
121+
failure.emit(testCase.name)
115122
totalFailures += 1
116123
if !failure.expected {
117124
unexpectedFailures += 1
118125
}
119126
result = failures.count > 0 ? "failed" : "passed"
120127
}
121128

122-
XCTPrint("Test Case '\(fullName)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")
123-
XCTAllRuns.append(XCTRun(duration: duration, method: fullName, passed: failures.count == 0, failures: failures))
129+
XCTPrint("Test Case '\(testCase.name)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")
130+
XCTAllRuns.append(XCTRun(duration: duration, method: testCase.name, passed: failures.count == 0, failures: failures))
124131
XCTFailureHandler = nil
125132
}
126133
}

0 commit comments

Comments
 (0)