From bfb325c96f2ef68e40662a5c715e1e45058c857c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 19 Oct 2014 17:21:51 +0200 Subject: [PATCH] pkg/test: fix after accidentally checking in WIP change in a82f603dbc4624d97dcc8884052dac58f702dd77 Change-Id: Ide7488005bb750b009c40a57443d6bb0b62818c3 --- pkg/test/test.go | 12 ++++++++---- pkg/test/test_test.go | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/test/test.go b/pkg/test/test.go index a87b4acde..222f34e70 100644 --- a/pkg/test/test.go +++ b/pkg/test/test.go @@ -20,6 +20,7 @@ import ( "log" "os" "strconv" + "strings" "testing" ) @@ -34,7 +35,7 @@ func BrokenTest(t *testing.T) { // TLog changes the log package's output to log to t and returns a function // to reset it back to stderr. func TLog(t testing.TB) func() { - log.SetOutput(&twriter{t: t}) + log.SetOutput(twriter{t: t}) return func() { log.SetOutput(os.Stderr) } @@ -44,11 +45,14 @@ type twriter struct { t testing.TB } -func (w *twriter) Write(p []byte) (n int, err error) { - t.Logf("%s", p) +func (w twriter) Write(p []byte) (n int, err error) { + if w.t != nil { + w.t.Log(strings.TrimSuffix(string(p), "\n")) + } + return len(p), nil } // NewLogger returns a logger that logs to t with the given prefix. func NewLogger(t *testing.T, prefix string) *log.Logger { - return log.New(&twriter{t: t}, prefix, log.LstdFlags) + return log.New(twriter{t: t}, prefix, log.LstdFlags) } diff --git a/pkg/test/test_test.go b/pkg/test/test_test.go index a83c01ca2..169f6330f 100644 --- a/pkg/test/test_test.go +++ b/pkg/test/test_test.go @@ -48,8 +48,7 @@ func TestTLog(t *testing.T) { want := []string{ "hello", "hello", - "some text", - "and more text", + "some text\nand more text", } if !reflect.DeepEqual(tb.log, want) { t.Errorf("Got %q; want %q", tb.log, want)