Skip to content

Commit 85a2e21

Browse files
authored
Move around some failure messaging. (#153)
* Move around some error messaging. * fix
1 parent 2a0d866 commit 85a2e21

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ public func verifySnapshot<Value, Format>(
127127
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
128128
return recording
129129
? """
130-
Record mode is on. \(diffMessage)
130+
Record mode is on. Turn record mode off and re-run "\(testName)" to test against the newly-recorded snapshot.
131131
132132
open "\(snapshotFileUrl.path)"
133133
134-
Turn record mode off and re-run "\(testName)" to test against the newly-recorded snapshot.
134+
\(diffMessage)
135135
"""
136136
: """
137137
No reference was found on disk. Automatically recorded snapshot: …
@@ -173,9 +173,11 @@ public func verifySnapshot<Value, Format>(
173173
.map { "\($0) \"\(snapshotFileUrl.path)\" \"\(failedSnapshotFileUrl.path)\"" }
174174
?? "@\(minus)\n\"\(snapshotFileUrl.path)\"\n@\(plus)\n\"\(failedSnapshotFileUrl.path)\""
175175
return """
176-
\(failure.trimmingCharacters(in: .whitespacesAndNewlines))
176+
Snapshot does not match reference.
177177
178178
\(diffMessage)
179+
180+
\(failure.trimmingCharacters(in: .whitespacesAndNewlines))
179181
"""
180182
} catch {
181183
return error.localizedDescription

Sources/SnapshotTesting/SnapshotTestCase.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ open class SnapshotTestCase: XCTestCase {
8484
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
8585
let message = recording
8686
? """
87-
Record mode is on. \(diffMessage)
87+
Record mode is on. Turn record mode off and re-run "\(testName)" to test against the newly-recorded snapshot.
8888
8989
open "\(snapshotFileUrl.path)"
9090
91-
Turn record mode off and re-run "\(testName)" to test against the newly-recorded snapshot.
91+
\(diffMessage)
9292
"""
9393
: """
9494
No reference was found on disk. Automatically recorded snapshot: …
@@ -131,9 +131,11 @@ open class SnapshotTestCase: XCTestCase {
131131
.map { "\($0) \"\(snapshotFileUrl.path)\" \"\(failedSnapshotFileUrl.path)\"" }
132132
?? "@\(minus)\n\"\(snapshotFileUrl.path)\"\n@\(plus)\n\"\(failedSnapshotFileUrl.path)\""
133133
let message = """
134-
\(failure.trimmingCharacters(in: .whitespacesAndNewlines))
134+
Snapshot does not match reference.
135135
136136
\(diffMessage)
137+
138+
\(failure.trimmingCharacters(in: .whitespacesAndNewlines))
137139
"""
138140
XCTFail(message, file: file, line: line)
139141
} catch {

Sources/SnapshotTesting/Snapshotting/String.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ extension Diffing where Value == String {
2121
.flatMap { [$0.patchMark] + $0.lines }
2222
.joined(separator: "\n")
2323
let attachment = XCTAttachment(data: Data(failure.utf8), uniformTypeIdentifier: "public.patch-file")
24-
return ("Diff: …\n\n\(failure)", [attachment])
24+
return (failure, [attachment])
2525
}
2626
}

0 commit comments

Comments
 (0)