From e37476ec2842b6e217221837061c555eeb449452 Mon Sep 17 00:00:00 2001 From: Suzy Ratcliff Date: Mon, 19 May 2025 21:25:09 -0700 Subject: [PATCH 1/3] Add test --- Sources/Testing/Issues/Issue+Recording.swift | 6 ++++-- Tests/TestingTests/IssueTests.swift | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Sources/Testing/Issues/Issue+Recording.swift b/Sources/Testing/Issues/Issue+Recording.swift index b79e94269..eeacf2309 100644 --- a/Sources/Testing/Issues/Issue+Recording.swift +++ b/Sources/Testing/Issues/Issue+Recording.swift @@ -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. /// @@ -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 ) -> 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() } } diff --git a/Tests/TestingTests/IssueTests.swift b/Tests/TestingTests/IssueTests.swift index cc0a7acf5..a86a19890 100644 --- a/Tests/TestingTests/IssueTests.swift +++ b/Tests/TestingTests/IssueTests.swift @@ -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 { @@ -1764,6 +1783,7 @@ struct IssueCodingTests { }.run(configuration: configuration) } } + } #endif From c8699e692f7832432acbf7bf8163c0d620d65396 Mon Sep 17 00:00:00 2001 From: Suzy Ratcliff Date: Tue, 20 May 2025 11:35:24 -0700 Subject: [PATCH 2/3] Remove extra line --- Tests/TestingTests/IssueTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/TestingTests/IssueTests.swift b/Tests/TestingTests/IssueTests.swift index a86a19890..943dd0aeb 100644 --- a/Tests/TestingTests/IssueTests.swift +++ b/Tests/TestingTests/IssueTests.swift @@ -1783,7 +1783,6 @@ struct IssueCodingTests { }.run(configuration: configuration) } } - } #endif From 1ce3dc289b9326831fa019737f877ce182a8e5a7 Mon Sep 17 00:00:00 2001 From: Suzy Ratcliff Date: Tue, 20 May 2025 12:11:22 -0700 Subject: [PATCH 3/3] Add another Record.issue overload and reorder parameters of Issue.record --- Sources/Testing/Issues/Issue+Recording.swift | 32 ++++++++++++++++++-- Tests/TestingTests/IssueTests.swift | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Sources/Testing/Issues/Issue+Recording.swift b/Sources/Testing/Issues/Issue+Recording.swift index eeacf2309..b03217280 100644 --- a/Sources/Testing/Issues/Issue+Recording.swift +++ b/Sources/Testing/Issues/Issue+Recording.swift @@ -76,7 +76,6 @@ 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. /// @@ -87,13 +86,40 @@ extension Issue { @discardableResult public static func record( _ comment: Comment? = nil, severity: Severity, - sourceLocation: SourceLocation = #_sourceLocation, - kind: Kind = .unconditional + sourceLocation: SourceLocation = #_sourceLocation + ) -> Self { + let sourceContext = SourceContext(backtrace: .current(), sourceLocation: sourceLocation) + let issue = Issue(kind: .unconditional, severity: severity, comments: Array(comment), sourceContext: sourceContext) + return issue.record() + } + + /// Record an issue when a running test fails unexpectedly. + /// + /// - 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. + /// + /// - 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, + 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 diff --git a/Tests/TestingTests/IssueTests.swift b/Tests/TestingTests/IssueTests.swift index 943dd0aeb..5c861f13a 100644 --- a/Tests/TestingTests/IssueTests.swift +++ b/Tests/TestingTests/IssueTests.swift @@ -999,7 +999,7 @@ final class IssueTests: XCTestCase { } await Test { - Issue.record("My comment", severity: .error, kind: .apiMisused) + Issue.record(kind: .apiMisused, comment: "My comment") }.run(configuration: configuration) await fulfillment(of: [apiMisused], timeout: 0.0)