Skip to content

Commit 9829b6a

Browse files
authored
Update reportIssue to call Issue.record (#116)
We should be calling to this more stable interface now that the messaging has been updated.
1 parent c6809a1 commit 9829b6a

File tree

4 files changed

+76
-69
lines changed

4 files changed

+76
-69
lines changed

Sources/IssueReporting/Internal/SwiftTesting.swift

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,21 @@ func _recordIssue(
1616
else {
1717
#if DEBUG
1818
guard
19-
let fromSyntaxNode = unsafeBitCast(
20-
symbol: "$s7Testing12__ExpressionV16__fromSyntaxNodeyACSSFZ",
21-
in: "Testing",
22-
to: (@convention(thin) (String) -> __Expression).self
23-
),
24-
let checkValue = unsafeBitCast(
25-
symbol: """
26-
$s7Testing12__checkValue_10expression0D25WithCapturedRuntimeValues26mismatchedErrorDesc\
27-
ription10difference8comments10isRequired14sourceLocations6ResultOyyts0J0_pGSb_AA12__Exp\
28-
ressionVAOSgyXKSSSgyXKAQyXKSayAA7CommentVGyXKSbAA06SourceQ0VtF
29-
""",
19+
let record = unsafeBitCast(
20+
symbol: "$s7Testing5IssueV6record_14sourceLocationAcA7CommentVSg_AA06SourceE0VtFZ",
3021
in: "Testing",
31-
to: (@convention(thin) (
32-
Bool,
33-
__Expression,
34-
@autoclosure () -> __Expression?,
35-
@autoclosure () -> String?,
36-
@autoclosure () -> String?,
37-
@autoclosure () -> [Any],
38-
Bool,
39-
SourceLocation
40-
) -> Result<Void, any Error>)
41-
.self
22+
to: (@convention(thin) (Any?, SourceLocation) -> Issue).self
4223
)
4324
else { return }
4425

45-
let syntaxNode = fromSyntaxNode(message ?? "")
46-
_ = checkValue(
47-
false,
48-
syntaxNode,
49-
nil,
50-
nil,
51-
nil,
52-
[],
53-
false,
26+
var comment: Any?
27+
if let message {
28+
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
29+
c.rawValue = message
30+
comment = c
31+
}
32+
_ = record(
33+
comment,
5434
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column)
5535
)
5636
#else
@@ -87,7 +67,7 @@ func _recordError(
8767
$s7Testing5IssueV6record__14sourceLocationACs5Error_p_AA7CommentVSgAA06SourceE0VtFZ
8868
""",
8969
in: "Testing",
90-
to: (@convention(thin) (any Error, Any?, SourceLocation) -> Any).self
70+
to: (@convention(thin) (any Error, Any?, SourceLocation) -> Issue).self
9171
)
9272
else { return }
9373

@@ -310,19 +290,9 @@ func _currentTestIsNotNil() -> Bool {
310290
var runtimeValue: Value?
311291
}
312292

313-
private struct TypeInfo: Sendable {
314-
enum _Kind: Sendable {
315-
case type(_ type: Any.Type)
316-
case nameOnly(fullyQualifiedComponents: [String], unqualified: String, mangled: String?)
317-
}
318-
var _kind: _Kind
319-
}
320-
321-
private struct SourceLocation: Sendable {
322-
var fileID: String
323-
var _filePath: String
324-
var line: Int
325-
var column: Int
293+
private struct Backtrace: Sendable {
294+
typealias Address = UInt64
295+
var addresses: [Address]
326296
}
327297

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

345-
private protocol Trait: Sendable {}
315+
private struct Confirmation: Sendable {
316+
protocol ExpectedCount: Sendable, RangeExpression<Int> {}
317+
}
318+
319+
private struct Expectation: Sendable {
320+
var evaluatedExpression: __Expression
321+
var mismatchedErrorDescription: String?
322+
var differenceDescription: String?
323+
var mismatchedExitConditionDescription: String?
324+
var isPassing: Bool
325+
var isRequired: Bool
326+
var sourceLocation: SourceLocation
327+
}
328+
329+
private struct Issue: Sendable {
330+
enum Kind: Sendable {
331+
case unconditional
332+
indirect case expectationFailed(_ expectation: Expectation)
333+
indirect case confirmationMiscounted(actual: Int, expected: Int)
334+
indirect case confirmationOutOfRange(actual: Int, expected: any Confirmation.ExpectedCount)
335+
indirect case errorCaught(_ error: any Error)
336+
indirect case timeLimitExceeded(timeLimitComponents: (seconds: Int64, attoseconds: Int64))
337+
case knownIssueNotRecorded
338+
case apiMisused
339+
case system
340+
}
341+
var kind: Kind
342+
var comments: [Comment]
343+
var sourceContext: SourceContext
344+
}
345+
346+
private struct SourceContext: Sendable {
347+
var backtrace: Backtrace?
348+
var sourceLocation: SourceLocation?
349+
}
350+
351+
private struct SourceLocation: Sendable {
352+
var fileID: String
353+
var _filePath: String
354+
var line: Int
355+
var column: Int
356+
}
346357

347358
struct Test: @unchecked Sendable {
348359
static var current: Self? {
@@ -378,6 +389,16 @@ func _currentTestIsNotNil() -> Bool {
378389
}
379390
private var isSynthesized = false
380391
}
392+
393+
private protocol Trait: Sendable {}
394+
395+
private struct TypeInfo: Sendable {
396+
enum _Kind: Sendable {
397+
case type(_ type: Any.Type)
398+
case nameOnly(fullyQualifiedComponents: [String], unqualified: String, mangled: String?)
399+
}
400+
var _kind: _Kind
401+
}
381402
#endif
382403

383404
@usableFromInline

Sources/IssueReportingTestSupport/SwiftTesting.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,15 @@ private func __recordIssue(
1212
column: Int
1313
) {
1414
#if canImport(Testing)
15-
// NB: https://github.com/apple/swift-testing/issues/490
16-
// Issue.record(
17-
// message.map(Comment.init(rawValue:)),
18-
// sourceLocation: SourceLocation(
19-
// fileID: fileID,
20-
// filePath: filePath,
21-
// line: line,
22-
// column: column
23-
// )
24-
// )
25-
__checkValue(
26-
false,
27-
expression: .__fromSyntaxNode(message ?? ""),
28-
comments: [],
29-
isRequired: false,
15+
Issue.record(
16+
message.map(Comment.init(rawValue:)),
3017
sourceLocation: SourceLocation(
3118
fileID: fileID,
3219
filePath: filePath,
3320
line: line,
3421
column: column
3522
)
3623
)
37-
.__expected()
3824
#endif
3925
}
4026

Tests/IssueReportingTests/SwiftTestingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
withKnownIssue {
1313
reportIssue()
1414
} matching: { issue in
15-
issue.description == "Expectation failed: "
15+
issue.description == "Issue recorded"
1616
}
1717
}
1818

@@ -29,7 +29,7 @@
2929
withKnownIssue {
3030
reportIssue("Something went wrong")
3131
} matching: { issue in
32-
issue.description == "Expectation failed: Something went wrong"
32+
issue.description == "Issue recorded: Something went wrong"
3333
}
3434
}
3535

Tests/IssueReportingTests/UnimplementedTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
model.callback(42)
1616
} matching: { issue in
1717
issue.description == """
18-
Expectation failed: Unimplemented …
18+
Issue recorded: Unimplemented …
1919
2020
Defined in 'Model' at:
2121
IssueReportingTests/UnimplementedTests.swift:\(model.line)
@@ -37,7 +37,7 @@
3737
model.callback()
3838
} matching: { issue in
3939
issue.description == """
40-
Expectation failed: Unimplemented …
40+
Issue recorded: Unimplemented …
4141
4242
Defined in 'Model' at:
4343
IssueReportingTests/UnimplementedTests.swift:\(model.line)
@@ -59,7 +59,7 @@
5959
_ = model.callback()
6060
} matching: { issue in
6161
issue.description == """
62-
Expectation failed: Unimplemented …
62+
Issue recorded: Unimplemented …
6363
6464
Defined in 'Model' at:
6565
IssueReportingTests/UnimplementedTests.swift:\(model.line)
@@ -81,7 +81,7 @@
8181
_ = try model.callback()
8282
} matching: { issue in
8383
issue.description == """
84-
Expectation failed: Unimplemented …
84+
Issue recorded: Unimplemented …
8585
8686
Defined in 'Model' at:
8787
IssueReportingTests/UnimplementedTests.swift:\(model.line)
@@ -107,7 +107,7 @@
107107
_ = try model.callback()
108108
} matching: { issue in
109109
issue.description == """
110-
Expectation failed: Unimplemented …
110+
Issue recorded: Unimplemented …
111111
112112
Defined in 'Model' at:
113113
IssueReportingTests/UnimplementedTests.swift:\(model.line)

0 commit comments

Comments
 (0)