@@ -16,27 +16,31 @@ func _XCTFail(
16
16
file: StaticString = #filePath,
17
17
line: UInt = #line
18
18
) {
19
- var pointer : UnsafeMutableRawPointer ? {
20
- let symbol = " $s6XCTest7XCTFail_4file4lineySS_s12StaticStringVSutF "
21
- #if canImport(Darwin) || canImport(Glibc)
22
- return dlsym ( dlopen ( " libXCTest.so " , RTLD_NOW) ?? dlopen ( nil , RTLD_NOW) , symbol)
23
- #elseif canImport(WinSDK)
24
- guard let dll = LoadLibraryA ( " XCTest.dll " ) else { return nil }
25
- return GetProcAddress ( dll, symbol)
26
- #else
27
- return nil
28
- #endif
29
- }
19
+ #if DEBUG
20
+ var pointer : UnsafeMutableRawPointer ? {
21
+ let symbol = " $s6XCTest7XCTFail_4file4lineySS_s12StaticStringVSutF "
22
+ #if canImport(Darwin) || canImport(Glibc)
23
+ return dlsym ( dlopen ( " libXCTest.so " , RTLD_NOW) ?? dlopen ( nil , RTLD_NOW) , symbol)
24
+ #elseif canImport(WinSDK)
25
+ guard let dll = LoadLibraryA ( " XCTest.dll " ) else { return nil }
26
+ return GetProcAddress ( dll, symbol)
27
+ #else
28
+ return nil
29
+ #endif
30
+ }
30
31
31
- guard
32
- !_XCTExpectedFailure. isInFailingBlock,
33
- let pointer
34
- else { return }
35
- let XCTFail = unsafeBitCast (
36
- pointer,
37
- to: ( @convention( thin) ( String, StaticString, UInt) - > Void) . self
38
- )
39
- XCTFail ( message, file, line)
32
+ guard
33
+ !_XCTExpectedFailure. isInFailingBlock,
34
+ let pointer
35
+ else { return }
36
+ let XCTFail = unsafeBitCast (
37
+ pointer,
38
+ to: ( @convention( thin) ( String, StaticString, UInt) - > Void) . self
39
+ )
40
+ XCTFail ( message, file, line)
41
+ #else
42
+ // TODO: Warn
43
+ #endif
40
44
}
41
45
42
46
@_transparent
@@ -49,45 +53,50 @@ func _XCTExpectFailure<R>(
49
53
line: UInt ,
50
54
failingBlock: ( ) throws -> R
51
55
) rethrows -> R {
52
- guard enabled != false
53
- else {
54
- return try failingBlock ( )
55
- }
56
- #if _runtime(_ObjC)
57
- guard
58
- let xctExpectFailureInBlockPtr = dlsym (
59
- dlopen ( nil , RTLD_NOW) ,
60
- " XCTExpectFailureWithOptionsInBlock "
61
- ) ,
62
- let xctExpectedFailureOptions = NSClassFromString ( " XCTExpectedFailureOptions " )
63
- as Any as? NSObjectProtocol ,
64
- let options = strict ?? true
65
- ? xctExpectedFailureOptions
66
- . perform ( NSSelectorFromString ( " alloc " ) ) ? . takeUnretainedValue ( )
67
- . perform ( NSSelectorFromString ( " init " ) ) ? . takeUnretainedValue ( )
68
- : xctExpectedFailureOptions
69
- . perform ( NSSelectorFromString ( " nonStrictOptions " ) ) ? . takeUnretainedValue ( )
56
+ #if DEBUG
57
+ guard enabled != false
70
58
else {
71
59
return try failingBlock ( )
72
60
}
73
- let xctExpectFailureInBlock = unsafeBitCast (
74
- xctExpectFailureInBlockPtr,
75
- to: ( @convention( c) ( String? , AnyObject, ( ) - > Void) - > Void) . self
76
- )
77
- var result : Result < R , any Error > !
78
- xctExpectFailureInBlock ( failureReason, options) {
79
- result = Result { try failingBlock ( ) }
80
- }
81
- return try result. _rethrowGet ( )
61
+ #if _runtime(_ObjC)
62
+ guard
63
+ let xctExpectFailureInBlockPtr = dlsym (
64
+ dlopen ( nil , RTLD_NOW) ,
65
+ " XCTExpectFailureWithOptionsInBlock "
66
+ ) ,
67
+ let xctExpectedFailureOptions = NSClassFromString ( " XCTExpectedFailureOptions " )
68
+ as Any as? NSObjectProtocol ,
69
+ let options = strict ?? true
70
+ ? xctExpectedFailureOptions
71
+ . perform ( NSSelectorFromString ( " alloc " ) ) ? . takeUnretainedValue ( )
72
+ . perform ( NSSelectorFromString ( " init " ) ) ? . takeUnretainedValue ( )
73
+ : xctExpectedFailureOptions
74
+ . perform ( NSSelectorFromString ( " nonStrictOptions " ) ) ? . takeUnretainedValue ( )
75
+ else {
76
+ return try failingBlock ( )
77
+ }
78
+ let xctExpectFailureInBlock = unsafeBitCast (
79
+ xctExpectFailureInBlockPtr,
80
+ to: ( @convention( c) ( String? , AnyObject, ( ) - > Void) - > Void) . self
81
+ )
82
+ var result : Result < R , any Error > !
83
+ xctExpectFailureInBlock ( failureReason, options) {
84
+ result = Result { try failingBlock ( ) }
85
+ }
86
+ return try result. _rethrowGet ( )
87
+ #else
88
+ _XCTFail (
89
+ " XCTest's XCTExpectFailure is unavailable on this platform. " ,
90
+ file: file,
91
+ line: line
92
+ )
93
+ return try _XCTExpectedFailure. $isInFailingBlock. withValue ( true ) {
94
+ try failingBlock ( )
95
+ }
96
+ #endif
82
97
#else
83
- _XCTFail (
84
- " XCTest's XCTExpectFailure is unavailable on this platform. " ,
85
- file: file,
86
- line: line
87
- )
88
- return try _XCTExpectedFailure. $isInFailingBlock. withValue ( true ) {
89
- try failingBlock ( )
90
- }
98
+ // TODO: Warn
99
+ try failingBlock ( )
91
100
#endif
92
101
}
93
102
0 commit comments