88// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99//
1010
11- @_spi ( Experimental) @_spi ( ForToolsIntegrationOnly) import Testing
11+ @testable @ _spi ( Experimental) @_spi ( ForToolsIntegrationOnly) import Testing
1212
1313@Suite ( " IssueHandlingTrait Tests " )
1414struct IssueHandlingTraitTests {
@@ -23,7 +23,7 @@ struct IssueHandlingTraitTests {
2323 #expect( issue. comments == [ " Foo " , " Bar " ] )
2424 }
2525
26- let handler = IssueHandlingTrait . transformIssues { issue in
26+ let handler = IssueHandlingTrait . compactMapIssues { issue in
2727 var issue = issue
2828 issue. comments. append ( " Bar " )
2929 return issue
@@ -34,16 +34,16 @@ struct IssueHandlingTraitTests {
3434 } . run ( configuration: configuration)
3535 }
3636
37- @Test ( " Suppressing an issue by returning `nil` from the transform closure " )
38- func suppressIssueUsingTransformer ( ) async throws {
37+ @Test ( " Suppressing an issue by returning `nil` from the closure passed to compactMapIssues() " )
38+ func suppressIssueUsingCompactMapIssues ( ) async throws {
3939 var configuration = Configuration ( )
4040 configuration. eventHandler = { event, context in
4141 if case . issueRecorded = event. kind {
4242 Issue . record ( " Unexpected issue recorded event: \( event) " )
4343 }
4444 }
4545
46- let handler = IssueHandlingTrait . transformIssues { _ in
46+ let handler = IssueHandlingTrait . compactMapIssues { _ in
4747 // Return nil to suppress the issue.
4848 nil
4949 }
@@ -81,10 +81,10 @@ struct IssueHandlingTraitTests {
8181
8282 struct MyError : Error { }
8383
84- try await confirmation ( " Transformer closure is called" ) { transformerCalled in
85- let transformer : @Sendable ( Issue ) -> Issue ? = { issue in
84+ try await confirmation ( " Issue handler closure is called" ) { issueHandlerCalled in
85+ let transform : @Sendable ( Issue ) -> Issue ? = { issue in
8686 defer {
87- transformerCalled ( )
87+ issueHandlerCalled ( )
8888 }
8989
9090 #expect( Test . Case. current == nil )
@@ -96,7 +96,7 @@ struct IssueHandlingTraitTests {
9696
9797 let test = Test (
9898 . enabled( if: try { throw MyError ( ) } ( ) ) ,
99- . transformIssues ( transformer )
99+ . compactMapIssues ( transform )
100100 ) { }
101101
102102 // Use a detached task to intentionally clear task local values for the
@@ -108,12 +108,12 @@ struct IssueHandlingTraitTests {
108108 }
109109#endif
110110
111- @Test ( " Accessing the current Test and Test.Case from a transformer closure " )
111+ @Test ( " Accessing the current Test and Test.Case from an issue handler closure " )
112112 func currentTestAndCase( ) async throws {
113- await confirmation ( " Transformer closure is called" ) { transformerCalled in
114- let handler = IssueHandlingTrait . transformIssues { issue in
113+ await confirmation ( " Issue handler closure is called" ) { issueHandlerCalled in
114+ let handler = IssueHandlingTrait . compactMapIssues { issue in
115115 defer {
116- transformerCalled ( )
116+ issueHandlerCalled ( )
117117 }
118118 #expect( Test . current? . name == " fixture() " )
119119 #expect( Test . Case. current != nil )
@@ -140,12 +140,12 @@ struct IssueHandlingTraitTests {
140140 #expect( issue. comments == [ " Foo " , " Bar " , " Baz " ] )
141141 }
142142
143- let outerHandler = IssueHandlingTrait . transformIssues { issue in
143+ let outerHandler = IssueHandlingTrait . compactMapIssues { issue in
144144 var issue = issue
145145 issue. comments. append ( " Baz " )
146146 return issue
147147 }
148- let innerHandler = IssueHandlingTrait . transformIssues { issue in
148+ let innerHandler = IssueHandlingTrait . compactMapIssues { issue in
149149 var issue = issue
150150 issue. comments. append ( " Bar " )
151151 return issue
@@ -156,7 +156,7 @@ struct IssueHandlingTraitTests {
156156 } . run ( configuration: configuration)
157157 }
158158
159- @Test ( " Secondary issue recorded from a transformer closure " )
159+ @Test ( " Secondary issue recorded from an issue handler closure " )
160160 func issueRecordedFromClosure( ) async throws {
161161 await confirmation ( " Original issue recorded " ) { originalIssueRecorded in
162162 await confirmation ( " Secondary issue recorded " ) { secondaryIssueRecorded in
@@ -175,14 +175,14 @@ struct IssueHandlingTraitTests {
175175 }
176176 }
177177
178- let handler1 = IssueHandlingTrait . transformIssues { issue in
178+ let handler1 = IssueHandlingTrait . compactMapIssues { issue in
179179 return issue
180180 }
181- let handler2 = IssueHandlingTrait . transformIssues { issue in
181+ let handler2 = IssueHandlingTrait . compactMapIssues { issue in
182182 Issue . record ( " Something else " )
183183 return issue
184184 }
185- let handler3 = IssueHandlingTrait . transformIssues { issue in
185+ let handler3 = IssueHandlingTrait . compactMapIssues { issue in
186186 // The "Something else" issue should not be passed to this closure.
187187 #expect( issue. comments. contains ( " Foo " ) )
188188 return issue
@@ -194,4 +194,40 @@ struct IssueHandlingTraitTests {
194194 }
195195 }
196196 }
197+
198+ @Test ( " System issues are not passed to issue handler closures " )
199+ func ignoresSystemIssues( ) async throws {
200+ var configuration = Configuration ( )
201+ configuration. eventHandler = { event, context in
202+ if case let . issueRecorded( issue) = event. kind, case . unconditional = issue. kind {
203+ issue. record ( )
204+ }
205+ }
206+
207+ let handler = IssueHandlingTrait . compactMapIssues { issue in
208+ if case . system = issue. kind {
209+ Issue . record ( " Unexpectedly received a system issue " )
210+ }
211+ return nil
212+ }
213+
214+ await Test ( handler) {
215+ Issue ( kind: . system) . record ( )
216+ } . run ( configuration: configuration)
217+ }
218+
219+ #if !SWT_NO_EXIT_TESTS
220+ @Test ( " Disallow assigning kind to .system " )
221+ func disallowAssigningSystemKind( ) async throws {
222+ await #expect( processExitsWith: . failure) {
223+ await Test ( . compactMapIssues { issue in
224+ var issue = issue
225+ issue. kind = . system
226+ return issue
227+ } ) {
228+ Issue . record ( " A non-system issue " )
229+ } . run ( )
230+ }
231+ }
232+ #endif
197233}
0 commit comments