]> Cypherpunks repositories - gostls13.git/commitdiff
testing: fix extra tabs when t.Log("string")
authorShenghou Ma <minux.ma@gmail.com>
Sun, 7 Oct 2012 16:21:53 +0000 (00:21 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Sun, 7 Oct 2012 16:21:53 +0000 (00:21 +0800)
t.Log("line 1\nline 2\nline 3")

Old output:
=== RUN TestLine3
--- PASS: TestLine3 (0.00 seconds)
testing_test.go:25:  line 1
line 2
line 3
PASS

New output:
=== RUN TestLine3
--- PASS: TestLine3 (0.00 seconds)
testing_test.go:24:  line 1
line 2
line 3
PASS

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6613069

src/pkg/testing/testing.go

index aeb3266c7ec378d8f3b31368de02f7ac4d61f58c..60edbd55ebd98ec73e488fbe80efc4426d5dec6f 100644 (file)
@@ -160,6 +160,9 @@ func decorate(s string) string {
        fmt.Fprintf(buf, "%s:%d: ", file, line)
 
        lines := strings.Split(s, "\n")
+       if l := len(lines); l > 1 && lines[l-1] == "" {
+               lines = lines[:l-1]
+       }
        for i, line := range lines {
                if i > 0 {
                        buf.WriteByte('\n')
@@ -172,10 +175,7 @@ func decorate(s string) string {
                }
                buf.WriteString(line)
        }
-       if l := len(s); l > 0 && s[len(s)-1] != '\n' {
-               // Add final new line if needed.
-               buf.WriteByte('\n')
-       }
+       buf.WriteByte('\n')
        return buf.String()
 }