@@ -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 ("\n Mismatch\n --------\n %s\n " , prettyDiff (string (diff )))
164166 }
165167}
0 commit comments