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? # for a free GitHub account to open an issue and contact its maintainers and the community.

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

Already on GitHub? # 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 2 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
6 changes: 4 additions & 2 deletions Sources/Testing/Issues/Issue+Recording.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ extension Issue {
/// - severity: The severity of the issue.
/// - sourceLocation: The source location to which the issue should be
/// attributed.
/// - kind: The kind of the issue.
///
/// - Returns: The issue that was recorded.
///
Expand All @@ -86,10 +87,11 @@ extension Issue {
@discardableResult public static func record(
_ comment: Comment? = nil,
severity: Severity,
sourceLocation: SourceLocation = #_sourceLocation
sourceLocation: SourceLocation = #_sourceLocation,
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.

I recall this is the overload of record() you added previously, and its primary difference from the existing, public API is that it includes a severity: parameter. This one is currently @_spi(Experimental), and I think that SPI level makes sense given your active pitch which seeks to elevate this overload to non-SPI and replace the older one entirely. If that proposal advances and is accepted, I think we will want to expose this record() method as it's currently written and proposed, without including a kind: parameter in its signature.

Given those plans, I think it may make more sense in this PR to expose an entirely new overload of the record() function which includes the kind: parameter, and leave the existing overload alone. And that overload can have two SPI groups—@_spi(Experimental) and @_spi(ForToolsIntegrationOnly)—to reflect that it's intended for use by integrated tools.

I would also suggest placing kind: as the first parameter in that new overload, and giving its comment parameter a label (instead of _ comment: Comment?).

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 never be possible to create an issue with an arbitrary kind field via API or non-experimental SPI, so we need to nix that argument for any public interfaces.

) -> Self {
let sourceContext = SourceContext(backtrace: .current(), sourceLocation: sourceLocation)
let issue = Issue(kind: .unconditional, severity: severity, comments: Array(comment), sourceContext: sourceContext)
let issue = Issue(kind: kind, severity: severity, comments: Array(comment), sourceContext: sourceContext)
return issue.record()
}
}
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("My comment", severity: .error, kind: .apiMisused)
}.run(configuration: configuration)

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

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