aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorMarcel van Lohuizen <mpvl@golang.org>2016-01-25 16:27:23 +0100
committerMarcel van Lohuizen <mpvl@golang.org>2016-03-18 12:30:39 +0000
commit2330ae8cf80e4fa5e6e2909e0c8562fd3d9beec6 (patch)
treee3ba4059278342c56806d26f27343209686b12dd /src/testing/testing.go
parent1857bfca134261ab2e0fc1adcf6a974f550d430a (diff)
downloadgo-2330ae8cf80e4fa5e6e2909e0c8562fd3d9beec6.tar.xz
testing: finish implementation of subtests
API not exposed yet. Change-Id: Iaba0adc0fa1ae8075e6b56796f99ee8db9177a78 Reviewed-on: https://go-review.googlesource.com/18896 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 13739ccd9d..0aa60d9ddc 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -273,6 +273,29 @@ func (c *common) flushToParent(format string, args ...interface{}) {
c.output = c.output[:0]
}
+type indenter struct {
+ c *common
+}
+
+func (w indenter) Write(b []byte) (n int, err error) {
+ n = len(b)
+ for len(b) > 0 {
+ end := bytes.IndexByte(b, '\n')
+ if end == -1 {
+ end = len(b)
+ } else {
+ end++
+ }
+ // An indent of 4 spaces will neatly align the dashes with the status
+ // indicator of the parent.
+ const indent = " "
+ w.c.output = append(w.c.output, indent...)
+ w.c.output = append(w.c.output, b[:end]...)
+ b = b[end:]
+ }
+ return
+}
+
// fmtDuration returns a string representing d in the form "87.00s".
func fmtDuration(d time.Duration) string {
return fmt.Sprintf("%.2fs", d.Seconds())
@@ -542,6 +565,7 @@ func (t *T) run(name string, f func(t *T)) bool {
},
context: t.context,
}
+ t.w = indenter{&t.common}
if *chatty {
fmt.Printf("=== RUN %s\n", t.name)