Skip to content

Commit ad12715

Browse files
committed
wip
1 parent ac259c9 commit ad12715

File tree

3 files changed

+75
-84
lines changed

3 files changed

+75
-84
lines changed

Sources/IssueReporting/Internal/SwiftTesting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func _currentTestIsNotNil() -> Bool {
273273
func function(for symbol: String) -> Any? {
274274
#if os(Linux)
275275
guard
276-
let handle = dlopen("Testing.so", RTLD_LAZY),
276+
let handle = dlopen("libTesting.so", RTLD_LAZY),
277277
let pointer = dlsym(handle, symbol)
278278
else { return nil }
279279
return unsafeBitCast(pointer, to: DynamicFunction.self)()

Sources/IssueReporting/Internal/XCTest.swift

Lines changed: 73 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func _XCTFail(
1616
file: StaticString = #filePath,
1717
line: UInt = #line
1818
) {
19+
#if !_runtime(_ObjC)
20+
guard !_XCTExpectedFailure.isInFailingBlock else { return }
21+
#endif
1922
guard let function = function(for: "$s25IssueReportingTestSupport8_XCTFailypyF")
2023
else {
2124
#if DEBUG
@@ -30,28 +33,24 @@ func _XCTFail(
3033
return nil
3134
#endif
3235
}
33-
34-
guard
35-
!_XCTExpectedFailure.isInFailingBlock,
36-
let pointer
37-
else { return }
38-
let XCTFail = unsafeBitCast(
39-
pointer,
40-
to: (@convention(thin) (String, StaticString, UInt) -> Void).self
41-
)
42-
XCTFail(message, file, line)
43-
#else
44-
fputs("""
45-
\(file):\(line): A failure was recorded without linking the XCTest framework.
46-
47-
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
48-
""",
49-
stderr
50-
)
36+
if let pointer {
37+
let XCTFail = unsafeBitCast(
38+
pointer,
39+
to: (@convention(thin) (String, StaticString, UInt) -> Void).self
40+
)
41+
XCTFail(message, file, line)
42+
return
43+
}
5144
#endif
45+
fputs("""
46+
\(file):\(line): A failure was recorded without linking the XCTest framework.
47+
48+
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
49+
""",
50+
stderr
51+
)
5252
return
5353
}
54-
5554
let XCTFail = function as! @Sendable (String, StaticString, UInt) -> Void
5655
XCTFail(message, file, line)
5756
}
@@ -66,73 +65,72 @@ func _XCTExpectFailure<R>(
6665
line: UInt,
6766
failingBlock: () throws -> R
6867
) rethrows -> R {
69-
guard let function = function(for: "$s25IssueReportingTestSupport17_XCTExpectFailureypyF")
70-
else {
71-
#if DEBUG
72-
guard enabled != false
73-
else {
74-
return try failingBlock()
75-
}
76-
#if _runtime(_ObjC)
77-
guard
78-
let xctExpectFailureInBlockPtr = dlsym(
79-
dlopen(nil, RTLD_NOW),
80-
"XCTExpectFailureWithOptionsInBlock"
81-
),
82-
let xctExpectedFailureOptions = NSClassFromString("XCTExpectedFailureOptions")
68+
#if _runtime(_ObjC)
69+
guard let function = function(for: "$s25IssueReportingTestSupport17_XCTExpectFailureypyF")
70+
else {
71+
#if DEBUG
72+
guard enabled != false
73+
else { return try failingBlock() }
74+
if let pointer = dlsym(dlopen(nil, RTLD_NOW), "XCTExpectFailureWithOptionsInBlock"),
75+
let XCTExpectedFailureOptions = NSClassFromString("XCTExpectedFailureOptions")
8376
as Any as? NSObjectProtocol,
8477
let options = strict ?? true
85-
? xctExpectedFailureOptions
78+
? XCTExpectedFailureOptions
8679
.perform(NSSelectorFromString("alloc"))?.takeUnretainedValue()
8780
.perform(NSSelectorFromString("init"))?.takeUnretainedValue()
88-
: xctExpectedFailureOptions
81+
: XCTExpectedFailureOptions
8982
.perform(NSSelectorFromString("nonStrictOptions"))?.takeUnretainedValue()
90-
else {
91-
return try failingBlock()
92-
}
93-
let xctExpectFailureInBlock = unsafeBitCast(
94-
xctExpectFailureInBlockPtr,
95-
to: (@convention(c) (String?, AnyObject, () -> Void) -> Void).self
96-
)
97-
var result: Result<R, any Error>!
98-
xctExpectFailureInBlock(failureReason, options) {
99-
result = Result { try failingBlock() }
83+
{
84+
let XCTExpectFailureInBlock = unsafeBitCast(
85+
pointer,
86+
to: (@convention(c) (String?, AnyObject, () -> Void) -> Void).self
87+
)
88+
var result: Result<R, any Error>?
89+
XCTExpectFailureInBlock(failureReason, options) {
90+
result = Result { try failingBlock() }
91+
}
92+
return try result!._rethrowGet()
10093
}
101-
return try result._rethrowGet()
10294
#else
103-
_XCTFail(
104-
"XCTest's XCTExpectFailure is unavailable on this platform.",
105-
file: file,
106-
line: line
95+
fputs(
96+
"""
97+
\(file):\(line): An expected failure was recorded without linking the XCTest framework.
98+
99+
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
100+
""",
101+
stderr
107102
)
108-
return try _XCTExpectedFailure.$isInFailingBlock.withValue(true) {
109-
try failingBlock()
110-
}
111103
#endif
112-
#else
113-
fputs("""
114-
\(file):\(line): An expected failure was recorded without linking the XCTest framework.
115-
116-
To fix this, add "IssueReportingTestSupport" as a dependency to your test target.
117-
""",
118-
stderr
119-
)
120104
return try failingBlock()
121-
#endif
122-
}
105+
}
106+
let XCTExpectFailure = function
107+
as! @Sendable (String?, Bool?, Bool?, () throws -> Void) throws -> Void
108+
var result: Result<R, any Error>!
109+
do {
110+
try XCTExpectFailure(failureReason, enabled, strict) {
111+
result = Result { try failingBlock() }
112+
}
113+
} catch {
114+
fatalError()
115+
}
116+
return try result._rethrowGet()
117+
#else
118+
_XCTFail(
119+
"""
120+
'XCTExpectFailure' is not available on this platform.
123121
124-
let XCTExpectFailure = function as! @Sendable (String?, Bool?, Bool?, () throws -> Void) throws -> Void
125-
var result: Result<R, any Error>!
126-
do {
127-
try XCTExpectFailure(failureReason, enabled, strict) {
128-
result = Result { try failingBlock() }
122+
Omit this test from your suite by wrapping it in '#if canImport(Darwin)', or consider using \
123+
Swift Testing and 'withKnownIssue', instead.
124+
"""
125+
)
126+
_XCTExpectedFailure.$isInFailingBlock.withValue(true) {
127+
try failingBlock()
129128
}
130-
} catch {
131-
fatalError()
132-
}
133-
return try result._rethrowGet()
129+
#endif
134130
}
135131

136-
public enum _XCTExpectedFailure {
137-
@TaskLocal public static var isInFailingBlock = false
138-
}
132+
#if !_runtime(_ObjC)
133+
private enum _XCTExpectedFailure {
134+
@TaskLocal public static var isInFailingBlock = false
135+
}
136+
#endif

Sources/IssueReportingTestSupport/XCTest.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ private func __XCTFail(_ message: String, file: StaticString, line: UInt) {
1111
}
1212

1313
public func _XCTExpectFailure() -> Any { __XCTExpectFailure }
14+
@_transparent
1415
@Sendable
1516
private func __XCTExpectFailure(
1617
_ failureReason: String?,
@@ -27,14 +28,6 @@ private func __XCTExpectFailure(
2728
failingBlock: failingBlock
2829
)
2930
#else
30-
XCTFail(
31-
"""
32-
'XCTExpectFailure' is not available on this platform.
33-
34-
Omit this test from your suite by wrapping it in '#if canImport(Darwin)', or consider using
35-
Swift Testing and 'withKnownIssue', instead.
36-
"""
37-
)
3831
try failingBlock()
3932
#endif
4033
#endif

0 commit comments

Comments
 (0)