quicktest

package
v0.0.0-...-97ebcb8 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: Apache-2.0, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

/ Package quicktest implements assertion and other helpers wrapped around the standard library's testing types. package quicktest

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert[T any](tb testing.TB, got T, op Checker[T], comment ...Comment)

Assert checks that the provided argument passes the given check and calls tb.Error otherwise, including any Comment arguments in the failure.

func Check

func Check[T any](tb testing.TB, got T, op Checker[T], comment ...Comment) bool

Check checks that the provided argument passes the given check and calls tb.Fatal otherwise, including any Comment arguments in the failure.

func Patch

func Patch[T any](tb testing.TB, dest *T, value T)

Patch sets *dest to value, then adds a Cleanup to tb that will set it back to its original value at the end of the test.

Types

type Checker

type Checker[T any] interface {
	// Check checks that the provided argument passes the check.
	// On failure, the returned error is printed along with
	// the checker arguments (obtained by calling ArgNames and Args)
	// and key-value pairs added by calling the note function.
	//
	// If Check returns ErrSilent, neither the checker arguments nor
	// the error are printed; values with note are still printed.
	Check(got T, note func(key string, value interface{})) error

	// ArgNames returns the arguments passed to the checker.
	ArgNames() []string

	// Args returns the arguments corresponding to ArgNames.
	Args() []interface{}
}

Checker is implemented by types used as part of Check/Assert invocations. The type parameter will be the type of the first argument passed to Check or Assert.

func DeepEquals

func DeepEquals[T any](want T) Checker[T]

func Equals

func Equals[T comparable](want T) Checker[T]

Equals checks that the argument is equal to want.

func IsZero

func IsZero[T any]() Checker[T]

IsZero checks that a value is the zero value for its type. Maybe this might be better with a shorter name like Z.

func Not

func Not[T any](c Checker[T]) Checker[T]

type Comment

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

func (Comment) String

func (c Comment) String() string

String outputs a string formatted according to the stored format specifier and args.

Jump to

Keyboard shortcuts

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