aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorJean de Klerk <deklerk@google.com>2018-07-31 18:10:42 -0700
committerIan Lance Taylor <iant@golang.org>2019-10-22 19:21:02 +0000
commita813d3c788b4ec58032616e8d269ee65d1b10085 (patch)
treeae82b1d8b5b6b18b5c474b9b62cae270e2fbe30d /src/testing/testing.go
parent7416315e3358b0bc2774c92f39d8f7c4b33790ad (diff)
downloadgo-a813d3c788b4ec58032616e8d269ee65d1b10085.tar.gz
go-a813d3c788b4ec58032616e8d269ee65d1b10085.zip
testing: stream log output in verbose mode
Fixes #24929 Change-Id: Icc426068cd73b75b78001f55e1e5d81ccebbe854 Reviewed-on: https://go-review.googlesource.com/c/go/+/127120 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 6ab9b79196..bbb10263c3 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -479,6 +479,9 @@ func (c *common) decorate(s string, skip int) string {
buf := new(strings.Builder)
// Every line is indented at least 4 spaces.
buf.WriteString(" ")
+ if c.chatty {
+ fmt.Fprintf(buf, "%s: ", c.name)
+ }
fmt.Fprintf(buf, "%s:%d: ", file, line)
lines := strings.Split(s, "\n")
if l := len(lines); l > 1 && lines[l-1] == "" {
@@ -662,9 +665,7 @@ func (c *common) log(s string) {
func (c *common) logDepth(s string, depth int) {
c.mu.Lock()
defer c.mu.Unlock()
- if !c.done {
- c.output = append(c.output, c.decorate(s, depth+1)...)
- } else {
+ if c.done {
// This test has already finished. Try and log this message
// with our parent. If we don't have a parent, panic.
for parent := c.parent; parent != nil; parent = parent.parent {
@@ -676,6 +677,12 @@ func (c *common) logDepth(s string, depth int) {
}
}
panic("Log in goroutine after " + c.name + " has completed")
+ } else {
+ if c.chatty {
+ fmt.Print(c.decorate(s, depth+1))
+ return
+ }
+ c.output = append(c.output, c.decorate(s, depth+1)...)
}
}