Skip to content

Commit 6fb1d3f

Browse files
author
suntala
committed
Fix output indentation
1 parent 8a61785 commit 6fb1d3f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/testing/testing.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,10 @@ func (c *common) log(s string) {
10091009
if l := len(s); l > 0 && (string(s[l-1]) != "\n") {
10101010
s += "\n"
10111011
}
1012+
// Second and subsequent lines are indented 4 spaces. This is in addition to
1013+
// the indentation provided by outputWriter.
1014+
s = strings.Replace(s, "\n", "\n ", -1)
1015+
10121016
cs := c.callSite(3) // callSite + log + public function
10131017
c.newOutputWriter(cs).Write([]byte(s))
10141018
}
@@ -1053,12 +1057,12 @@ type outputWriter struct {
10531057
// the call site if provided. It inserts indentation spaces for formatting. It
10541058
// stores input for later if it is not terminated by a newline.
10551059
func (o *outputWriter) Write(p []byte) (int, error) {
1056-
o.b = append(o.b, p...)
1060+
s := string(append(o.b, p...))
10571061

10581062
o.c.mu.Lock()
10591063
defer o.c.mu.Unlock()
10601064

1061-
lines := strings.Split(string(o.b), "\n")
1065+
lines := strings.Split(s, "\n")
10621066

10631067
for i, line := range lines {
10641068
l := len(lines)
@@ -1072,14 +1076,13 @@ func (o *outputWriter) Write(p []byte) (int, error) {
10721076
}
10731077

10741078
buf := new(strings.Builder)
1075-
// The first line is indented 4 spaces. Subsequent lines are
1076-
// indented 8 spaces unless a line is the final one and
1079+
// All lines are indented 4 spaces unless a line is the final one and
10771080
// is empty.
10781081
if i == 0 {
10791082
buf.WriteString(" ")
10801083
buf.WriteString(o.cs)
10811084
} else if i < l-1 {
1082-
buf.WriteString("\n ")
1085+
buf.WriteString("\n ")
10831086
} else {
10841087
// The final line must be empty otherwise the loop would have
10851088
// terminated earlier.

0 commit comments

Comments
 (0)