diff --git a/README.md b/README.md index 7b90b1c..282285a 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ one is signed.) ## Version History +* v0.3.4: + * Create a custom interface for just the components of testing.TB + * slogassert actually uses. * v0.3.3: * Export LogMessageMatch.Matches for external use. * Add utility function for testing. diff --git a/slogassert.go b/slogassert.go index 1558526..f9d107f 100644 --- a/slogassert.go +++ b/slogassert.go @@ -37,7 +37,6 @@ import ( "sort" "strings" "sync" - "testing" "time" ) @@ -60,7 +59,19 @@ type Handler struct { m sync.Mutex logMessages []LogMessage - t testing.TB + t Tester +} + +// The Tester interface defines the incoming testing interface. +// +// The standard library *testing.T and *testing.B values conform to this +// already. +// +// If your testing library doesn't have an equivalent of Helper, it is fine +// to implement it as a no-op. +type Tester interface { + Helper() + Fatalf(string, ...any) } // New creates a new testing logger, logging with the given level. @@ -70,7 +81,7 @@ type Handler struct { // // It is recommended to generally call defer handler.AssertEmpty() on // the result of this call. -func New(t testing.TB, leveler slog.Leveler, wrapped slog.Handler) *Handler { +func New(t Tester, leveler slog.Leveler, wrapped slog.Handler) *Handler { if t == nil { panic("t must not be nil for a slogtest.Handler") }