@@ -100,22 +100,25 @@ import Foundation
100
100
}
101
101
}
102
102
let expected = expected ? ( )
103
- guard
104
- record != . all,
105
- record != . missing || expected != nil
106
- else {
103
+ func recordSnapshot( ) {
107
104
// NB: Write snapshot state before calling `XCTFail` in case `continueAfterFailure = false`
108
105
inlineSnapshotState [ File ( path: filePath) , default: [ ] ] . append (
109
106
InlineSnapshot (
110
107
expected: expected,
111
108
actual: actual,
112
- wasRecording: record == . all,
109
+ wasRecording: record == . all || record == . failed ,
113
110
syntaxDescriptor: syntaxDescriptor,
114
111
function: " \( function) " ,
115
112
line: line,
116
113
column: column
117
114
)
118
115
)
116
+ }
117
+ guard
118
+ record != . all,
119
+ ( record != . missing && record != . failed) || expected != nil
120
+ else {
121
+ recordSnapshot ( )
119
122
120
123
var failure : String
121
124
if syntaxDescriptor. trailingClosureLabel
@@ -162,12 +165,19 @@ import Foundation
162
165
else { return }
163
166
164
167
let message = message ( )
165
- syntaxDescriptor. fail (
166
- """
168
+ var failureMessage = """
167
169
\( message. isEmpty ? " Snapshot did not match. Difference: … " : message)
168
-
170
+
169
171
\( difference. indenting ( by: 2 ) )
170
- """ ,
172
+ """
173
+
174
+ if record == . failed {
175
+ recordSnapshot ( )
176
+ failureMessage += " \n \n A new snapshot was automatically recorded. "
177
+ }
178
+
179
+ syntaxDescriptor. fail (
180
+ failureMessage,
171
181
fileID: fileID,
172
182
file: filePath,
173
183
line: line,
@@ -352,27 +362,27 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable {
352
362
}
353
363
}
354
364
355
- private struct File : Hashable {
356
- let path : StaticString
357
- static func == ( lhs: Self , rhs: Self ) -> Bool {
365
+ @ _spi ( Internals ) public struct File : Hashable {
366
+ public let path : StaticString
367
+ public static func == ( lhs: Self , rhs: Self ) -> Bool {
358
368
" \( lhs. path) " == " \( rhs. path) "
359
369
}
360
- func hash( into hasher: inout Hasher ) {
370
+ public func hash( into hasher: inout Hasher ) {
361
371
hasher. combine ( " \( self . path) " )
362
372
}
363
373
}
364
374
365
- private struct InlineSnapshot : Hashable {
366
- var expected : String ?
367
- var actual : String ?
368
- var wasRecording : Bool
369
- var syntaxDescriptor : InlineSnapshotSyntaxDescriptor
370
- var function : String
371
- var line : UInt
372
- var column : UInt
375
+ @ _spi ( Internals ) public struct InlineSnapshot : Hashable {
376
+ public var expected : String ?
377
+ public var actual : String ?
378
+ public var wasRecording : Bool
379
+ public var syntaxDescriptor : InlineSnapshotSyntaxDescriptor
380
+ public var function : String
381
+ public var line : UInt
382
+ public var column : UInt
373
383
}
374
384
375
- private var inlineSnapshotState : [ File : [ InlineSnapshot ] ] = [ : ]
385
+ @ _spi ( Internals ) public var inlineSnapshotState : [ File : [ InlineSnapshot ] ] = [ : ]
376
386
377
387
private struct TestSource {
378
388
let source : String
0 commit comments