ensure

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion struct {
	// contains filtered or unexported fields
}

Assertion, produced by the ensure.That() constructor is a chainable interface for annotating rich assertions, as a complement to the fun/assert and fun/assert/check libraries. Use ensure.That() forms to annotate

func That

func That(that is.That) *Assertion

That constructs a new Assertion with the provided check, as in:

ensure.That(is.True(1 == 1)).Run(t)

func (*Assertion) Add

func (a *Assertion) Add(sub *Assertion) *Assertion

Add adds an assertion object as a subtest of the root assertion.

func (*Assertion) Benchmark

func (a *Assertion) Benchmark() func(*testing.B)

Benchmark creates a sub-benchrmark function, which is suitable for use as an argument to b.Run().

func (*Assertion) Error

func (a *Assertion) Error() *Assertion

Error uses t.Error or b.Error assertions, which mean that the assertion is "continue-on-error" and will not abort the execution of the test in the case of a failure.

func (*Assertion) Fatal

func (a *Assertion) Fatal() *Assertion

Fatal, the default, means that the assertion has "abort-on-error" semantics, and will cause the test to fail when the assertion fails. If there are subtests, they will always run before the test aborts.

func (*Assertion) Log

func (a *Assertion) Log(args ...any) *Assertion

Logs adds a message that is printed on failure in quiet mode, and unconditionally in verbose mode. Operates generally like t.Log() or fmt.Sprint().

func (*Assertion) Logf

func (a *Assertion) Logf(tmpl string, args ...any) *Assertion

Logf adds a message that is printed on failure in quiet mode, and unconditionally in verbose mode. Operates like t.Logf or fmt.Sprintf.

func (*Assertion) Metadata

func (a *Assertion) Metadata(md *dt.Pairs[string, any]) *Assertion

Metadata adds structured logging pairs, which can be constructed using the is.Plist().Add(k,v) constructor and chaining.

Each pair is logged as it's own Log statement.

func (*Assertion) Queit

func (a *Assertion) Queit() *Assertion

Quiet toggles the logging behavior to be "quiet" (e.g. only, log in the case of that the Assertion fails.) This is the default.

func (*Assertion) Run

func (a *Assertion) Run(t testing.TB)

Run rus the test and produces the output.

func (*Assertion) Test

func (a *Assertion) Test() func(*testing.T)

Test creates a test function, which is suitable for use as an argument to t.Run() as a subtest.

func (*Assertion) That

func (a *Assertion) That(t is.That) *Assertion

That sets a new assertion handler function, overriding (potentially) the assertion created when the Assertion was created. If the assertion has been run, this operation is always a noop.

func (*Assertion) Verbose

func (a *Assertion) Verbose() *Assertion

Verbose toggles the logging behavior to log all messages even when the test succeeds.

func (*Assertion) With

func (a *Assertion) With(name string, op func(ensure *Assertion)) *Assertion

With creates a subtest that is un-conditionally executed after the assertions main check runs.

Subtests are always run after the root of their "parent" tasks, are run unconditionally in the order they were added.

It is invalid and will panic if you call .Run() on the assertion provided to the With() function.

Directories

Path Synopsis
Package is contains a simple assertion library for the fun/ensure testing framework.
Package is contains a simple assertion library for the fun/ensure testing framework.

Jump to

Keyboard shortcuts

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