@@ -37,7 +37,7 @@ final class KnownIssueTests: XCTestCase {
37
37
await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
38
38
}
39
39
40
- func testKnownIssueWithComment ( ) async {
40
+ func testKnownIssueNotRecordedWithComment ( ) async {
41
41
let issueRecorded = expectation ( description: " Issue recorded " )
42
42
43
43
var configuration = Configuration ( )
@@ -62,6 +62,216 @@ final class KnownIssueTests: XCTestCase {
62
62
await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
63
63
}
64
64
65
+ func testKnownIssueRecordedWithComment( ) async {
66
+ let issueRecorded = expectation ( description: " Issue recorded " )
67
+
68
+ var configuration = Configuration ( )
69
+ configuration. eventHandler = { event, _ in
70
+ guard case let . issueRecorded( issue) = event. kind else {
71
+ return
72
+ }
73
+ issueRecorded. fulfill ( )
74
+
75
+ guard case . unconditional = issue. kind else {
76
+ return
77
+ }
78
+
79
+ XCTAssertEqual ( issue. comments, [ " With Known Issue Comment " , " Issue Comment " ] )
80
+ XCTAssertTrue ( issue. isKnown)
81
+ }
82
+
83
+ await Test {
84
+ withKnownIssue ( " With Known Issue Comment " ) {
85
+ Issue . record ( " Issue Comment " )
86
+ }
87
+ } . run ( configuration: configuration)
88
+
89
+ await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
90
+ }
91
+
92
+ func testThrownKnownIssueRecordedWithComment( ) async {
93
+ let issueRecorded = expectation ( description: " Issue recorded " )
94
+
95
+ var configuration = Configuration ( )
96
+ configuration. eventHandler = { event, _ in
97
+ guard case let . issueRecorded( issue) = event. kind else {
98
+ return
99
+ }
100
+ issueRecorded. fulfill ( )
101
+
102
+ guard case . unconditional = issue. kind else {
103
+ return
104
+ }
105
+
106
+ XCTAssertEqual ( issue. comments, [ " With Known Issue Comment " ] )
107
+ XCTAssertTrue ( issue. isKnown)
108
+ }
109
+
110
+ struct E : Error { }
111
+
112
+ await Test {
113
+ withKnownIssue ( " With Known Issue Comment " ) {
114
+ throw E ( )
115
+ }
116
+ } . run ( configuration: configuration)
117
+
118
+ await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
119
+ }
120
+
121
+ func testKnownIssueRecordedWithNoComment( ) async {
122
+ let issueRecorded = expectation ( description: " Issue recorded " )
123
+
124
+ var configuration = Configuration ( )
125
+ configuration. eventHandler = { event, _ in
126
+ guard case let . issueRecorded( issue) = event. kind else {
127
+ return
128
+ }
129
+ issueRecorded. fulfill ( )
130
+
131
+ guard case . unconditional = issue. kind else {
132
+ return
133
+ }
134
+
135
+ XCTAssertEqual ( issue. comments, [ " Issue Comment " ] )
136
+ XCTAssertTrue ( issue. isKnown)
137
+ }
138
+
139
+ await Test {
140
+ withKnownIssue {
141
+ Issue . record ( " Issue Comment " )
142
+ }
143
+ } . run ( configuration: configuration)
144
+
145
+ await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
146
+ }
147
+
148
+ func testKnownIssueRecordedWithInnermostMatchingComment( ) async {
149
+ let issueRecorded = expectation ( description: " Issue recorded " )
150
+
151
+ var configuration = Configuration ( )
152
+ configuration. eventHandler = { event, _ in
153
+ guard case let . issueRecorded( issue) = event. kind else {
154
+ return
155
+ }
156
+ issueRecorded. fulfill ( )
157
+
158
+ guard case . unconditional = issue. kind else {
159
+ return
160
+ }
161
+
162
+ XCTAssertEqual ( issue. comments, [ " Inner Contains B " , " Issue B " ] )
163
+ XCTAssertTrue ( issue. isKnown)
164
+ }
165
+
166
+ await Test {
167
+ withKnownIssue ( " Contains A " , isIntermittent: true ) {
168
+ withKnownIssue ( " Outer Contains B " , isIntermittent: true ) {
169
+ withKnownIssue ( " Inner Contains B " ) {
170
+ withKnownIssue ( " Contains C " , isIntermittent: true ) {
171
+ Issue . record ( " Issue B " )
172
+ } matching: { issue in
173
+ issue. comments. contains { $0. rawValue. contains ( " C " ) }
174
+ }
175
+ } matching: { issue in
176
+ issue. comments. contains { $0. rawValue. contains ( " B " ) }
177
+ }
178
+ } matching: { issue in
179
+ issue. comments. contains { $0. rawValue. contains ( " B " ) }
180
+ }
181
+ } matching: { issue in
182
+ issue. comments. contains { $0. rawValue. contains ( " A " ) }
183
+ }
184
+ } . run ( configuration: configuration)
185
+
186
+ await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
187
+ }
188
+
189
+ func testThrownKnownIssueRecordedWithInnermostMatchingComment( ) async {
190
+ let issueRecorded = expectation ( description: " Issue recorded " )
191
+
192
+ var configuration = Configuration ( )
193
+ configuration. eventHandler = { event, _ in
194
+ guard case let . issueRecorded( issue) = event. kind else {
195
+ return
196
+ }
197
+ issueRecorded. fulfill ( )
198
+
199
+ guard case . unconditional = issue. kind else {
200
+ return
201
+ }
202
+
203
+ XCTAssertEqual ( issue. comments, [ " Inner Is B " , " B " ] )
204
+ XCTAssertTrue ( issue. isKnown)
205
+ }
206
+
207
+ struct A : Error { }
208
+ struct B : Error { }
209
+ struct C : Error { }
210
+
211
+ await Test {
212
+ try withKnownIssue ( " Is A " , isIntermittent: true ) {
213
+ try withKnownIssue ( " Outer Is B " , isIntermittent: true ) {
214
+ try withKnownIssue ( " Inner Is B " ) {
215
+ try withKnownIssue ( " Is C " , isIntermittent: true ) {
216
+ throw B ( )
217
+ } matching: { issue in
218
+ issue. error is C
219
+ }
220
+ } matching: { issue in
221
+ issue. error is B
222
+ }
223
+ } matching: { issue in
224
+ issue. error is B
225
+ }
226
+ } matching: { issue in
227
+ issue. error is A
228
+ }
229
+ } . run ( configuration: configuration)
230
+
231
+ await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
232
+ }
233
+
234
+ func testKnownIssueRecordedWithNoCommentOnInnermostMatch( ) async {
235
+ let issueRecorded = expectation ( description: " Issue recorded " )
236
+
237
+ var configuration = Configuration ( )
238
+ configuration. eventHandler = { event, _ in
239
+ guard case let . issueRecorded( issue) = event. kind else {
240
+ return
241
+ }
242
+ issueRecorded. fulfill ( )
243
+
244
+ guard case . unconditional = issue. kind else {
245
+ return
246
+ }
247
+
248
+ XCTAssertEqual ( issue. comments, [ " Issue B " ] )
249
+ XCTAssertTrue ( issue. isKnown)
250
+ }
251
+
252
+ await Test {
253
+ withKnownIssue ( " Contains A " , isIntermittent: true ) {
254
+ withKnownIssue ( " Outer Contains B " , isIntermittent: true ) {
255
+ withKnownIssue { // No comment here on the withKnownIssue that will actually match.
256
+ withKnownIssue ( " Contains C " , isIntermittent: true ) {
257
+ Issue . record ( " Issue B " )
258
+ } matching: { issue in
259
+ issue. comments. contains { $0. rawValue. contains ( " C " ) }
260
+ }
261
+ } matching: { issue in
262
+ issue. comments. contains { $0. rawValue. contains ( " B " ) }
263
+ }
264
+ } matching: { issue in
265
+ issue. comments. contains { $0. rawValue. contains ( " B " ) }
266
+ }
267
+ } matching: { issue in
268
+ issue. comments. contains { $0. rawValue. contains ( " A " ) }
269
+ }
270
+ } . run ( configuration: configuration)
271
+
272
+ await fulfillment ( of: [ issueRecorded] , timeout: 0.0 )
273
+ }
274
+
65
275
func testIssueIsKnownPropertyIsSetCorrectlyWithCustomIssueMatcher( ) async {
66
276
struct MyError : Error { }
67
277
0 commit comments