Skip to content

Improve error reporting in edge cases. #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Sources/XCTest/Public/XCTestRun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,21 @@ open class XCTestRun {
/// result of a failed assertion, `false` if it was the result of an
/// uncaught exception.
func recordFailure(withDescription description: String, inFile filePath: String?, atLine lineNumber: Int, expected: Bool) {
func failureLocation() -> String {
if let filePath = filePath {
return "\(test.name) (\(filePath):\(lineNumber))"
} else {
return "\(test.name)"
}
}

guard isStarted else {
fatalError("Invalid attempt to record a failure for a test run " +
"that has not yet been started: \(self)")
"that has not yet been started: \(failureLocation())")
}
guard !isStopped else {
fatalError("Invalid attempt to record a failure for a test run " +
"that has already been stopped: \(self)")
"that has already been stopped: \(failureLocation())")
}

if expected {
Expand Down