diff --git a/assertions.go b/assertions.go index c65919f..192419d 100644 --- a/assertions.go +++ b/assertions.go @@ -9,20 +9,28 @@ import ( "github.com/stretchr/testify/assert" ) -type testingT struct { +// TestingT is an interface wrapper around *testing.T. +type TestingT interface { + Errorf(format string, args ...interface{}) + FailNow() + Log(args ...interface{}) + Logf(format string, args ...interface{}) +} + +type tError struct { err error } -func (t *testingT) Errorf(format string, args ...interface{}) { +func (t *tError) Errorf(format string, args ...interface{}) { t.err = fmt.Errorf(format, args...) // nolint: goerr113 } -func (t *testingT) LastError() error { +func (t *tError) LastError() error { return t.err } -func t() *testingT { - return &testingT{} +func teeError() *tError { + return &tError{} } // AssertState asserts console state. diff --git a/assertions_test.go b/assertions_test.go index 1bf6805..47ba2c1 100644 --- a/assertions_test.go +++ b/assertions_test.go @@ -9,8 +9,8 @@ import ( func TestTestingT_LastError(t *testing.T) { t.Parallel() - newT := &testingT{} - newT.Errorf("error: %s", "unknown") + tee := teeError() + tee.Errorf("error: %s", "unknown") - assert.EqualError(t, newT.LastError(), `error: unknown`) + assert.EqualError(t, tee.LastError(), `error: unknown`) } diff --git a/manager.go b/manager.go index 4b28d0b..30a4594 100644 --- a/manager.go +++ b/manager.go @@ -1,7 +1,6 @@ package consoledog import ( - "testing" "time" "github.com/Netflix/go-expect" @@ -21,7 +20,7 @@ type Option func(m *Manager) // Manager manages console and its state. type Manager struct { - test *testing.T + test TestingT console *expect.Console state *vt10x.State @@ -98,7 +97,7 @@ func (m *Manager) Flush() { func (m *Manager) isConsoleOutput(expected *godog.DocString) error { m.Flush() - t := t() + t := teeError() AssertState(t, m.state, expected.Content) return t.LastError() @@ -119,7 +118,7 @@ func (m *Manager) WithCloser(c Closer) *Manager { } // New initiates a new console Manager. -func New(t *testing.T, options ...Option) *Manager { // nolint: thelper +func New(t TestingT, options ...Option) *Manager { m := &Manager{ test: t, }