Documentation ¶
Overview ¶
Package tt supports table-driven tests with little boilerplate.
A typical use of this package looks like this:
// Function being tested func Neg(i int) { return -i } func TestNeg(t *testing.T) { Test(t, Neg, // Unnamed test case Args(1).Rets(-1), // Named test case It("returns 0 for 0").Args(0).Rets(0), ) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CommonCmpOpt = cmp.Options([]cmp.Option{ cmp.Transformer("transformList", transformList), cmp.Transformer("transformMap", transformMap), cmp.Comparer(func(x, y *big.Int) bool { return x.Cmp(y) == 0 }), cmp.Comparer(func(x, y *big.Rat) bool { return x.Cmp(y) == 0 }), })
CommonCmpOpt is cmp.Option shared between tt and evaltest.
Functions ¶
Types ¶
type Case ¶
type Case struct {
// contains filtered or unexported fields
}
Case represents a test case. It has setter methods that augment and return itself, so they can be chained like It(...).Args(...).Rets(...).
func Args ¶
Args is equivalent to It("").args(...). It is useful when the test case is trivial and doesn't need a description; for more complex or interesting test cases, use It instead.
func (*Case) Args ¶ added in v0.20.0
Args modifies the Case to pass the given arguments. It returns the receiver.
func (*Case) Rets ¶
Rets modifies the Case to expect the given return values. It returns the receiver.
The arguments may implement the Matcher interface, in which case its Match method is called with the actual return value. Otherwise, reflect.DeepEqual is used to determine matches.
type FnDescriptor ¶ added in v0.20.0
type FnDescriptor struct {
// contains filtered or unexported fields
}
FnDescriptor describes a function to test. It has setter methods that augment and return itself, so they can be chained like Fn(...).Named(...).ArgsFmt(...).
func (*FnDescriptor) ArgsFmt ¶ added in v0.20.0
func (fn *FnDescriptor) ArgsFmt(s string) *FnDescriptor
ArgsFmt sets the string for formatting arguments in test error messages. It returns the receiver.
func (*FnDescriptor) Named ¶ added in v0.20.0
func (fn *FnDescriptor) Named(name string) *FnDescriptor
Named sets the name of the function. This is only necessary for methods and local closures; package-level functions will have their name automatically inferred via reflection. It returns the receiver.
type Matcher ¶
type Matcher interface { // Match reports whether a return value is considered a match. The argument // is of type RetValue so that it cannot be implemented accidentally. Match(RetValue) bool }
Matcher wraps the Match method.
Values that implement this interface can be passed to *Case.Rets to control the matching algorithm for return values.
var Any Matcher = anyMatcher{}
Any is a Matcher that matches any value.