mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: make indentation consistent in sub-tests
Instead of mixed usage of spaces and tabs for indentation,
just use 4 spaces instead of one tab.
This test:
func TestX(t *testing.T) {
t.Error("1\nnew line")
t.Error("2")
t.Error("3")
t.Run("Y", func(t *testing.T) {
t.Error("2")
t.Error("2b\nnew line")
t.Run("Z", func(t *testing.T) {
t.Error("3\nnew line")
})
})
t.Error("4")
}
produces following output:
--- FAIL: TestX (0.00s)
indent_test.go:6: 1
new line
indent_test.go:7: 2
indent_test.go:8: 3
--- FAIL: TestX/Y (0.00s)
indent_test.go:10: 2
indent_test.go:11: 2b
new line
--- FAIL: TestX/Y/Z (0.00s)
indent_test.go:13: 3
new line
indent_test.go:16: 4
FAIL
Fixes #25369
Change-Id: Ib3b5da45ab3ee670c6e8a23172e7cbefb94c5e60
Reviewed-on: https://go-review.googlesource.com/113177
Run-TryBot: Yury Smolsky <yury@smolsky.by>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
This commit is contained in:
parent
3c4d3bdd3b
commit
fffb3a5c20
3 changed files with 37 additions and 37 deletions
|
|
@ -4892,30 +4892,30 @@ func TestTestRegexps(t *testing.T) {
|
||||||
// BenchmarkX/Y is run in full, twice
|
// BenchmarkX/Y is run in full, twice
|
||||||
want := `=== RUN TestX
|
want := `=== RUN TestX
|
||||||
=== RUN TestX/Y
|
=== RUN TestX/Y
|
||||||
x_test.go:6: LOG: X running
|
x_test.go:6: LOG: X running
|
||||||
x_test.go:8: LOG: Y running
|
x_test.go:8: LOG: Y running
|
||||||
=== RUN TestXX
|
=== RUN TestXX
|
||||||
z_test.go:10: LOG: XX running
|
z_test.go:10: LOG: XX running
|
||||||
=== RUN TestX
|
=== RUN TestX
|
||||||
=== RUN TestX/Y
|
=== RUN TestX/Y
|
||||||
x_test.go:6: LOG: X running
|
x_test.go:6: LOG: X running
|
||||||
x_test.go:8: LOG: Y running
|
x_test.go:8: LOG: Y running
|
||||||
=== RUN TestXX
|
=== RUN TestXX
|
||||||
z_test.go:10: LOG: XX running
|
z_test.go:10: LOG: XX running
|
||||||
--- BENCH: BenchmarkX/Y
|
--- BENCH: BenchmarkX/Y
|
||||||
x_test.go:15: LOG: Y running N=1
|
x_test.go:15: LOG: Y running N=1
|
||||||
x_test.go:15: LOG: Y running N=100
|
x_test.go:15: LOG: Y running N=100
|
||||||
x_test.go:15: LOG: Y running N=10000
|
x_test.go:15: LOG: Y running N=10000
|
||||||
x_test.go:15: LOG: Y running N=1000000
|
x_test.go:15: LOG: Y running N=1000000
|
||||||
x_test.go:15: LOG: Y running N=100000000
|
x_test.go:15: LOG: Y running N=100000000
|
||||||
x_test.go:15: LOG: Y running N=2000000000
|
x_test.go:15: LOG: Y running N=2000000000
|
||||||
--- BENCH: BenchmarkX/Y
|
--- BENCH: BenchmarkX/Y
|
||||||
x_test.go:15: LOG: Y running N=1
|
x_test.go:15: LOG: Y running N=1
|
||||||
x_test.go:15: LOG: Y running N=2000000000
|
x_test.go:15: LOG: Y running N=2000000000
|
||||||
--- BENCH: BenchmarkX
|
--- BENCH: BenchmarkX
|
||||||
x_test.go:13: LOG: X running N=1
|
x_test.go:13: LOG: X running N=1
|
||||||
--- BENCH: BenchmarkXX
|
--- BENCH: BenchmarkXX
|
||||||
z_test.go:18: LOG: XX running N=1
|
z_test.go:18: LOG: XX running N=1
|
||||||
`
|
`
|
||||||
|
|
||||||
have := strings.Join(lines, "")
|
have := strings.Join(lines, "")
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ func TestTRun(t *T) {
|
||||||
--- FAIL: failure in parallel test propagates upwards (N.NNs)
|
--- FAIL: failure in parallel test propagates upwards (N.NNs)
|
||||||
--- FAIL: failure in parallel test propagates upwards/#00 (N.NNs)
|
--- FAIL: failure in parallel test propagates upwards/#00 (N.NNs)
|
||||||
--- FAIL: failure in parallel test propagates upwards/#00/par (N.NNs)
|
--- FAIL: failure in parallel test propagates upwards/#00/par (N.NNs)
|
||||||
`,
|
`,
|
||||||
f: func(t *T) {
|
f: func(t *T) {
|
||||||
t.Run("", func(t *T) {
|
t.Run("", func(t *T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
@ -210,8 +210,8 @@ func TestTRun(t *T) {
|
||||||
desc: "skipping after error",
|
desc: "skipping after error",
|
||||||
output: `
|
output: `
|
||||||
--- FAIL: skipping after error (N.NNs)
|
--- FAIL: skipping after error (N.NNs)
|
||||||
sub_test.go:NNN: an error
|
sub_test.go:NNN: an error
|
||||||
sub_test.go:NNN: skipped`,
|
sub_test.go:NNN: skipped`,
|
||||||
f: func(t *T) {
|
f: func(t *T) {
|
||||||
t.Error("an error")
|
t.Error("an error")
|
||||||
t.Skip("skipped")
|
t.Skip("skipped")
|
||||||
|
|
@ -320,9 +320,9 @@ func TestTRun(t *T) {
|
||||||
ok: false,
|
ok: false,
|
||||||
output: `
|
output: `
|
||||||
--- FAIL: subtest calls error on parent (N.NNs)
|
--- FAIL: subtest calls error on parent (N.NNs)
|
||||||
sub_test.go:NNN: first this
|
sub_test.go:NNN: first this
|
||||||
sub_test.go:NNN: and now this!
|
sub_test.go:NNN: and now this!
|
||||||
sub_test.go:NNN: oh, and this too`,
|
sub_test.go:NNN: oh, and this too`,
|
||||||
maxPar: 1,
|
maxPar: 1,
|
||||||
f: func(t *T) {
|
f: func(t *T) {
|
||||||
t.Errorf("first this")
|
t.Errorf("first this")
|
||||||
|
|
@ -337,10 +337,10 @@ func TestTRun(t *T) {
|
||||||
ok: false,
|
ok: false,
|
||||||
output: `
|
output: `
|
||||||
--- FAIL: subtest calls fatal on parent (N.NNs)
|
--- FAIL: subtest calls fatal on parent (N.NNs)
|
||||||
sub_test.go:NNN: first this
|
sub_test.go:NNN: first this
|
||||||
sub_test.go:NNN: and now this!
|
sub_test.go:NNN: and now this!
|
||||||
--- FAIL: subtest calls fatal on parent/#00 (N.NNs)
|
--- FAIL: subtest calls fatal on parent/#00 (N.NNs)
|
||||||
testing.go:NNN: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test`,
|
testing.go:NNN: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test`,
|
||||||
maxPar: 1,
|
maxPar: 1,
|
||||||
f: func(t *T) {
|
f: func(t *T) {
|
||||||
outer := t
|
outer := t
|
||||||
|
|
@ -355,10 +355,10 @@ func TestTRun(t *T) {
|
||||||
ok: false,
|
ok: false,
|
||||||
output: `
|
output: `
|
||||||
--- FAIL: subtest calls error on ancestor (N.NNs)
|
--- FAIL: subtest calls error on ancestor (N.NNs)
|
||||||
sub_test.go:NNN: Report to ancestor
|
sub_test.go:NNN: Report to ancestor
|
||||||
--- FAIL: subtest calls error on ancestor/#00 (N.NNs)
|
--- FAIL: subtest calls error on ancestor/#00 (N.NNs)
|
||||||
sub_test.go:NNN: Still do this
|
sub_test.go:NNN: Still do this
|
||||||
sub_test.go:NNN: Also do this`,
|
sub_test.go:NNN: Also do this`,
|
||||||
maxPar: 1,
|
maxPar: 1,
|
||||||
f: func(t *T) {
|
f: func(t *T) {
|
||||||
outer := t
|
outer := t
|
||||||
|
|
@ -375,7 +375,7 @@ func TestTRun(t *T) {
|
||||||
ok: false,
|
ok: false,
|
||||||
output: `
|
output: `
|
||||||
--- FAIL: subtest calls fatal on ancestor (N.NNs)
|
--- FAIL: subtest calls fatal on ancestor (N.NNs)
|
||||||
sub_test.go:NNN: Nope`,
|
sub_test.go:NNN: Nope`,
|
||||||
maxPar: 1,
|
maxPar: 1,
|
||||||
f: func(t *T) {
|
f: func(t *T) {
|
||||||
outer := t
|
outer := t
|
||||||
|
|
@ -503,7 +503,7 @@ func TestBRun(t *T) {
|
||||||
chatty: true,
|
chatty: true,
|
||||||
output: `
|
output: `
|
||||||
--- SKIP: root
|
--- SKIP: root
|
||||||
sub_test.go:NNN: skipping`,
|
sub_test.go:NNN: skipping`,
|
||||||
f: func(b *B) { b.Skip("skipping") },
|
f: func(b *B) { b.Skip("skipping") },
|
||||||
}, {
|
}, {
|
||||||
desc: "chatty with recursion",
|
desc: "chatty with recursion",
|
||||||
|
|
@ -521,8 +521,8 @@ func TestBRun(t *T) {
|
||||||
failed: true,
|
failed: true,
|
||||||
output: `
|
output: `
|
||||||
--- FAIL: root
|
--- FAIL: root
|
||||||
sub_test.go:NNN: an error
|
sub_test.go:NNN: an error
|
||||||
sub_test.go:NNN: skipped`,
|
sub_test.go:NNN: skipped`,
|
||||||
f: func(b *B) {
|
f: func(b *B) {
|
||||||
b.Error("an error")
|
b.Error("an error")
|
||||||
b.Skip("skipped")
|
b.Skip("skipped")
|
||||||
|
|
|
||||||
|
|
@ -394,7 +394,7 @@ func (c *common) frameSkip(skip int) runtime.Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate prefixes the string with the file and line of the call site
|
// decorate prefixes the string with the file and line of the call site
|
||||||
// and inserts the final newline if needed and indentation tabs for formatting.
|
// and inserts the final newline if needed and indentation spaces for formatting.
|
||||||
// This function must be called with c.mu held.
|
// This function must be called with c.mu held.
|
||||||
func (c *common) decorate(s string) string {
|
func (c *common) decorate(s string) string {
|
||||||
frame := c.frameSkip(3) // decorate + log + public function.
|
frame := c.frameSkip(3) // decorate + log + public function.
|
||||||
|
|
@ -414,8 +414,8 @@ func (c *common) decorate(s string) string {
|
||||||
line = 1
|
line = 1
|
||||||
}
|
}
|
||||||
buf := new(strings.Builder)
|
buf := new(strings.Builder)
|
||||||
// Every line is indented at least one tab.
|
// Every line is indented at least 4 spaces.
|
||||||
buf.WriteByte('\t')
|
buf.WriteString(" ")
|
||||||
fmt.Fprintf(buf, "%s:%d: ", file, line)
|
fmt.Fprintf(buf, "%s:%d: ", file, line)
|
||||||
lines := strings.Split(s, "\n")
|
lines := strings.Split(s, "\n")
|
||||||
if l := len(lines); l > 1 && lines[l-1] == "" {
|
if l := len(lines); l > 1 && lines[l-1] == "" {
|
||||||
|
|
@ -423,8 +423,8 @@ func (c *common) decorate(s string) string {
|
||||||
}
|
}
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
// Second and subsequent lines are indented an extra tab.
|
// Second and subsequent lines are indented an additional 4 spaces.
|
||||||
buf.WriteString("\n\t\t")
|
buf.WriteString("\n ")
|
||||||
}
|
}
|
||||||
buf.WriteString(line)
|
buf.WriteString(line)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue