1
1
#if DEBUG
2
2
#if canImport(os)
3
- import os
4
- import XCTestDynamicOverlay
3
+ import os
4
+ import XCTestDynamicOverlay
5
5
6
- // NB: Xcode runtime warnings offer a much better experience than traditional assertions and
7
- // breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
8
- // To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
9
- //
10
- // Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
11
- private let rw = (
12
- dso: { ( ) -> UnsafeMutableRawPointer in
13
- let count = _dyld_image_count ( )
14
- for i in 0 ..< count {
15
- if let name = _dyld_get_image_name ( i) {
16
- let swiftString = String ( cString: name)
17
- if swiftString. hasSuffix ( " /SwiftUI " ) {
18
- if let header = _dyld_get_image_header ( i) {
19
- return UnsafeMutableRawPointer ( mutating: UnsafeRawPointer ( header) )
20
- }
6
+ // NB: Xcode runtime warnings offer a much better experience than traditional assertions and
7
+ // breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
8
+ // To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
9
+ //
10
+ // Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
11
+ private let rw = (
12
+ dso: { ( ) -> UnsafeMutableRawPointer in
13
+ let count = _dyld_image_count ( )
14
+ for i in 0 ..< count {
15
+ if let name = _dyld_get_image_name ( i) {
16
+ let swiftString = String ( cString: name)
17
+ if swiftString. hasSuffix ( " /SwiftUI " ) {
18
+ if let header = _dyld_get_image_header ( i) {
19
+ return UnsafeMutableRawPointer ( mutating: UnsafeRawPointer ( header) )
21
20
}
22
21
}
23
22
}
24
- return UnsafeMutableRawPointer ( mutating: #dsohandle)
25
- } ( ) ,
26
- log: OSLog ( subsystem: " com.apple.runtime-issues " , category: " ComposableArchitecture " )
27
- )
28
- #endif
23
+ }
24
+ return UnsafeMutableRawPointer ( mutating: #dsohandle)
25
+ } ( ) ,
26
+ log: OSLog ( subsystem: " com.apple.runtime-issues " , category: " ComposableArchitecture " )
27
+ )
28
+ #endif
29
29
#endif
30
30
31
31
@inline ( __always)
@@ -34,18 +34,20 @@ func runtimeWarning(
34
34
_ args: @autoclosure ( ) -> [ CVarArg ] = [ ]
35
35
) {
36
36
#if DEBUG
37
- #if canImport(os)
38
- let message = message ( )
39
- unsafeBitCast (
40
- os_log as ( OSLogType , UnsafeRawPointer , OSLog , StaticString , CVarArg . . . ) -> Void ,
41
- to: ( ( OSLogType, UnsafeRawPointer, OSLog, StaticString, [ CVarArg] ) - > Void) . self
42
- ) ( . fault, rw. dso, rw. log, message, args ( ) )
43
- XCTFail ( String ( format: " \( message) " , arguments: args ( ) ) )
44
- #else
45
- let strMessage = message ( ) . withUTF8Buffer {
46
- String ( decoding: $0, as: UTF8 . self)
47
- }
48
- print ( String ( format: strMessage, arguments: args ( ) ) )
49
- #endif
37
+ if _XCTIsTesting {
38
+ XCTFail ( String ( format: " \( message ( ) ) " , arguments: args ( ) ) )
39
+ } else {
40
+ #if canImport(os)
41
+ unsafeBitCast (
42
+ os_log as ( OSLogType , UnsafeRawPointer , OSLog , StaticString , CVarArg . . . ) -> Void ,
43
+ to: ( ( OSLogType, UnsafeRawPointer, OSLog, StaticString, [ CVarArg] ) - > Void) . self
44
+ ) ( . fault, rw. dso, rw. log, message ( ) , args ( ) )
45
+ #else
46
+ let strMessage = message ( ) . withUTF8Buffer {
47
+ String ( decoding: $0, as: UTF8 . self)
48
+ }
49
+ print ( String ( format: strMessage, arguments: args ( ) ) )
50
+ #endif
51
+ }
50
52
#endif
51
53
}
0 commit comments