Skip to content

Introduce a severity level when recording issues #1070

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
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions Sources/Testing/Issues/Issue+Recording.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,34 @@ extension Issue {
let issue = Issue(kind: .errorCaught(error), comments: Array(comment), sourceContext: sourceContext)
return issue.record()
}

/// Record a new issue when a running test unexpectedly catches an error.
///
/// - Parameters:
/// - error: The error that caused the issue.
/// - comment: A comment describing the expectation.
/// - sourceLocation: The source location to which the issue should be
/// attributed.
/// - severity: The severity of the issue.
///
/// - Returns: The issue that was recorded.
///
/// This function can be used if an unexpected error is caught while running a
/// test and it should be treated as a test failure. If an error is thrown
/// from a test function, it is automatically recorded as an issue and this
/// function does not need to be used.
@_spi(Experimental)
@discardableResult public static func record(
_ error: any Error,
_ comment: Comment? = nil,
sourceLocation: SourceLocation = #_sourceLocation,
severity: Severity = .error,
) -> Self {
let backtrace = Backtrace(forFirstThrowOf: error) ?? Backtrace.current()
let sourceContext = SourceContext(backtrace: backtrace, sourceLocation: sourceLocation)
let issue = Issue(kind: .errorCaught(error), severity: severity, comments: Array(comment), sourceContext: sourceContext)
return issue.record()
}

/// Catch any error thrown from a closure and record it as an issue instead of
/// allowing it to propagate to the caller.
Expand Down