@@ -4,25 +4,25 @@ import Foundation
44 import os
55#endif
66
7- extension IssueReporter where Self == _RuntimeWarningReporter {
7+ extension IssueReporter where Self == _DefaultReporter {
88 /// An issue reporter that emits "purple" runtime warnings to Xcode and logs fault-level messages
99 /// to the console.
1010 ///
1111 /// This is the default issue reporter. On non-Apple platforms it logs messages to `stderr`.
12+ /// During test runs it emits test failures, instead.
1213 ///
1314 /// If this issue reporter receives an expected issue, it will log an info-level message to the
1415 /// console, instead.
1516 #if canImport(Darwin)
1617 @_transparent
1718 #endif
18- public static var runtimeWarning : Self { Self ( ) }
19+ public static var `default` : Self { Self ( ) }
1920}
2021
21- /// A type representing an issue reporter that emits "purple" runtime warnings to Xcode and logs
22- /// fault-level messages to the console.
22+ /// A type representing an issue reporter that emits "purple" runtime warnings and test failures.
2323///
2424/// Use ``IssueReporter/runtimeWarning`` to create one of these values.
25- public struct _RuntimeWarningReporter : IssueReporter {
25+ public struct _DefaultReporter : IssueReporter {
2626 #if canImport(os)
2727 @UncheckedSendable
2828 #if canImport(Darwin)
@@ -64,55 +64,113 @@ public struct _RuntimeWarningReporter: IssueReporter {
6464 filePath: StaticString ,
6565 line: UInt ,
6666 column: UInt
67+ ) {
68+ guard !isTesting else {
69+ _recordIssue (
70+ message: message ( ) ,
71+ fileID: " \( fileID) " ,
72+ filePath: " \( filePath) " ,
73+ line: Int ( line) ,
74+ column: Int ( column)
75+ )
76+ _XCTFail (
77+ message ( ) . withAppHostWarningIfNeeded ( ) ?? " " ,
78+ file: filePath,
79+ line: line
80+ )
81+ return
82+ }
83+ runtimeWarn ( message ( ) , fileID: fileID, line: line)
84+ }
85+
86+ @_transparent
87+ public func reportIssue(
88+ _ error: any Error ,
89+ _ message: @autoclosure ( ) -> String ? ,
90+ fileID: StaticString ,
91+ filePath: StaticString ,
92+ line: UInt ,
93+ column: UInt
94+ ) {
95+ guard !isTesting else {
96+ _recordError (
97+ error: error,
98+ message: message ( ) ,
99+ fileID: " \( fileID) " ,
100+ filePath: " \( filePath) " ,
101+ line: Int ( line) ,
102+ column: Int ( column)
103+ )
104+ _XCTFail (
105+ " Caught error: \( error) \( message ( ) . map { " : \( $0) " } ?? " " ) " . withAppHostWarningIfNeeded ( ) ,
106+ file: filePath,
107+ line: line
108+ )
109+ return
110+ }
111+ runtimeWarn (
112+ " Caught error: \( error) \( message ( ) . map { " : \( $0) " } ?? " " ) " ,
113+ fileID: fileID,
114+ line: line
115+ )
116+ }
117+
118+ public func expectIssue(
119+ _ message: @autoclosure ( ) -> String ? ,
120+ fileID: StaticString ,
121+ filePath: StaticString ,
122+ line: UInt ,
123+ column: UInt
67124 ) {
68125 #if canImport(os)
69- guard ProcessInfo . processInfo. environment [ " XCODE_RUNNING_FOR_PREVIEWS " ] != " 1 "
70- else {
71- print ( " 🟣 \( fileID) : \( line) : \( message ( ) ?? " " ) " )
72- return
73- }
74126 let moduleName = String (
75127 Substring ( " \( fileID) " . utf8. prefix ( while: { $0 != UTF8 . CodeUnit ( ascii: " / " ) } ) )
76128 )
77129 var message = message ( ) ?? " "
78130 if message. isEmpty {
79- message = " Issue reported "
131+ message = " Issue expected "
80132 }
81133 os_log (
82- . fault,
83- dso: dso,
84- log: OSLog ( subsystem: " com.apple.runtime-issues " , category: moduleName) ,
134+ . info,
135+ log: OSLog ( subsystem: " co.pointfree.expected-issues " , category: moduleName) ,
85136 " %@ " ,
86137 " \( isTesting ? " \( fileID) : \( line) : " : " " ) \( message) "
87138 )
88139 #else
89- printError ( " \( fileID) : \( line) : \( message ( ) ?? " " ) " )
140+ print ( " \( fileID) : \( line) : \( message ( ) ?? " " ) " )
90141 #endif
91142 }
92143
93- public func expectIssue(
144+ @_transparent
145+ @inlinable
146+ func runtimeWarn(
94147 _ message: @autoclosure ( ) -> String ? ,
95148 fileID: StaticString ,
96- filePath: StaticString ,
97- line: UInt ,
98- column: UInt
149+ line: UInt
99150 ) {
100151 #if canImport(os)
152+ guard ProcessInfo . processInfo. environment [ " XCODE_RUNNING_FOR_PREVIEWS " ] != " 1 "
153+ else {
154+ print ( " 🟣 \( fileID) : \( line) : \( message ( ) ?? " " ) " )
155+ return
156+ }
101157 let moduleName = String (
102158 Substring ( " \( fileID) " . utf8. prefix ( while: { $0 != UTF8 . CodeUnit ( ascii: " / " ) } ) )
103159 )
104160 var message = message ( ) ?? " "
105161 if message. isEmpty {
106- message = " Issue expected "
162+ message = " Issue reported "
107163 }
108164 os_log (
109- . info,
110- log: OSLog ( subsystem: " co.pointfree.expected-issues " , category: moduleName) ,
165+ . fault,
166+ dso: dso,
167+ log: OSLog ( subsystem: " com.apple.runtime-issues " , category: moduleName) ,
111168 " %@ " ,
112169 " \( isTesting ? " \( fileID) : \( line) : " : " " ) \( message) "
113170 )
114171 #else
115- print ( " \( fileID) : \( line) : \( message ( ) ?? " " ) " )
172+ printError ( " \( fileID) : \( line) : \( message ( ) ?? " " ) " )
116173 #endif
174+
117175 }
118176}
0 commit comments