Skip to content

Expose Issue severity and isFailure as API #1075

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
48 changes: 3 additions & 45 deletions Sources/Testing/Issues/Issue+Recording.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,6 @@ extension Issue {
return self
}

/// Record an issue when a running test fails unexpectedly.
///
/// - Parameters:
/// - comment: A comment describing the expectation.
/// - sourceLocation: The source location to which the issue should be
/// attributed.
///
/// - Returns: The issue that was recorded.
///
/// Use this function if, while running a test, an issue occurs that cannot be
/// represented as an expectation (using the ``expect(_:_:sourceLocation:)``
/// or ``require(_:_:sourceLocation:)-5l63q`` macros.)
@discardableResult public static func record(
_ comment: Comment? = nil,
sourceLocation: SourceLocation = #_sourceLocation
) -> Self {
record(comment, severity: .error, sourceLocation: sourceLocation)
}

/// Record an issue when a running test fails unexpectedly.
///
/// - Parameters:
Expand All @@ -90,10 +71,9 @@ extension Issue {
/// Use this function if, while running a test, an issue occurs that cannot be
/// represented as an expectation (using the ``expect(_:_:sourceLocation:)``
/// or ``require(_:_:sourceLocation:)-5l63q`` macros.)
@_spi(Experimental)
@discardableResult public static func record(
_ comment: Comment? = nil,
severity: Severity,
severity: Severity = .error,
sourceLocation: SourceLocation = #_sourceLocation
) -> Self {
let sourceContext = SourceContext(backtrace: .current(), sourceLocation: sourceLocation)
Expand All @@ -105,28 +85,7 @@ extension Issue {
// MARK: - Recording issues for errors

extension Issue {
/// 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.
///
/// - 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.
@discardableResult public static func record(
_ error: any Error,
_ comment: Comment? = nil,
sourceLocation: SourceLocation = #_sourceLocation
) -> Self {
record(error, comment, severity: .error, sourceLocation: sourceLocation)
}


/// Record a new issue when a running test unexpectedly catches an error.
///
/// - Parameters:
Expand All @@ -142,11 +101,10 @@ extension Issue {
/// 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,
severity: Severity,
severity: Severity = .error,
sourceLocation: SourceLocation = #_sourceLocation
) -> Self {
let backtrace = Backtrace(forFirstThrowOf: error) ?? Backtrace.current()
Expand Down
3 changes: 0 additions & 3 deletions Sources/Testing/Issues/Issue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public struct Issue: Sendable {
///
/// - ``warning``
/// - ``error``
@_spi(Experimental)
public enum Severity: Sendable {
/// The severity level for an issue which should be noted but is not
/// necessarily an error.
Expand All @@ -101,7 +100,6 @@ public struct Issue: Sendable {
}

/// The severity of this issue.
@_spi(Experimental)
public var severity: Severity

/// Whether or not this issue should cause the test it's associated with to be
Expand All @@ -114,7 +112,6 @@ public struct Issue: Sendable {
///
/// Use this property to determine if an issue should be considered a failure, instead of
/// directly comparing the value of the ``severity`` property.
@_spi(Experimental)
public var isFailure: Bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this member is necessary; whether or not a warning is a failure might depend on external configuration (some equivalent to -Werror perhaps.)

return !self.isKnown && self.severity >= .error
}
Expand Down