Documentation ¶
Overview ¶
Package tdutil allows to write unit tests for go-testdeep helpers and so provides some helpful functions.
It is not intended to be used in tests outside go-testdeep and its helpers perimeter.
Index ¶
- func BuildTestName(args ...any) string
- func FbuildTestName(w io.Writer, args ...any)
- func FormatString(s string) string
- func MapEach(m reflect.Value, fn func(k, v reflect.Value) bool) bool
- func MapEachValue(m reflect.Value, fn func(k reflect.Value) bool) bool
- func MapSortedKeys(m reflect.Value) []reflect.Value
- func MapSortedValues(m reflect.Value) []reflect.Value
- func SortableValues(s []reflect.Value) sort.Interface
- func SpewString(val any) string
- type T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildTestName ¶
BuildTestName builds a string from given args.
If optional first args is a string containing at least one %, args are passed as is to fmt.Fprintf, else they are passed to fmt.Fprint.
func FbuildTestName ¶
FbuildTestName builds a string from given args.
If optional first args is a string containing at least one %, args are passed as is to fmt.Fprintf, else they are passed to fmt.Fprint.
func FormatString ¶
FormatString formats s to a printable string, trying to enclose it in double-quotes or back-quotes and defaulting to using SpewString.
func MapEach ¶ added in v1.1.0
MapEach calls fn for each key/value pair of map m. If fn returns false, it will not be called again.
func MapEachValue ¶ added in v1.1.0
MapEachValue calls fn for each value of map m. If fn returns false, it will not be called again.
func MapSortedKeys ¶ added in v1.1.0
MapSortedKeys returns a slice of all sorted keys of map m. It panics if m's reflect.Kind is not reflect.Map.
func MapSortedValues ¶ added in v1.1.0
MapSortedValues returns a slice of all sorted values of map m. It panics if m's reflect.Kind is not reflect.Map.
func SortableValues ¶ added in v1.1.0
SortableValues is used to allow the sorting of a []reflect.Value slice. It is used with the standard sort package:
vals := []reflect.Value{a, b, c, d} sort.Sort(SortableValues(vals)) // vals contents now sorted
Replace sort.Sort by sort.Stable for a stable sort. See sort documentation.
Sorting rules are as follows:
- nil is always lower
- different types are sorted by their name
- false is lesser than true
- float and int numbers are sorted by their value
- complex numbers are sorted by their real, then by their imaginary parts
- strings are sorted by their value
- map: shorter length is lesser, then sorted by address
- functions, channels and unsafe pointer are sorted by their address
- struct: comparison is spread to each field
- pointer: comparison is spread to the pointed value
- arrays: comparison is spread to each item
- slice: comparison is spread to each item, then shorter length is lesser
- interface: comparison is spread to the value
Cyclic references are correctly handled.
Types ¶
type T ¶
T can be used in tests, to test testing.T behavior as it overrides testing.T.Run method.
func NewT ¶ added in v1.2.0
NewT returns a new *T instance. name is the string returned by method Name.
func (*T) CatchFailNow ¶ added in v1.10.0
CatchFailNow returns true if a T.FailNow, T.Fatal or T.Fatalf call occurred during the execution of fn.
func (*T) FailNow ¶ added in v1.10.0
func (t *T) FailNow()
FailNow simulates the original testing.T.FailNow using panic. T.CatchFailNow should be used to properly intercept it.
func (*T) Fatal ¶ added in v1.10.0
Fatal simulates the original testing.T.Fatal.
func (*T) Fatalf ¶ added in v1.10.0
Fatal simulates the original testing.T.Fatalf.
func (*T) LogBuf ¶
LogBuf is an ugly hack allowing to access internal testing.T log buffer. Keep cool, it is only used for internal unit tests.