@@ -16,6 +16,9 @@ func _XCTFail(
16
16
file: StaticString = #filePath,
17
17
line: UInt = #line
18
18
) {
19
+ #if !_runtime(_ObjC)
20
+ guard !_XCTExpectedFailure. isInFailingBlock else { return }
21
+ #endif
19
22
guard let function = function ( for: " $s25IssueReportingTestSupport8_XCTFailypyF " )
20
23
else {
21
24
#if DEBUG
@@ -30,28 +33,24 @@ func _XCTFail(
30
33
return nil
31
34
#endif
32
35
}
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
+ }
51
44
#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
+ )
52
52
return
53
53
}
54
-
55
54
let XCTFail = function as! @Sendable ( String , StaticString , UInt ) -> Void
56
55
XCTFail ( message, file, line)
57
56
}
@@ -66,73 +65,72 @@ func _XCTExpectFailure<R>(
66
65
line: UInt ,
67
66
failingBlock: ( ) throws -> R
68
67
) 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 " )
83
76
as Any as? NSObjectProtocol ,
84
77
let options = strict ?? true
85
- ? xctExpectedFailureOptions
78
+ ? XCTExpectedFailureOptions
86
79
. perform ( NSSelectorFromString ( " alloc " ) ) ? . takeUnretainedValue ( )
87
80
. perform ( NSSelectorFromString ( " init " ) ) ? . takeUnretainedValue ( )
88
- : xctExpectedFailureOptions
81
+ : XCTExpectedFailureOptions
89
82
. 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 ( )
100
93
}
101
- return try result. _rethrowGet ( )
102
94
#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
107
102
)
108
- return try _XCTExpectedFailure. $isInFailingBlock. withValue ( true ) {
109
- try failingBlock ( )
110
- }
111
103
#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
- )
120
104
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.
123
121
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 ( )
129
128
}
130
- } catch {
131
- fatalError ( )
132
- }
133
- return try result. _rethrowGet ( )
129
+ #endif
134
130
}
135
131
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
0 commit comments