8
8
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
//
10
10
11
- @_spi ( Experimental) @_spi ( ForToolsIntegrationOnly) import Testing
11
+ @testable @ _spi ( Experimental) @_spi ( ForToolsIntegrationOnly) import Testing
12
12
13
13
@Suite ( " IssueHandlingTrait Tests " )
14
14
struct IssueHandlingTraitTests {
@@ -23,7 +23,7 @@ struct IssueHandlingTraitTests {
23
23
#expect( issue. comments == [ " Foo " , " Bar " ] )
24
24
}
25
25
26
- let handler = IssueHandlingTrait . transformIssues { issue in
26
+ let handler = IssueHandlingTrait . compactMapIssues { issue in
27
27
var issue = issue
28
28
issue. comments. append ( " Bar " )
29
29
return issue
@@ -34,16 +34,16 @@ struct IssueHandlingTraitTests {
34
34
} . run ( configuration: configuration)
35
35
}
36
36
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 {
39
39
var configuration = Configuration ( )
40
40
configuration. eventHandler = { event, context in
41
41
if case . issueRecorded = event. kind {
42
42
Issue . record ( " Unexpected issue recorded event: \( event) " )
43
43
}
44
44
}
45
45
46
- let handler = IssueHandlingTrait . transformIssues { _ in
46
+ let handler = IssueHandlingTrait . compactMapIssues { _ in
47
47
// Return nil to suppress the issue.
48
48
nil
49
49
}
@@ -81,10 +81,10 @@ struct IssueHandlingTraitTests {
81
81
82
82
struct MyError : Error { }
83
83
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
86
86
defer {
87
- transformerCalled ( )
87
+ issueHandlerCalled ( )
88
88
}
89
89
90
90
#expect( Test . Case. current == nil )
@@ -96,7 +96,7 @@ struct IssueHandlingTraitTests {
96
96
97
97
let test = Test (
98
98
. enabled( if: try { throw MyError ( ) } ( ) ) ,
99
- . transformIssues ( transformer )
99
+ . compactMapIssues ( transform )
100
100
) { }
101
101
102
102
// Use a detached task to intentionally clear task local values for the
@@ -108,12 +108,12 @@ struct IssueHandlingTraitTests {
108
108
}
109
109
#endif
110
110
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 " )
112
112
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
115
115
defer {
116
- transformerCalled ( )
116
+ issueHandlerCalled ( )
117
117
}
118
118
#expect( Test . current? . name == " fixture() " )
119
119
#expect( Test . Case. current != nil )
@@ -140,12 +140,12 @@ struct IssueHandlingTraitTests {
140
140
#expect( issue. comments == [ " Foo " , " Bar " , " Baz " ] )
141
141
}
142
142
143
- let outerHandler = IssueHandlingTrait . transformIssues { issue in
143
+ let outerHandler = IssueHandlingTrait . compactMapIssues { issue in
144
144
var issue = issue
145
145
issue. comments. append ( " Baz " )
146
146
return issue
147
147
}
148
- let innerHandler = IssueHandlingTrait . transformIssues { issue in
148
+ let innerHandler = IssueHandlingTrait . compactMapIssues { issue in
149
149
var issue = issue
150
150
issue. comments. append ( " Bar " )
151
151
return issue
@@ -156,7 +156,7 @@ struct IssueHandlingTraitTests {
156
156
} . run ( configuration: configuration)
157
157
}
158
158
159
- @Test ( " Secondary issue recorded from a transformer closure " )
159
+ @Test ( " Secondary issue recorded from an issue handler closure " )
160
160
func issueRecordedFromClosure( ) async throws {
161
161
await confirmation ( " Original issue recorded " ) { originalIssueRecorded in
162
162
await confirmation ( " Secondary issue recorded " ) { secondaryIssueRecorded in
@@ -175,14 +175,14 @@ struct IssueHandlingTraitTests {
175
175
}
176
176
}
177
177
178
- let handler1 = IssueHandlingTrait . transformIssues { issue in
178
+ let handler1 = IssueHandlingTrait . compactMapIssues { issue in
179
179
return issue
180
180
}
181
- let handler2 = IssueHandlingTrait . transformIssues { issue in
181
+ let handler2 = IssueHandlingTrait . compactMapIssues { issue in
182
182
Issue . record ( " Something else " )
183
183
return issue
184
184
}
185
- let handler3 = IssueHandlingTrait . transformIssues { issue in
185
+ let handler3 = IssueHandlingTrait . compactMapIssues { issue in
186
186
// The "Something else" issue should not be passed to this closure.
187
187
#expect( issue. comments. contains ( " Foo " ) )
188
188
return issue
@@ -194,4 +194,40 @@ struct IssueHandlingTraitTests {
194
194
}
195
195
}
196
196
}
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
197
233
}
0 commit comments