Skip to content

Commit 027930a

Browse files
authored
Xcode 26 (Swift 6.2) fixes (#167)
1 parent 23e3442 commit 027930a

File tree

5 files changed

+103
-52
lines changed

5 files changed

+103
-52
lines changed

Sources/IssueReporting/Internal/SwiftTesting.swift

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,49 @@ func _recordIssue(
1616
guard let function = function(for: "$s25IssueReportingTestSupport07_recordA0ypyF")
1717
else {
1818
#if DEBUG && canImport(Darwin)
19-
guard
20-
let record = unsafeBitCast(
21-
symbol: "$s7Testing5IssueV6record_14sourceLocationAcA7CommentVSg_AA06SourceE0VtFZ",
22-
in: "Testing",
23-
to: (@convention(thin) (Any?, SourceLocation) -> Issue).self
19+
#if compiler(>=6.2)
20+
guard
21+
let record = unsafeBitCast(
22+
symbol: """
23+
$s7Testing5IssueV6record_8severity14sourceLocationAcA7CommentVSg_AC8SeverityOAA06Sour\
24+
ceF0VtFZ
25+
""",
26+
in: "Testing",
27+
to: (@convention(thin) (Any?, Any, SourceLocation) -> Issue).self
28+
)
29+
else { return }
30+
31+
var comment: Any?
32+
if let message {
33+
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
34+
c.rawValue = message
35+
comment = c
36+
}
37+
_ = record(
38+
comment,
39+
Issue.Severity.error, // TODO: Support other severities?
40+
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column)
2441
)
25-
else { return }
42+
#else
43+
guard
44+
let record = unsafeBitCast(
45+
symbol: "$s7Testing5IssueV6record_14sourceLocationAcA7CommentVSg_AA06SourceE0VtFZ",
46+
in: "Testing",
47+
to: (@convention(thin) (Any?, SourceLocation) -> Issue).self
48+
)
49+
else { return }
2650

27-
var comment: Any?
28-
if let message {
29-
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
30-
c.rawValue = message
31-
comment = c
32-
}
33-
_ = record(
34-
comment,
35-
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column)
36-
)
51+
var comment: Any?
52+
if let message {
53+
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
54+
c.rawValue = message
55+
comment = c
56+
}
57+
_ = record(
58+
comment,
59+
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column)
60+
)
61+
#endif
3762
#else
3863
printError(
3964
"""
@@ -188,7 +213,7 @@ func _withKnownIssue(
188213
let withKnownIssue = unsafeBitCast(
189214
symbol: """
190215
$s7Testing14withKnownIssue_14isIntermittent9isolation14sourceLocation_yAA7CommentVSg_\
191-
SbScA_pSgYiAA06SourceI0VyyYaKXEtYaF
216+
SbScA_pSgYiAA06SourceI0VyyYaKXEtYaFTu
192217
""",
193218
in: "Testing",
194219
to: (@convention(thin) (
@@ -350,7 +375,9 @@ func _currentTest() -> _Test? {
350375
var value: __Expression
351376
}
352377
indirect case functionCall(
353-
value: __Expression?, functionName: String, arguments: [FunctionCallArgument]
378+
value: __Expression?,
379+
functionName: String,
380+
arguments: [FunctionCallArgument]
354381
)
355382
indirect case propertyAccess(value: __Expression, keyPath: __Expression)
356383
indirect case negation(_ expression: __Expression, isParenthetical: Bool)
@@ -407,17 +434,34 @@ func _currentTest() -> _Test? {
407434
enum Kind: Sendable {
408435
case unconditional
409436
indirect case expectationFailed(_ expectation: Expectation)
410-
indirect case confirmationMiscounted(actual: Int, expected: Int)
411-
indirect case confirmationOutOfRange(actual: Int, expected: any ExpectedCount)
437+
#if compiler(>=6.2)
438+
indirect case confirmationMiscounted(actual: Int, expected: any RangeExpression & Sendable)
439+
#else
440+
indirect case confirmationMiscounted(actual: Int, expected: Int)
441+
indirect case confirmationOutOfRange(actual: Int, expected: any ExpectedCount)
442+
#endif
412443
indirect case errorCaught(_ error: any Error)
413444
indirect case timeLimitExceeded(timeLimitComponents: (seconds: Int64, attoseconds: Int64))
414445
case knownIssueNotRecorded
415446
case apiMisused
416447
case system
417448
}
418449
var kind: Kind
450+
#if compiler(>=6.2)
451+
enum Severity: Sendable {
452+
case warning
453+
case error
454+
}
455+
var severity: Severity
456+
#endif
419457
var comments: [Comment]
420458
var sourceContext: SourceContext
459+
#if compiler(>=6.2)
460+
struct KnownIssueContext: Sendable {
461+
public var comment: Comment?
462+
}
463+
var knownIssueContext: KnownIssueContext? = nil
464+
#endif
421465
}
422466

423467
private struct SourceContext: Sendable {
@@ -523,7 +567,7 @@ func _currentTest() -> _Test? {
523567
> = LockIsolated([:])
524568
var fullyQualifiedNameComponents: [String] {
525569
switch _kind {
526-
case let .type(type):
570+
case .type(let type):
527571
if let cachedResult = Self
528572
._fullyQualifiedNameComponentsCache.withLock({ $0[ObjectIdentifier(type)] })
529573
{
@@ -541,7 +585,7 @@ func _currentTest() -> _Test? {
541585
}
542586
return result
543587

544-
case let .nameOnly(fullyQualifiedComponents, _, _):
588+
case .nameOnly(let fullyQualifiedComponents, _, _):
545589
return fullyQualifiedComponents
546590
}
547591
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#if compiler(>=6.2)
2+
let issueDescriptionSuffix = " (error)"
3+
#else
4+
let issueDescriptionSuffix = ""
5+
#endif

Tests/IssueReportingTests/SwiftTestingTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
withKnownIssue {
1818
reportIssue()
1919
} matching: { issue in
20-
issue.description == "Issue recorded"
20+
issue.description == "Issue recorded\(issueDescriptionSuffix)"
2121
}
2222
}
2323

@@ -26,23 +26,23 @@
2626
withKnownIssue {
2727
reportIssue(Failure())
2828
} matching: { issue in
29-
issue.description == "Caught error: Failure()"
29+
issue.description == "Caught error: Failure()\(issueDescriptionSuffix)"
3030
}
3131
}
3232

3333
@Test func reportIssue_CustomMessage() {
3434
withKnownIssue {
3535
reportIssue("Something went wrong")
3636
} matching: { issue in
37-
issue.description == "Issue recorded: Something went wrong"
37+
issue.description == "Issue recorded\(issueDescriptionSuffix): Something went wrong"
3838
}
3939
}
4040

4141
@Test func reportError_CustomMessage() {
4242
withKnownIssue {
4343
reportIssue(Failure(), "Something went wrong")
4444
} matching: { issue in
45-
issue.description == "Caught error: Failure(): Something went wrong"
45+
issue.description == "Caught error: Failure()\(issueDescriptionSuffix): Something went wrong"
4646
}
4747
}
4848

@@ -74,7 +74,7 @@
7474
withExpectedIssue {
7575
}
7676
} matching: { issue in
77-
issue.description == "Known issue was not recorded"
77+
issue.description == "Known issue was not recorded\(issueDescriptionSuffix)"
7878
}
7979
}
8080

@@ -84,7 +84,7 @@
8484
await Task.yield()
8585
}
8686
} matching: { issue in
87-
issue.description == "Known issue was not recorded"
87+
issue.description == "Known issue was not recorded\(issueDescriptionSuffix)"
8888
}
8989
}
9090

@@ -93,7 +93,7 @@
9393
withExpectedIssue("This didn't fail") {
9494
}
9595
} matching: { issue in
96-
issue.description == "Known issue was not recorded: This didn't fail"
96+
issue.description == "Known issue was not recorded\(issueDescriptionSuffix): This didn't fail"
9797
}
9898
}
9999

@@ -103,7 +103,7 @@
103103
await Task.yield()
104104
}
105105
} matching: { issue in
106-
issue.description == "Known issue was not recorded: This didn't fail"
106+
issue.description == "Known issue was not recorded\(issueDescriptionSuffix): This didn't fail"
107107
}
108108
}
109109

@@ -126,7 +126,7 @@
126126
} matching: { issue in
127127
let expectedReportingLine = #line - 4
128128
return issue.sourceLocation?.line == expectedReportingLine
129-
&& issue.description == "Issue recorded: Something went wrong"
129+
&& issue.description == "Issue recorded\(issueDescriptionSuffix): Something went wrong"
130130
}
131131
}
132132

Tests/IssueReportingTests/UnimplementedTests.swift

Lines changed: 9 additions & 9 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-
Issue recorded: Unimplemented …
18+
Issue recorded\(issueDescriptionSuffix): 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-
Issue recorded: Unimplemented …
40+
Issue recorded\(issueDescriptionSuffix): 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-
Issue recorded: Unimplemented …
62+
Issue recorded\(issueDescriptionSuffix): 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-
Issue recorded: Unimplemented …
84+
Issue recorded\(issueDescriptionSuffix): Unimplemented …
8585
8686
Defined in 'Model' at:
8787
IssueReportingTests/UnimplementedTests.swift:\(model.line)
@@ -90,7 +90,7 @@
9090
()
9191
"""
9292
|| issue.description == """
93-
Caught error: UnimplementedFailure(description: "")
93+
Caught error: UnimplementedFailure(description: "")\(issueDescriptionSuffix)
9494
"""
9595
}
9696
}
@@ -107,7 +107,7 @@
107107
_ = try model.callback()
108108
} matching: { issue in
109109
issue.description == """
110-
Issue recorded: Unimplemented …
110+
Issue recorded\(issueDescriptionSuffix): Unimplemented …
111111
112112
Defined in 'Model' at:
113113
IssueReportingTests/UnimplementedTests.swift:\(model.line)
@@ -118,7 +118,7 @@
118118
}
119119
} matching: { issue in
120120
issue.description == """
121-
Caught error: UnimplementedFailure(description: "")
121+
Caught error: UnimplementedFailure(description: "")\(issueDescriptionSuffix)
122122
"""
123123
}
124124
}
@@ -136,7 +136,7 @@
136136
_ = try model.callback()
137137
} matching: { issue in
138138
issue.description == """
139-
Issue recorded: Unimplemented …
139+
Issue recorded\(issueDescriptionSuffix): Unimplemented …
140140
141141
Defined in 'Model' at:
142142
IssueReportingTests/UnimplementedTests.swift:\(model.line)
@@ -147,7 +147,7 @@
147147
}
148148
} matching: { issue in
149149
issue.description == """
150-
Caught error: UnimplementedFailure(description: "")
150+
Caught error: UnimplementedFailure(description: "")\(issueDescriptionSuffix)
151151
"""
152152
}
153153
}

Tests/IssueReportingTests/WithErrorReportingTests.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
throw SomeError()
1111
}
1212
} matching: { issue in
13-
issue.description == "Caught error: SomeError()"
13+
issue.description == "Caught error: SomeError()\(issueDescriptionSuffix)"
1414
}
1515

1616
withKnownIssue {
1717
withErrorReporting("Failed") {
1818
throw SomeError()
1919
}
2020
} matching: { issue in
21-
issue.description == "Caught error: SomeError(): Failed"
21+
issue.description == "Caught error: SomeError()\(issueDescriptionSuffix): Failed"
2222
}
2323
}
2424

@@ -28,28 +28,30 @@
2828
throw SomeError()
2929
}
3030
} matching: { issue in
31-
issue.description == "Caught error: SomeError()"
31+
issue.description == "Caught error: SomeError()\(issueDescriptionSuffix)"
3232
}
3333

3434
await withKnownIssue {
3535
await withErrorReporting("Failed") { () async throws in
3636
throw SomeError()
3737
}
3838
} matching: { issue in
39-
issue.description == "Caught error: SomeError(): Failed"
39+
issue.description == "Caught error: SomeError()\(issueDescriptionSuffix): Failed"
4040
}
4141
}
4242

43-
@MainActor
44-
@Test func isolation() async {
45-
await withKnownIssue {
46-
await withErrorReporting { () async throws in
47-
throw SomeError()
43+
#if compiler(<6.2)
44+
@MainActor
45+
@Test func isolation() async {
46+
await withKnownIssue {
47+
await withErrorReporting { () async throws in
48+
throw SomeError()
49+
}
50+
} matching: { issue in
51+
issue.description == "Caught error: SomeError()"
4852
}
49-
} matching: { issue in
50-
issue.description == "Caught error: SomeError()"
5153
}
52-
}
54+
#endif
5355
}
5456

5557
private struct SomeError: Error {}

0 commit comments

Comments
 (0)