Documentation
¶
Overview ¶
Package att (leaktest All The things!) extends fortyw2's leaktest by wrapping it in an ErrorReporter. When using leaktest for actual tests, the original should be used, passing a *testing.T or *testing.B to it, for proper error reporting and test failure. If you want to use this in your own programs, however, possibly only for a few moments or in certain modes, this package helps make that trivially easy.
Example ¶
er := New()
defer er.Dump()
defer er.Check()() // note the *two* sets of parens!
// do some stuff
// at the end, if no additional goros are still running when er.Check()'s closure fires,
// then when Dump() fires, there is nothing to dump, otherwise there is!
// or maybe somewhere else you want to save an error for later:
var err error
er.Append(err)
// or even unformatted
er.Errorf("This crazy! %s, %d", "So crazy", 42)
// Maybe not, though
er.Reset()
Index ¶
- type ErrorReporter
- func (m *ErrorReporter) Append(e error)
- func (m *ErrorReporter) Check() func()
- func (m *ErrorReporter) CheckContext(ctx context.Context) func()
- func (m *ErrorReporter) CheckTimeout(timeout time.Duration) func()
- func (m *ErrorReporter) Count() int
- func (m *ErrorReporter) Dump()
- func (m *ErrorReporter) DumpLog(log *log.Logger)
- func (m *ErrorReporter) Errorf(format string, a ...any)
- func (m *ErrorReporter) Errors() []error
- func (m *ErrorReporter) Reset()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorReporter ¶
type ErrorReporter struct {
// contains filtered or unexported fields
}
ErrorReporter is a goro-safe leaktest.ErrorReporter. Use New() as the zero value is unsafe.
func (*ErrorReporter) Check ¶
func (m *ErrorReporter) Check() func()
Check is a passthtough from leaktest.Check.
func (*ErrorReporter) CheckContext ¶
func (m *ErrorReporter) CheckContext(ctx context.Context) func()
CheckContext is a passthtough from leaktest.CheckContext.
func (*ErrorReporter) CheckTimeout ¶
func (m *ErrorReporter) CheckTimeout(timeout time.Duration) func()
CheckTimeout is a passthtough from leaktest.CheckTimeout.
func (*ErrorReporter) Count ¶
func (m *ErrorReporter) Count() int
Count returns the number of accumulated errors.
func (*ErrorReporter) Dump ¶
func (m *ErrorReporter) Dump()
Dump will Println all of the accumulated errors.
func (*ErrorReporter) DumpLog ¶
func (m *ErrorReporter) DumpLog(log *log.Logger)
DumpLog will Println all of the accumulated errors to the specified Logger
func (*ErrorReporter) Errorf ¶
func (m *ErrorReporter) Errorf(format string, a ...any)
Errorf is a formatted error appender, satisfying leaktest.ErrorReporter.
func (*ErrorReporter) Errors ¶
func (m *ErrorReporter) Errors() []error
Errors returns a slice of the accumulated errors.
func (*ErrorReporter) Reset ¶
func (m *ErrorReporter) Reset()
Reset removes all accumulated errors. Generally only useful in sync.Pool situations.