Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix XCTFail.
Browse files Browse the repository at this point in the history
mbrandonw committed Apr 5, 2024
1 parent 5ede785 commit 31d64ed
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Sources/XCTestDynamicOverlay/XCTFail.swift
Original file line number Diff line number Diff line change
@@ -71,16 +71,25 @@ public struct XCTFailContext: Sendable {
public func XCTFail(_ message: String = "", file: StaticString, line: UInt) {
var message = message
attachHostApplicationWarningIfNeeded(&message)
_XCTFailureHandler(nil, true, "\(file)", line, "\(message.isEmpty ? "failed" : message)", nil)
guard let handler = _XCTFailureHandler
else {
runtimeWarn(message)
return
}
handler(nil, true, "\(file)", line, "\(message.isEmpty ? "failed" : message)", nil)
}

private typealias XCTFailureHandler = @convention(c) (
AnyObject?, Bool, UnsafePointer<CChar>, UInt, String, String?
) -> Void
private let _XCTFailureHandler = unsafeBitCast(
dlsym(dlopen(nil, RTLD_LAZY), "_XCTFailureHandler"),
to: XCTFailureHandler.self
)
private let _XCTFailureHandler: XCTFailureHandler? = {
dlsym(dlopen(nil, RTLD_LAZY), "_XCTFailureHandler").map { pointer in
unsafeBitCast(
pointer,
to: XCTFailureHandler.self
)
}
}()

private func attachHostApplicationWarningIfNeeded(_ message: inout String) {
guard

0 comments on commit 31d64ed

Please sign in to comment.