add new Logfer interface This is for convenience. The client can now call pretty.Ldiff(t, a, b) in tests rather than looping over the results of Diff.
diff --git a/diff.go b/diff.go index 6df2f86..b08522d 100644 --- a/diff.go +++ b/diff.go
@@ -44,6 +44,25 @@ diffPrinter{w: p}.diff(reflect.ValueOf(a), reflect.ValueOf(b)) } +type Logfer interface { + Logf(format string, a ...interface{}) +} + +// logprintfer calls Fprintf on w for each Printf call +// with a trailing newline. +type logprintfer struct{ l Logfer } + +func (p *logprintfer) Printf(format string, a ...interface{}) { + p.l.Logf(format, a...) +} + +// Ldiff prints to l a description of the differences between a and b. +// It calls Logf once for each difference, with no trailing newline. +// The standard library testing.T and testing.B are Logfers. +func Ldiff(l Logfer, a, b interface{}) { + Pdiff(&logprintfer{l}, a, b) +} + type diffPrinter struct { w Printfer l string // label
diff --git a/diff_test.go b/diff_test.go index eab6c47..c47c9f0 100644 --- a/diff_test.go +++ b/diff_test.go
@@ -3,10 +3,17 @@ import ( "bytes" "fmt" + "log" "testing" "unsafe" ) +var ( + _ Logfer = (*testing.T)(nil) + _ Logfer = (*testing.B)(nil) + _ Printfer = (*log.Logger)(nil) +) + type difftest struct { a interface{} b interface{}