diff --git a/Sources/IssueReporting/Internal/SwiftTesting.swift b/Sources/IssueReporting/Internal/SwiftTesting.swift index ac8aa47..e75f37f 100644 --- a/Sources/IssueReporting/Internal/SwiftTesting.swift +++ b/Sources/IssueReporting/Internal/SwiftTesting.swift @@ -16,24 +16,49 @@ func _recordIssue( guard let function = function(for: "$s25IssueReportingTestSupport07_recordA0ypyF") else { #if DEBUG && canImport(Darwin) - guard - let record = unsafeBitCast( - symbol: "$s7Testing5IssueV6record_14sourceLocationAcA7CommentVSg_AA06SourceE0VtFZ", - in: "Testing", - to: (@convention(thin) (Any?, SourceLocation) -> Issue).self + #if compiler(>=6.2) + guard + let record = unsafeBitCast( + symbol: """ + $s7Testing5IssueV6record_8severity14sourceLocationAcA7CommentVSg_AC8SeverityOAA06Sour\ + ceF0VtFZ + """, + in: "Testing", + to: (@convention(thin) (Any?, Any, SourceLocation) -> Issue).self + ) + else { return } + + var comment: Any? + if let message { + var c = UnsafeMutablePointer.allocate(capacity: 1).pointee + c.rawValue = message + comment = c + } + _ = record( + comment, + Issue.Severity.error, // TODO: Support other severities? + SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column) ) - else { return } + #else + guard + let record = unsafeBitCast( + symbol: "$s7Testing5IssueV6record_14sourceLocationAcA7CommentVSg_AA06SourceE0VtFZ", + in: "Testing", + to: (@convention(thin) (Any?, SourceLocation) -> Issue).self + ) + else { return } - var comment: Any? - if let message { - var c = UnsafeMutablePointer.allocate(capacity: 1).pointee - c.rawValue = message - comment = c - } - _ = record( - comment, - SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column) - ) + var comment: Any? + if let message { + var c = UnsafeMutablePointer.allocate(capacity: 1).pointee + c.rawValue = message + comment = c + } + _ = record( + comment, + SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column) + ) + #endif #else printError( """ @@ -188,7 +213,7 @@ func _withKnownIssue( let withKnownIssue = unsafeBitCast( symbol: """ $s7Testing14withKnownIssue_14isIntermittent9isolation14sourceLocation_yAA7CommentVSg_\ - SbScA_pSgYiAA06SourceI0VyyYaKXEtYaF + SbScA_pSgYiAA06SourceI0VyyYaKXEtYaFTu """, in: "Testing", to: (@convention(thin) ( @@ -350,7 +375,9 @@ func _currentTest() -> _Test? { var value: __Expression } indirect case functionCall( - value: __Expression?, functionName: String, arguments: [FunctionCallArgument] + value: __Expression?, + functionName: String, + arguments: [FunctionCallArgument] ) indirect case propertyAccess(value: __Expression, keyPath: __Expression) indirect case negation(_ expression: __Expression, isParenthetical: Bool) @@ -407,8 +434,12 @@ func _currentTest() -> _Test? { enum Kind: Sendable { case unconditional indirect case expectationFailed(_ expectation: Expectation) - indirect case confirmationMiscounted(actual: Int, expected: Int) - indirect case confirmationOutOfRange(actual: Int, expected: any ExpectedCount) + #if compiler(>=6.2) + indirect case confirmationMiscounted(actual: Int, expected: any RangeExpression & Sendable) + #else + indirect case confirmationMiscounted(actual: Int, expected: Int) + indirect case confirmationOutOfRange(actual: Int, expected: any ExpectedCount) + #endif indirect case errorCaught(_ error: any Error) indirect case timeLimitExceeded(timeLimitComponents: (seconds: Int64, attoseconds: Int64)) case knownIssueNotRecorded @@ -416,8 +447,21 @@ func _currentTest() -> _Test? { case system } var kind: Kind + #if compiler(>=6.2) + enum Severity: Sendable { + case warning + case error + } + var severity: Severity + #endif var comments: [Comment] var sourceContext: SourceContext + #if compiler(>=6.2) + struct KnownIssueContext: Sendable { + public var comment: Comment? + } + var knownIssueContext: KnownIssueContext? = nil + #endif } private struct SourceContext: Sendable { @@ -523,7 +567,7 @@ func _currentTest() -> _Test? { > = LockIsolated([:]) var fullyQualifiedNameComponents: [String] { switch _kind { - case let .type(type): + case .type(let type): if let cachedResult = Self ._fullyQualifiedNameComponentsCache.withLock({ $0[ObjectIdentifier(type)] }) { @@ -541,7 +585,7 @@ func _currentTest() -> _Test? { } return result - case let .nameOnly(fullyQualifiedComponents, _, _): + case .nameOnly(let fullyQualifiedComponents, _, _): return fullyQualifiedComponents } } diff --git a/Tests/IssueReportingTests/Support.swift b/Tests/IssueReportingTests/Support.swift new file mode 100644 index 0000000..8e1e756 --- /dev/null +++ b/Tests/IssueReportingTests/Support.swift @@ -0,0 +1,5 @@ +#if compiler(>=6.2) + let issueDescriptionSuffix = " (error)" +#else + let issueDescriptionSuffix = "" +#endif diff --git a/Tests/IssueReportingTests/SwiftTestingTests.swift b/Tests/IssueReportingTests/SwiftTestingTests.swift index 68a3f09..2ea5d57 100644 --- a/Tests/IssueReportingTests/SwiftTestingTests.swift +++ b/Tests/IssueReportingTests/SwiftTestingTests.swift @@ -17,7 +17,7 @@ withKnownIssue { reportIssue() } matching: { issue in - issue.description == "Issue recorded" + issue.description == "Issue recorded\(issueDescriptionSuffix)" } } @@ -26,7 +26,7 @@ withKnownIssue { reportIssue(Failure()) } matching: { issue in - issue.description == "Caught error: Failure()" + issue.description == "Caught error: Failure()\(issueDescriptionSuffix)" } } @@ -34,7 +34,7 @@ withKnownIssue { reportIssue("Something went wrong") } matching: { issue in - issue.description == "Issue recorded: Something went wrong" + issue.description == "Issue recorded\(issueDescriptionSuffix): Something went wrong" } } @@ -42,7 +42,7 @@ withKnownIssue { reportIssue(Failure(), "Something went wrong") } matching: { issue in - issue.description == "Caught error: Failure(): Something went wrong" + issue.description == "Caught error: Failure()\(issueDescriptionSuffix): Something went wrong" } } @@ -74,7 +74,7 @@ withExpectedIssue { } } matching: { issue in - issue.description == "Known issue was not recorded" + issue.description == "Known issue was not recorded\(issueDescriptionSuffix)" } } @@ -84,7 +84,7 @@ await Task.yield() } } matching: { issue in - issue.description == "Known issue was not recorded" + issue.description == "Known issue was not recorded\(issueDescriptionSuffix)" } } @@ -93,7 +93,7 @@ withExpectedIssue("This didn't fail") { } } matching: { issue in - issue.description == "Known issue was not recorded: This didn't fail" + issue.description == "Known issue was not recorded\(issueDescriptionSuffix): This didn't fail" } } @@ -103,7 +103,7 @@ await Task.yield() } } matching: { issue in - issue.description == "Known issue was not recorded: This didn't fail" + issue.description == "Known issue was not recorded\(issueDescriptionSuffix): This didn't fail" } } @@ -126,7 +126,7 @@ } matching: { issue in let expectedReportingLine = #line - 4 return issue.sourceLocation?.line == expectedReportingLine - && issue.description == "Issue recorded: Something went wrong" + && issue.description == "Issue recorded\(issueDescriptionSuffix): Something went wrong" } } diff --git a/Tests/IssueReportingTests/UnimplementedTests.swift b/Tests/IssueReportingTests/UnimplementedTests.swift index 858e30f..ed47857 100644 --- a/Tests/IssueReportingTests/UnimplementedTests.swift +++ b/Tests/IssueReportingTests/UnimplementedTests.swift @@ -15,7 +15,7 @@ model.callback(42) } matching: { issue in issue.description == """ - Issue recorded: Unimplemented … + Issue recorded\(issueDescriptionSuffix): Unimplemented … Defined in 'Model' at: IssueReportingTests/UnimplementedTests.swift:\(model.line) @@ -37,7 +37,7 @@ model.callback() } matching: { issue in issue.description == """ - Issue recorded: Unimplemented … + Issue recorded\(issueDescriptionSuffix): Unimplemented … Defined in 'Model' at: IssueReportingTests/UnimplementedTests.swift:\(model.line) @@ -59,7 +59,7 @@ _ = model.callback() } matching: { issue in issue.description == """ - Issue recorded: Unimplemented … + Issue recorded\(issueDescriptionSuffix): Unimplemented … Defined in 'Model' at: IssueReportingTests/UnimplementedTests.swift:\(model.line) @@ -81,7 +81,7 @@ _ = try model.callback() } matching: { issue in issue.description == """ - Issue recorded: Unimplemented … + Issue recorded\(issueDescriptionSuffix): Unimplemented … Defined in 'Model' at: IssueReportingTests/UnimplementedTests.swift:\(model.line) @@ -90,7 +90,7 @@ () """ || issue.description == """ - Caught error: UnimplementedFailure(description: "") + Caught error: UnimplementedFailure(description: "")\(issueDescriptionSuffix) """ } } @@ -107,7 +107,7 @@ _ = try model.callback() } matching: { issue in issue.description == """ - Issue recorded: Unimplemented … + Issue recorded\(issueDescriptionSuffix): Unimplemented … Defined in 'Model' at: IssueReportingTests/UnimplementedTests.swift:\(model.line) @@ -118,7 +118,7 @@ } } matching: { issue in issue.description == """ - Caught error: UnimplementedFailure(description: "") + Caught error: UnimplementedFailure(description: "")\(issueDescriptionSuffix) """ } } @@ -136,7 +136,7 @@ _ = try model.callback() } matching: { issue in issue.description == """ - Issue recorded: Unimplemented … + Issue recorded\(issueDescriptionSuffix): Unimplemented … Defined in 'Model' at: IssueReportingTests/UnimplementedTests.swift:\(model.line) @@ -147,7 +147,7 @@ } } matching: { issue in issue.description == """ - Caught error: UnimplementedFailure(description: "") + Caught error: UnimplementedFailure(description: "")\(issueDescriptionSuffix) """ } } diff --git a/Tests/IssueReportingTests/WithErrorReportingTests.swift b/Tests/IssueReportingTests/WithErrorReportingTests.swift index 8b7905e..c54b533 100644 --- a/Tests/IssueReportingTests/WithErrorReportingTests.swift +++ b/Tests/IssueReportingTests/WithErrorReportingTests.swift @@ -10,7 +10,7 @@ throw SomeError() } } matching: { issue in - issue.description == "Caught error: SomeError()" + issue.description == "Caught error: SomeError()\(issueDescriptionSuffix)" } withKnownIssue { @@ -18,7 +18,7 @@ throw SomeError() } } matching: { issue in - issue.description == "Caught error: SomeError(): Failed" + issue.description == "Caught error: SomeError()\(issueDescriptionSuffix): Failed" } } @@ -28,7 +28,7 @@ throw SomeError() } } matching: { issue in - issue.description == "Caught error: SomeError()" + issue.description == "Caught error: SomeError()\(issueDescriptionSuffix)" } await withKnownIssue { @@ -36,20 +36,22 @@ throw SomeError() } } matching: { issue in - issue.description == "Caught error: SomeError(): Failed" + issue.description == "Caught error: SomeError()\(issueDescriptionSuffix): Failed" } } - @MainActor - @Test func isolation() async { - await withKnownIssue { - await withErrorReporting { () async throws in - throw SomeError() + #if compiler(<6.2) + @MainActor + @Test func isolation() async { + await withKnownIssue { + await withErrorReporting { () async throws in + throw SomeError() + } + } matching: { issue in + issue.description == "Caught error: SomeError()" } - } matching: { issue in - issue.description == "Caught error: SomeError()" } - } + #endif } private struct SomeError: Error {}