errs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package errs allows for safe error handling in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(t Testing, err error)

Check checks for an error, stopping the test and failing if one is encountered.

func Defer

func Defer(t Testing, fn func() error)

Defer checks if something producing an error while in defer.

func Must

func Must[T any](v T, err error) func(Testing) T

Must returns a function that evaluates the given parameters and fails the tests immediately if err != nil.

func Must2

func Must2[T1, T2 any](t1 T1, t2 T2, err error) func(Testing) (T1, T2)

Must2 is the same as Must but for returning two values.

Types

type TestMain

type TestMain struct {
	*testing.M
	// contains filtered or unexported fields
}

TestMain is a wrapper to help with testing a TestMain function.

func NewTestMain

func NewTestMain(m *testing.M) *TestMain

NewTestMain creates a new TestMain wrapping testing.M.

func (*TestMain) Errorf

func (t *TestMain) Errorf(s string, a ...interface{})

Errorf logs to slog.Error.

func (*TestMain) Exit

func (t *TestMain) Exit()

func (*TestMain) FailNow

func (t *TestMain) FailNow()

FailNow causes a nil panic.

func (*TestMain) Helper

func (t *TestMain) Helper()

Helper is a noop.

func (*TestMain) Logf

func (t *TestMain) Logf(s string, a ...any)

Logf logs to slog.Info.

func (*TestMain) Run

func (t *TestMain) Run()

Run runs the tests saving the return code for exiting later.

type Testing

type Testing interface {
	Helper()
	Logf(string, ...any)
	require.TestingT
}

Testing is implemented by testing.T and testing.B

Jump to

Keyboard shortcuts

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