Skip to content

Commit

Permalink
Merge pull request #149 from dnephin/golden-normalize
Browse files Browse the repository at this point in the history
golden: Add a var to disable normalization of crlf
  • Loading branch information
dnephin authored Apr 4, 2020
2 parents 038ef91 + f13b253 commit 4299c6d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ 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 value may be set to false by setting GOTESTTOOLS_GOLDEN_NormalizeCRLFToLF=false
// in the environment before running tests.
//
// The default value may change in a future major release.
var NormalizeCRLFToLF = os.Getenv("GOTESTTOOLS_GOLDEN_NormalizeCRLFToLF") != "false"

// Open opens the file in ./testdata
func Open(t assert.TestingT, filename string) *os.File {
if ht, ok := t.(helperT); ok {
Expand Down Expand Up @@ -62,6 +75,9 @@ func update(filename string, actual []byte) error {
}

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 4299c6d

Please sign in to comment.