att

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

README

att

import "github.com/cognusion/go-leaktest-att"

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

Examples
Package files

att.go

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 New
func New() *ErrorReporter

New returns a reference to an initialized ErrorReporter

func (*ErrorReporter) Append
func (m *ErrorReporter) Append(e error)

Append is an error appender.

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.


Generated by godoc2md

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

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 New

func New() *ErrorReporter

New returns a reference to an initialized ErrorReporter

func (*ErrorReporter) Append

func (m *ErrorReporter) Append(e error)

Append is an error appender.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL