File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
Sources/XCTestDynamicOverlay
Tests/XCTestDynamicOverlayTests Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 3030 run : make test-linux
3131
3232 wasm :
33- name : SwiftWASM
33+ name : Wasm
3434 runs-on : ubuntu-latest
3535 strategy :
3636 matrix :
Original file line number Diff line number Diff line change 11import Foundation
22
3+ public struct XCTFailContext {
4+ @TaskLocal public static var current : Self ?
5+
6+ public var file : StaticString
7+ public var line : UInt
8+
9+ public init ( file: StaticString , line: UInt ) {
10+ self . file = file
11+ self . line = line
12+ }
13+ }
14+
315#if DEBUG
416 #if canImport(ObjectiveC)
517 /// This function generates a failure immediately and unconditionally.
@@ -12,6 +24,10 @@ import Foundation
1224 /// results.
1325 @_disfavoredOverload
1426 public func XCTFail( _ message: String = " " ) {
27+ if let context = XCTFailContext . current {
28+ XCTFail ( message, file: context. file, line: context. line)
29+ return
30+ }
1531 var message = message
1632 attachHostApplicationWarningIfNeeded ( & message)
1733 guard
Original file line number Diff line number Diff line change 1+ #if !os(Linux)
2+ import XCTest
3+ import XCTestDynamicOverlay
4+
5+ public final class XCTContextTests : XCTestCase {
6+ func testContext( ) {
7+ XCTExpectFailure {
8+ $0. compactDescription == " Failed "
9+ && $0. sourceCodeContext. location
10+ == XCTSourceCodeLocation ( filePath: " unknown " , lineNumber: 1 )
11+ }
12+ XCTFailContext . $current. withValue ( XCTFailContext ( file: " unknown " , line: 1 ) ) {
13+ XCTestDynamicOverlay . XCTFail ( " Failed " )
14+ }
15+ }
16+ }
17+ #endif
You can’t perform that action at this time.
0 commit comments