Skip to content

Commit

Permalink
Fix XCTFail. (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw authored Apr 5, 2024
1 parent 5ede785 commit 6f30bdb
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
Expand Up @@ -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
Expand Down

0 comments on commit 6f30bdb

Please sign in to comment.