From ddd0fa17446aa510dd48df7fd07ccce9a9b156d0 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 8 Apr 2011 09:50:20 -0700 Subject: [PATCH] gotest: Fix fix for \r\n on windows. R=rsc, brainman, rh, r2 CC=golang-dev https://golang.org/cl/4366045 --- src/cmd/gotest/gotest.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cmd/gotest/gotest.go b/src/cmd/gotest/gotest.go index 2455aa88f4..138216e681 100644 --- a/src/cmd/gotest/gotest.go +++ b/src/cmd/gotest/gotest.go @@ -234,15 +234,14 @@ func run(args ...string) { // runWithStdout is like run, but returns the text of standard output with the last newline dropped. func runWithStdout(argv ...string) string { s := doRun(argv, true) + if strings.HasSuffix(s, "\r\n") { + s = s[:len(s)-2] + } else if strings.HasSuffix(s, "\n") { + s = s[:len(s)-1] + } if len(s) == 0 { Fatalf("no output from command %s", strings.Join(argv, " ")) } - if s[len(s)-1] == '\n' { - s = s[:len(s)-1] - } - if len(s) > 0 && s[len(s)-1] == '\r' { // it is \r\n on Windows. - s = s[:len(s)-1] - } return s }