Skip to content

Commit c01811a

Browse files
Replace CRLF with LF in current as well as previous (#29)
## Summary <!-- Describe your changes in detail here, if it closes an open issue, include "Closes #<issue>" -->
1 parent b39329e commit c01811a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

snapshot.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ func (s *SnapShotter) Snap(value any) {
132132
s.tb.Fatalf("Snap: %v", err)
133133
}
134134

135+
currentBytes := bytes.ReplaceAll(current.Bytes(), []byte("\r\n"), []byte("\n"))
136+
135137
if !exists || s.update {
136138
// No previous snapshot, save the current one, potentially creating the
137139
// directory structure for the first time, then pass the test by returning early
@@ -143,7 +145,7 @@ func (s *SnapShotter) Snap(value any) {
143145
s.tb.Logf("Snap: updating snapshot %s", path)
144146
}
145147

146-
if err = os.WriteFile(path, current.Bytes(), defaultFilePermissions); err != nil {
148+
if err = os.WriteFile(path, currentBytes, defaultFilePermissions); err != nil {
147149
s.tb.Fatalf("Snap: could not write snapshot: %v", err)
148150
}
149151
// We're done
@@ -159,7 +161,7 @@ func (s *SnapShotter) Snap(value any) {
159161
// Normalise CRLF to LF everywhere
160162
previous = bytes.ReplaceAll(previous, []byte("\r\n"), []byte("\n"))
161163

162-
if diff := diff.Diff("previous", previous, "current", current.Bytes()); diff != nil {
164+
if diff := diff.Diff("previous", previous, "current", currentBytes); diff != nil {
163165
s.tb.Fatalf("\nMismatch\n--------\n%s\n", prettyDiff(string(diff)))
164166
}
165167
}

0 commit comments

Comments
 (0)