From 2330ae8cf80e4fa5e6e2909e0c8562fd3d9beec6 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Mon, 25 Jan 2016 16:27:23 +0100 Subject: testing: finish implementation of subtests API not exposed yet. Change-Id: Iaba0adc0fa1ae8075e6b56796f99ee8db9177a78 Reviewed-on: https://go-review.googlesource.com/18896 Reviewed-by: Russ Cox --- src/testing/testing.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/testing/testing.go') 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) -- cgit v1.3