Skip to content

Commit 717e833

Browse files
authored
Add isolation to withExpectedIssue and withIssueContext (#147)
* Add isolation to `withExpectedIssue` and `withIssueContext` * wip
1 parent b444594 commit 717e833

File tree

9 files changed

+377
-167
lines changed

9 files changed

+377
-167
lines changed

Examples/ExamplesTests/SwiftTestingTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@
8888
@Test func withExpectedIssueDoesNotFail() {
8989
withExpectedIssue {}
9090
}
91+
92+
@Test func withExpectedIssueDoesNotFailAsync() async {
93+
await withExpectedIssue {
94+
await Task.yield()
95+
}
96+
}
9197
}
9298
#endif
93-
9499
#endif
95100

96101
private struct Failure: Error {}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# ``IssueReporting/withExpectedIssue(_:isIntermittent:fileID:filePath:line:column:_:)-9pinm``
1+
# ``IssueReporting/withExpectedIssue(_:isIntermittent:fileID:filePath:line:column:_:)``
22

33
## Topics
44

55
### Overloads
66

7-
- ``IssueReporting/withExpectedIssue(_:isIntermittent:fileID:filePath:line:column:_:)-7noz2``
7+
- ``IssueReporting/withExpectedIssue(_:isIntermittent:isolation:fileID:filePath:line:column:_:)``
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# ``IssueReporting/withIssueContext(fileID:filePath:line:column:operation:)-97lux``
1+
# ``IssueReporting/withIssueContext(fileID:filePath:line:column:operation:)``
22

33
## Topics
44

55
### Overloads
66

7-
- ``withIssueContext(fileID:filePath:line:column:operation:)-6o3dr``
7+
- ``withIssueContext(fileID:filePath:line:column:isolation:operation:)``

Sources/IssueReporting/Internal/AppHostWarning.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension String {
3838
3939
For more information (and workarounds), see "Testing gotchas":
4040
41-
https://pointfreeco.github.io/swift-dependencies/main/documentation/dependencies/testing#Testing-gotchas
41+
https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/testing#Testing-gotchas
4242
"""
4343

4444
return isEmpty

Sources/IssueReporting/Internal/SwiftTesting.swift

Lines changed: 141 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func _withKnownIssue(
148148
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
149149
"""
150150
)
151+
try? body()
151152
#endif
152153
return
153154
}
@@ -166,73 +167,151 @@ func _withKnownIssue(
166167
withKnownIssue(message, isIntermittent, fileID, filePath, line, column, body)
167168
}
168169

169-
@usableFromInline
170-
func _withKnownIssue(
171-
_ message: String? = nil,
172-
isIntermittent: Bool = false,
173-
fileID: String = #fileID,
174-
filePath: String = #filePath,
175-
line: Int = #line,
176-
column: Int = #column,
177-
_ body: () async throws -> Void
178-
) async {
179-
guard let function = function(for: "$s25IssueReportingTestSupport010_withKnownA5AsyncypyF")
180-
else {
181-
#if DEBUG
182-
guard
183-
let withKnownIssue = unsafeBitCast(
184-
symbol: """
185-
$s7Testing14withKnownIssue_14isIntermittent14sourceLocation_yAA7CommentVSg_SbAA06Source\
186-
H0VyyYaKXEtYaFTu
187-
""",
188-
in: "Testing",
189-
to: (@convention(thin) (
190-
Any?,
191-
Bool,
192-
SourceLocation,
193-
() async throws -> Void
194-
) async -> Void)
195-
.self
170+
#if compiler(>=6.0.2)
171+
@usableFromInline
172+
func _withKnownIssue(
173+
_ message: String?,
174+
isIntermittent: Bool,
175+
isolation: isolated (any Actor)?,
176+
fileID: String,
177+
filePath: String,
178+
line: Int,
179+
column: Int,
180+
_ body: () async throws -> Void
181+
) async {
182+
guard
183+
let function = function(for: "$s25IssueReportingTestSupport010_withKnownA13AsyncIsolatedypyF")
184+
else {
185+
#if DEBUG
186+
guard
187+
let withKnownIssue = unsafeBitCast(
188+
symbol: """
189+
$s7Testing14withKnownIssue_14isIntermittent9isolation14sourceLocation_yAA7CommentVSg_\
190+
SbScA_pSgYiAA06SourceI0VyyYaKXEtYaF
191+
""",
192+
in: "Testing",
193+
to: (@convention(thin) (
194+
Any?,
195+
Bool,
196+
isolated (any Actor)?,
197+
SourceLocation,
198+
() async throws -> Void
199+
) async -> Void)
200+
.self
201+
)
202+
else { return }
203+
204+
var comment: Any?
205+
if let message {
206+
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
207+
c.rawValue = message
208+
comment = c
209+
}
210+
await withKnownIssue(
211+
comment,
212+
isIntermittent,
213+
isolation,
214+
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column),
215+
body
196216
)
197-
else { return }
217+
#else
218+
printError(
219+
"""
220+
\(fileID):\(line): A known issue was recorded without linking the Testing framework.
198221
199-
var comment: Any?
200-
if let message {
201-
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
202-
c.rawValue = message
203-
comment = c
204-
}
205-
await withKnownIssue(
206-
comment,
207-
isIntermittent,
208-
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column),
209-
body
210-
)
211-
#else
212-
printError(
213-
"""
214-
\(fileID):\(line): A known issue was recorded without linking the Testing framework.
222+
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
223+
"""
224+
)
225+
try? await body()
226+
#endif
227+
return
228+
}
215229

216-
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
217-
"""
218-
)
219-
#endif
220-
return
230+
let withKnownIssue =
231+
function
232+
as! @Sendable (
233+
String?,
234+
Bool,
235+
isolated (any Actor)?,
236+
String,
237+
String,
238+
Int,
239+
Int,
240+
() async throws -> Void
241+
) async -> Void
242+
await withKnownIssue(message, isIntermittent, isolation, fileID, filePath, line, column, body)
221243
}
244+
#else
245+
@usableFromInline
246+
func _withKnownIssue(
247+
_ message: String?,
248+
isIntermittent: Bool,
249+
fileID: String,
250+
filePath: String,
251+
line: Int,
252+
column: Int,
253+
_ body: () async throws -> Void
254+
) async {
255+
guard let function = function(for: "$s25IssueReportingTestSupport010_withKnownA5AsyncypyF")
256+
else {
257+
#if DEBUG
258+
guard
259+
let withKnownIssue = unsafeBitCast(
260+
symbol: """
261+
$s7Testing14withKnownIssue_14isIntermittent14sourceLocation_yAA7CommentVSg_SbAA06Sour\
262+
ceH0VyyYaKXEtYaFTu
263+
""",
264+
in: "Testing",
265+
to: (@convention(thin) (
266+
Any?,
267+
Bool,
268+
SourceLocation,
269+
() async throws -> Void
270+
) async -> Void)
271+
.self
272+
)
273+
else { return }
274+
275+
var comment: Any?
276+
if let message {
277+
var c = UnsafeMutablePointer<Comment>.allocate(capacity: 1).pointee
278+
c.rawValue = message
279+
comment = c
280+
}
281+
await withKnownIssue(
282+
comment,
283+
isIntermittent,
284+
SourceLocation(fileID: fileID, _filePath: filePath, line: line, column: column),
285+
body
286+
)
287+
#else
288+
printError(
289+
"""
290+
\(fileID):\(line): A known issue was recorded without linking the Testing framework.
291+
292+
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
293+
"""
294+
)
295+
#endif
296+
return
297+
}
298+
299+
let withKnownIssue =
300+
function
301+
as! @Sendable (
302+
String?,
303+
Bool,
304+
String,
305+
String,
306+
Int,
307+
Int,
308+
() async throws -> Void
309+
) async -> Void
310+
await withKnownIssue(message, isIntermittent, fileID, filePath, line, column, body)
311+
}
312+
313+
#endif
222314

223-
let withKnownIssue =
224-
function
225-
as! @Sendable (
226-
String?,
227-
Bool,
228-
String,
229-
String,
230-
Int,
231-
Int,
232-
() async throws -> Void
233-
) async -> Void
234-
await withKnownIssue(message, isIntermittent, fileID, filePath, line, column, body)
235-
}
236315
@usableFromInline
237316
func _currentTestID() -> AnyHashable? {
238317
guard let function = function(for: "$s25IssueReportingTestSupport08_currentC2IDypyF")

Sources/IssueReporting/Internal/XCTest.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func _XCTFail(
3333
#endif
3434
printError(
3535
"""
36-
\(file):\(line): A failure was recorded without linking the XCTest framework.
36+
\(file):\(line): A failure was recorded without linking the XCTest framework\
37+
\(message.isEmpty ? "" : ": \(message)")
3738
3839
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
3940
"""

0 commit comments

Comments
 (0)