Skip to content

Commit

Permalink
golden: Add a var to disable normalization of crlf
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Mar 20, 2019
1 parent d1a6560 commit 9bb28b8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ type helperT interface {
Helper()
}

// NormalizeCRLFToLF enables end-of-line normalization for actual values passed
// to Assert and String, as well as the values saved to golden files with
// -test.update-golden.
//
// Defaults to true. If you use the core.autocrlf=true git setting on windows
// you will need to set this to false.
//
// The default value may change in a future major release.
var NormalizeCRLFToLF = true

// Get returns the contents of the file in ./testdata
func Get(t assert.TestingT, filename string) []byte {
if ht, ok := t.(helperT); ok {
Expand Down Expand Up @@ -50,6 +60,9 @@ func update(filename string, actual []byte, normalize normalize) error {
type normalize func([]byte) []byte

func removeCarriageReturn(in []byte) []byte {
if !NormalizeCRLFToLF {
return in
}
return bytes.Replace(in, []byte("\r\n"), []byte("\n"), -1)
}

Expand Down

0 comments on commit 9bb28b8

Please sign in to comment.