]> Cypherpunks repositories - gostls13.git/commitdiff
gotest: Fix fix for \r\n on windows.
authorRob Pike <r@golang.org>
Fri, 8 Apr 2011 16:50:20 +0000 (09:50 -0700)
committerRob Pike <r@golang.org>
Fri, 8 Apr 2011 16:50:20 +0000 (09:50 -0700)
R=rsc, brainman, rh, r2
CC=golang-dev
https://golang.org/cl/4366045

src/cmd/gotest/gotest.go

index 2455aa88f4154b43b66d60ba89f4bae4e0f96a89..138216e68152c5a2317229884e19bca32ca27cd5 100644 (file)
@@ -234,14 +234,13 @@ 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 len(s) == 0 {
-               Fatalf("no output from command %s", strings.Join(argv, " "))
-       }
-       if s[len(s)-1] == '\n' {
+       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 && s[len(s)-1] == '\r' { // it is \r\n on Windows.
-               s = s[:len(s)-1]
+       if len(s) == 0 {
+               Fatalf("no output from command %s", strings.Join(argv, " "))
        }
        return s
 }