Skip to content

Commit

Permalink
Update reportIssue to call Issue.record (#116)
Browse files Browse the repository at this point in the history
We should be calling to this more stable interface now that the
messaging has been updated.
  • Loading branch information
stephencelis authored Aug 19, 2024
1 parent c6809a1 commit 9829b6a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 69 deletions.
113 changes: 67 additions & 46 deletions Sources/IssueReporting/Internal/SwiftTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,21 @@ func _recordIssue(
else {
#if DEBUG
guard
let fromSyntaxNode = unsafeBitCast(
symbol: "$s7Testing12__ExpressionV16__fromSyntaxNodeyACSSFZ",
in: "Testing",
to: (@convention(thin) (String) -> __Expression).self
),
let checkValue = unsafeBitCast(
symbol: """
$s7Testing12__checkValue_10expression0D25WithCapturedRuntimeValues26mismatchedErrorDesc\
ription10difference8comments10isRequired14sourceLocations6ResultOyyts0J0_pGSb_AA12__Exp\
ressionVAOSgyXKSSSgyXKAQyXKSayAA7CommentVGyXKSbAA06SourceQ0VtF
""",
let record = unsafeBitCast(
symbol: "$s7Testing5IssueV6record_14sourceLocationAcA7CommentVSg_AA06SourceE0VtFZ",
in: "Testing",
to: (@convention(thin) (
Bool,
__Expression,
@autoclosure () -> __Expression?,
@autoclosure () -> String?,
@autoclosure () -> String?,
@autoclosure () -> [Any],
Bool,
SourceLocation
) -> Result<Void, any Error>)
.self
to: (@convention(thin) (Any?, SourceLocation) -> Issue).self
)
else { return }

let syntaxNode = fromSyntaxNode(message ?? "")
_ = checkValue(
false,
syntaxNode,
nil,
nil,
nil,
[],
false,
var comment: Any?
if let message {
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
c.rawValue = message
comment = c
}
_ = record(
comment,
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column)
)
#else
Expand Down Expand Up @@ -87,7 +67,7 @@ func _recordError(
$s7Testing5IssueV6record__14sourceLocationACs5Error_p_AA7CommentVSgAA06SourceE0VtFZ
""",
in: "Testing",
to: (@convention(thin) (any Error, Any?, SourceLocation) -> Any).self
to: (@convention(thin) (any Error, Any?, SourceLocation) -> Issue).self
)
else { return }

Expand Down Expand Up @@ -310,19 +290,9 @@ func _currentTestIsNotNil() -> Bool {
var runtimeValue: Value?
}

private struct TypeInfo: Sendable {
enum _Kind: Sendable {
case type(_ type: Any.Type)
case nameOnly(fullyQualifiedComponents: [String], unqualified: String, mangled: String?)
}
var _kind: _Kind
}

private struct SourceLocation: Sendable {
var fileID: String
var _filePath: String
var line: Int
var column: Int
private struct Backtrace: Sendable {
typealias Address = UInt64
var addresses: [Address]
}

private struct Comment: RawRepresentable, Sendable {
Expand All @@ -342,7 +312,48 @@ func _currentTestIsNotNil() -> Bool {
var kind: Kind?
}

private protocol Trait: Sendable {}
private struct Confirmation: Sendable {
protocol ExpectedCount: Sendable, RangeExpression<Int> {}
}

private struct Expectation: Sendable {
var evaluatedExpression: __Expression
var mismatchedErrorDescription: String?
var differenceDescription: String?
var mismatchedExitConditionDescription: String?
var isPassing: Bool
var isRequired: Bool
var sourceLocation: SourceLocation
}

private struct Issue: Sendable {
enum Kind: Sendable {
case unconditional
indirect case expectationFailed(_ expectation: Expectation)
indirect case confirmationMiscounted(actual: Int, expected: Int)
indirect case confirmationOutOfRange(actual: Int, expected: any Confirmation.ExpectedCount)
indirect case errorCaught(_ error: any Error)
indirect case timeLimitExceeded(timeLimitComponents: (seconds: Int64, attoseconds: Int64))
case knownIssueNotRecorded
case apiMisused
case system
}
var kind: Kind
var comments: [Comment]
var sourceContext: SourceContext
}

private struct SourceContext: Sendable {
var backtrace: Backtrace?
var sourceLocation: SourceLocation?
}

private struct SourceLocation: Sendable {
var fileID: String
var _filePath: String
var line: Int
var column: Int
}

struct Test: @unchecked Sendable {
static var current: Self? {
Expand Down Expand Up @@ -378,6 +389,16 @@ func _currentTestIsNotNil() -> Bool {
}
private var isSynthesized = false
}

private protocol Trait: Sendable {}

private struct TypeInfo: Sendable {
enum _Kind: Sendable {
case type(_ type: Any.Type)
case nameOnly(fullyQualifiedComponents: [String], unqualified: String, mangled: String?)
}
var _kind: _Kind
}
#endif

@usableFromInline
Expand Down
18 changes: 2 additions & 16 deletions Sources/IssueReportingTestSupport/SwiftTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,15 @@ private func __recordIssue(
column: Int
) {
#if canImport(Testing)
// NB: https://github.com/apple/swift-testing/issues/490
// Issue.record(
// message.map(Comment.init(rawValue:)),
// sourceLocation: SourceLocation(
// fileID: fileID,
// filePath: filePath,
// line: line,
// column: column
// )
// )
__checkValue(
false,
expression: .__fromSyntaxNode(message ?? ""),
comments: [],
isRequired: false,
Issue.record(
message.map(Comment.init(rawValue:)),
sourceLocation: SourceLocation(
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
)
.__expected()
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/IssueReportingTests/SwiftTestingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
withKnownIssue {
reportIssue()
} matching: { issue in
issue.description == "Expectation failed: "
issue.description == "Issue recorded"
}
}

Expand All @@ -29,7 +29,7 @@
withKnownIssue {
reportIssue("Something went wrong")
} matching: { issue in
issue.description == "Expectation failed: Something went wrong"
issue.description == "Issue recorded: Something went wrong"
}
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/IssueReportingTests/UnimplementedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
model.callback(42)
} matching: { issue in
issue.description == """
Expectation failed: Unimplemented …
Issue recorded: Unimplemented …
Defined in 'Model' at:
IssueReportingTests/UnimplementedTests.swift:\(model.line)
Expand All @@ -37,7 +37,7 @@
model.callback()
} matching: { issue in
issue.description == """
Expectation failed: Unimplemented …
Issue recorded: Unimplemented …
Defined in 'Model' at:
IssueReportingTests/UnimplementedTests.swift:\(model.line)
Expand All @@ -59,7 +59,7 @@
_ = model.callback()
} matching: { issue in
issue.description == """
Expectation failed: Unimplemented …
Issue recorded: Unimplemented …
Defined in 'Model' at:
IssueReportingTests/UnimplementedTests.swift:\(model.line)
Expand All @@ -81,7 +81,7 @@
_ = try model.callback()
} matching: { issue in
issue.description == """
Expectation failed: Unimplemented …
Issue recorded: Unimplemented …
Defined in 'Model' at:
IssueReportingTests/UnimplementedTests.swift:\(model.line)
Expand All @@ -107,7 +107,7 @@
_ = try model.callback()
} matching: { issue in
issue.description == """
Expectation failed: Unimplemented …
Issue recorded: Unimplemented …
Defined in 'Model' at:
IssueReportingTests/UnimplementedTests.swift:\(model.line)
Expand Down

0 comments on commit 9829b6a

Please sign in to comment.