@@ -23,14 +23,16 @@ import Foundation
23
23
/// - expected: An optional closure that returns a previously generated snapshot. When omitted,
24
24
/// the library will automatically write a snapshot into your test file at the call sight of
25
25
/// the assertion.
26
- /// - file: The file where the assertion occurs. The default is the filename of the test case
27
- /// where you call this function.
26
+ /// - fileID: The file ID in which failure occurred. Defaults to the file ID of the test case in
27
+ /// which this function was called.
28
+ /// - file: The file in which failure occurred. Defaults to the file path of the test case in
29
+ /// which this function was called.
28
30
/// - function: The function where the assertion occurs. The default is the name of the test
29
31
/// method where you call this function.
30
- /// - line: The line where the assertion occurs. The default is the line number where you call
31
- /// this function.
32
- /// - column: The column where the assertion occurs. The default is the line column you call
33
- /// this function.
32
+ /// - line: The line number on which failure occurred. Defaults to the line number on which this
33
+ /// function was called .
34
+ /// - column: The column on which failure occurred. Defaults to the column on which this
35
+ /// function was called .
34
36
public func assertInlineSnapshot< Value> (
35
37
of value: @autoclosure ( ) throws -> Value ? ,
36
38
as snapshotting: Snapshotting < Value , String > ,
@@ -39,7 +41,8 @@ import Foundation
39
41
timeout: TimeInterval = 5 ,
40
42
syntaxDescriptor: InlineSnapshotSyntaxDescriptor = InlineSnapshotSyntaxDescriptor ( ) ,
41
43
matches expected: ( ( ) -> String ) ? = nil ,
42
- file: StaticString = #filePath,
44
+ fileID: StaticString = #fileID,
45
+ file filePath: StaticString = #filePath,
43
46
function: StaticString = #function,
44
47
line: UInt = #line,
45
48
column: UInt = #column
@@ -70,15 +73,29 @@ import Foundation
70
73
loaded. If a timeout is unavoidable, consider setting the " timeout " parameter of
71
74
" assertInlineSnapshot " to a higher value.
72
75
""" ,
73
- file: file,
74
- line: line
76
+ fileID: fileID,
77
+ filePath: filePath,
78
+ line: line,
79
+ column: column
75
80
)
76
81
return
77
82
case . incorrectOrder, . interrupted, . invertedFulfillment:
78
- recordIssue ( " Couldn't snapshot value " , file: file, line: line)
83
+ recordIssue (
84
+ " Couldn't snapshot value " ,
85
+ fileID: fileID,
86
+ filePath: filePath,
87
+ line: line,
88
+ column: column
89
+ )
79
90
return
80
91
@unknown default :
81
- recordIssue ( " Couldn't snapshot value " , file: file, line: line)
92
+ recordIssue (
93
+ " Couldn't snapshot value " ,
94
+ fileID: fileID,
95
+ filePath: filePath,
96
+ line: line,
97
+ column: column
98
+ )
82
99
return
83
100
}
84
101
}
@@ -88,7 +105,7 @@ import Foundation
88
105
record != . missing || expected != nil
89
106
else {
90
107
// NB: Write snapshot state before calling `XCTFail` in case `continueAfterFailure = false`
91
- inlineSnapshotState [ File ( path: file ) , default: [ ] ] . append (
108
+ inlineSnapshotState [ File ( path: filePath ) , default: [ ] ] . append (
92
109
InlineSnapshot (
93
110
expected: expected,
94
111
actual: actual,
@@ -119,8 +136,10 @@ import Foundation
119
136
120
137
Re-run " \( function) " to assert against the newly-recorded snapshot.
121
138
""" ,
122
- file: file,
123
- line: line
139
+ fileID: fileID,
140
+ filePath: filePath,
141
+ line: line,
142
+ column: column
124
143
)
125
144
return
126
145
}
@@ -131,8 +150,10 @@ import Foundation
131
150
"""
132
151
No expected value to assert against.
133
152
""" ,
134
- file: file,
135
- line: line
153
+ fileID: fileID,
154
+ filePath: filePath,
155
+ line: line,
156
+ column: column
136
157
)
137
158
return
138
159
}
@@ -147,25 +168,34 @@ import Foundation
147
168
148
169
\( difference. indenting ( by: 2 ) )
149
170
""" ,
150
- file: file,
171
+ fileID: fileID,
172
+ file: filePath,
151
173
line: line,
152
174
column: column
153
175
)
154
176
} catch {
155
- recordIssue ( " Threw error: \( error) " , file: file, line: line)
177
+ recordIssue (
178
+ " Threw error: \( error) " ,
179
+ fileID: fileID,
180
+ filePath: filePath,
181
+ line: line,
182
+ column: column
183
+ )
156
184
}
157
185
}
158
186
}
159
187
#else
160
188
@available ( * , unavailable, message: " 'assertInlineSnapshot' requires 'swift-syntax' >= 509.0.0 " )
161
189
public func assertInlineSnapshot< Value> (
162
- of value: @autoclosure ( ) throws -> Value ,
190
+ of value: @autoclosure ( ) throws -> Value ? ,
163
191
as snapshotting: Snapshotting < Value , String > ,
164
192
message: @autoclosure ( ) -> String = " " ,
193
+ record isRecording: Bool ? = nil ,
165
194
timeout: TimeInterval = 5 ,
166
195
syntaxDescriptor: InlineSnapshotSyntaxDescriptor = InlineSnapshotSyntaxDescriptor ( ) ,
167
196
matches expected: ( ( ) -> String ) ? = nil ,
168
- file: StaticString = #filePath,
197
+ fileID: StaticString = #fileID,
198
+ file filePath: StaticString = #filePath,
169
199
function: StaticString = #function,
170
200
line: UInt = #line,
171
201
column: UInt = #column
@@ -242,20 +272,23 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable {
242
272
///
243
273
/// - Parameters:
244
274
/// - message: An optional description of the assertion, for inclusion in test results.
245
- /// - file: The file where the assertion occurs. The default is the filename of the test case
246
- /// where you call `assertInlineSnapshot`.
247
- /// - line: The line where the assertion occurs. The default is the line number where you call
248
- /// `assertInlineSnapshot`.
249
- /// - column: The column where the assertion occurs. The default is the column where you call
250
- /// `assertInlineSnapshot`.
275
+ /// - fileID: The file ID in which failure occurred. Defaults to the file ID of the test case
276
+ /// in which this function was called.
277
+ /// - file: The file in which failure occurred. Defaults to the file path of the test case in
278
+ /// which this function was called.
279
+ /// - line: The line number on which failure occurred. Defaults to the line number on which
280
+ /// this function was called.
281
+ /// - column: The column on which failure occurred. Defaults to the column on which this
282
+ /// function was called.
251
283
public func fail(
252
284
_ message: @autoclosure ( ) -> String = " " ,
253
- file: StaticString ,
285
+ fileID: StaticString ,
286
+ file filePath: StaticString ,
254
287
line: UInt ,
255
288
column: UInt
256
289
) {
257
290
var trailingClosureLine : Int ?
258
- if let testSource = try ? testSource ( file: File ( path: file ) ) {
291
+ if let testSource = try ? testSource ( file: File ( path: filePath ) ) {
259
292
let visitor = SnapshotVisitor (
260
293
functionCallLine: Int ( line) ,
261
294
functionCallColumn: Int ( column) ,
@@ -267,8 +300,10 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable {
267
300
}
268
301
recordIssue (
269
302
message ( ) ,
270
- file: file,
271
- line: trailingClosureLine. map ( UInt . init) ?? line
303
+ fileID: fileID,
304
+ filePath: filePath,
305
+ line: trailingClosureLine. map ( UInt . init) ?? line,
306
+ column: column
272
307
)
273
308
}
274
309
@@ -279,7 +314,8 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable {
279
314
@available ( * , unavailable, message: " 'assertInlineSnapshot' requires 'swift-syntax' >= 509.0.0 " )
280
315
public func fail(
281
316
_ message: @autoclosure ( ) -> String = " " ,
282
- file: StaticString ,
317
+ fileID: StaticString ,
318
+ file filePath: StaticString ,
283
319
line: UInt ,
284
320
column: UInt
285
321
) {
0 commit comments