Skip to content

Add a kind to Issue.record to record various kinds a of issues #1120

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

/// Record an issue when a running test fails unexpectedly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Record an issue when a running test fails unexpectedly.
/// Record an issue with a specific kind.

///
/// - Parameters:
/// - comment: A comment describing the expectation.
/// - severity: The severity of the issue.
/// - sourceLocation: The source location to which the issue should be
/// attributed.
/// - kind: The kind of the issue.
Copy link
Contributor

Choose a reason for hiding this comment

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

kind can move up to the top, now

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be deleted.

///
/// - 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.)
@_spi(Experimental)
@_spi(ForToolsIntegrationOnly)
@discardableResult public static func record(
kind: Kind = .unconditional,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok now that this is a distinct overload, I think you'll need to make kind: not have a default value at all, because all parameters have a default value now and Issue.record() (zero args) may be ambiguous with the public API

Suggested change
kind: Kind = .unconditional,
kind: Kind,

comment: Comment? = nil,
severity: Severity = .error,
sourceLocation: SourceLocation = #_sourceLocation
) -> Self {
let sourceContext = SourceContext(backtrace: .current(), sourceLocation: sourceLocation)
let issue = Issue(kind: kind, severity: severity, comments: Array(comment), sourceContext: sourceContext)
return issue.record()
}

}

// MARK: - Recording issues for errors
Expand Down
19 changes: 19 additions & 0 deletions Tests/TestingTests/IssueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,25 @@ final class IssueTests: XCTestCase {

await fulfillment(of: [errorCaught, apiMisused, expectationFailed], timeout: 0.0)
}

func testIssueRecordKinds() async throws {
var configuration = Configuration()
let apiMisused = expectation(description: "API misused")
configuration.eventHandler = { event, _ in
guard case let .issueRecorded(issue) = event.kind else {
return
}
if case .apiMisused = issue.kind {
apiMisused.fulfill()
}

}
await Test {
Issue.record(kind: .apiMisused, comment: "My comment")
}.run(configuration: configuration)

await fulfillment(of: [apiMisused], timeout: 0.0)
}

@__testing(semantics: "nomacrowarnings")
func testErrorCheckingWithRequire_ResultValueIsNever_VariousSyntaxes() throws {
Expand Down