diff --git a/src/cmd/gofmt/gofmt_test.go b/src/cmd/gofmt/gofmt_test.go index 903ba2177d..e4d5796f3c 100644 --- a/src/cmd/gofmt/gofmt_test.go +++ b/src/cmd/gofmt/gofmt_test.go @@ -81,6 +81,7 @@ var tests = []struct { {"testdata/stdin*.input", "-stdin"}, {"testdata/comments.input", ""}, {"testdata/import.input", ""}, + {"testdata/crlf.input", ""}, // test case for issue 3961; see also TestCRLF } func TestRewrite(t *testing.T) { @@ -103,3 +104,24 @@ func TestRewrite(t *testing.T) { } } } + +func TestCRLF(t *testing.T) { + const input = "testdata/crlf.input" // must contain CR/LF's + const golden = "testdata/crlf.golden" // must not contain any CR's + + data, err := ioutil.ReadFile(input) + if err != nil { + t.Error(err) + } + if bytes.Index(data, []byte("\r\n")) < 0 { + t.Errorf("%s contains no CR/LF's", input) + } + + data, err = ioutil.ReadFile(golden) + if err != nil { + t.Error(err) + } + if bytes.Index(data, []byte("\r")) >= 0 { + t.Errorf("%s contains CR's", golden) + } +} diff --git a/src/cmd/gofmt/testdata/crlf.golden b/src/cmd/gofmt/testdata/crlf.golden new file mode 100644 index 0000000000..57679f770f --- /dev/null +++ b/src/cmd/gofmt/testdata/crlf.golden @@ -0,0 +1,12 @@ +/* + Source containing CR/LF line endings. + The gofmt'ed output must only have LF + line endings. +*/ +package main + +func main() { + // line comment + println("hello, world!") // another line comment + println() +} diff --git a/src/cmd/gofmt/testdata/crlf.input b/src/cmd/gofmt/testdata/crlf.input new file mode 100755 index 0000000000..61a1aa0b4e --- /dev/null +++ b/src/cmd/gofmt/testdata/crlf.input @@ -0,0 +1,12 @@ +/* + Source containing CR/LF line endings. + The gofmt'ed output must only have LF + line endings. +*/ +package main + +func main() { + // line comment + println("hello, world!") // another line comment + println() +}