pkg/test: fix after accidentally checking in WIP change in a82f603dbc

Change-Id: Ide7488005bb750b009c40a57443d6bb0b62818c3
This commit is contained in:
Brad Fitzpatrick 2014-10-19 17:21:51 +02:00
parent a93cb4d9b9
commit bfb325c96f
2 changed files with 9 additions and 6 deletions

View File

@ -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)
}

View File

@ -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)