Skip to content

Commit 0541fa8

Browse files
authored
Merge pull request #282 from drodriguez/better-fatal-error
Improve error reporting in edge cases.
2 parents d893b8e + 4ddeedf commit 0541fa8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/XCTest/Public/XCTestRun.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,21 @@ open class XCTestRun {
119119
/// result of a failed assertion, `false` if it was the result of an
120120
/// uncaught exception.
121121
func recordFailure(withDescription description: String, inFile filePath: String?, atLine lineNumber: Int, expected: Bool) {
122+
func failureLocation() -> String {
123+
if let filePath = filePath {
124+
return "\(test.name) (\(filePath):\(lineNumber))"
125+
} else {
126+
return "\(test.name)"
127+
}
128+
}
129+
122130
guard isStarted else {
123131
fatalError("Invalid attempt to record a failure for a test run " +
124-
"that has not yet been started: \(self)")
132+
"that has not yet been started: \(failureLocation())")
125133
}
126134
guard !isStopped else {
127135
fatalError("Invalid attempt to record a failure for a test run " +
128-
"that has already been stopped: \(self)")
136+
"that has already been stopped: \(failureLocation())")
129137
}
130138

131139
if expected {

0 commit comments

Comments
 (0)