From 9bb28b8cc88625a2b104ccbdf1a8fd7da3fd6ceb Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 20 Mar 2019 19:36:36 -0400 Subject: [PATCH] golden: Add a var to disable normalization of crlf --- golden/golden.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/golden/golden.go b/golden/golden.go index 72645299..f646d252 100644 --- a/golden/golden.go +++ b/golden/golden.go @@ -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 { @@ -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) }