b5d71ea779
When tests fail, only the logs for the failing run are dumped to the console which helps in diagnosis. This is easily added to other test scenarios as they come up.
31 lines
550 B
Go
31 lines
550 B
Go
package testutil
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLogger(t testing.TB) *log.Logger {
|
|
return log.New(&testWriter{t}, "test: ", log.LstdFlags)
|
|
}
|
|
|
|
func TestLoggerWithName(t testing.TB, name string) *log.Logger {
|
|
return log.New(&testWriter{t}, "test["+name+"]: ", log.LstdFlags)
|
|
}
|
|
|
|
func TestWriter(t testing.TB) io.Writer {
|
|
return &testWriter{t}
|
|
}
|
|
|
|
type testWriter struct {
|
|
t testing.TB
|
|
}
|
|
|
|
func (tw *testWriter) Write(p []byte) (n int, err error) {
|
|
tw.t.Helper()
|
|
tw.t.Log(strings.TrimSpace(string(p)))
|
|
return len(p), nil
|
|
}
|