package tt
import "src.elv.sh/pkg/tt"
Package tt supports table-driven tests with little boilerplate.
See the test case for this package for example usage.
Index ¶
- func Test(t T, fn *FnToTest, tests Table)
- type Case
- type FnToTest
- func Fn(name string, body interface{}) *FnToTest
- func (fn *FnToTest) ArgsFmt(s string) *FnToTest
- func (fn *FnToTest) RetsFmt(s string) *FnToTest
- type Matcher
- type RetValue
- type T
- type Table
Package Files ¶
func Test ¶
Test tests a function against test cases.
type Case ¶
type Case struct {
// contains filtered or unexported fields
}
Case represents a test case. It is created by the C function, and offers setters that augment and return itself; those calls can be chained like C(...).Rets(...).
func Args ¶
Args returns a new Case with the given arguments.
func (*Case) Rets ¶
Rets modifies the test case so that it requires the return values to match the given 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 FnToTest ¶
type FnToTest struct {
// contains filtered or unexported fields
}
FnToTest describes a function to test.
func Fn ¶
Fn makes a new FnToTest with the given function name and body.
func (*FnToTest) ArgsFmt ¶
ArgsFmt sets the string for formatting arguments in test error messages, and return fn itself.
func (*FnToTest) RetsFmt ¶
RetsFmt sets the string for formatting return values in test error messages, and return fn itself.
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.
Any is a Matcher that matches any value.
type RetValue ¶
type RetValue interface{}
RetValue is an empty interface used in the Matcher interface.
type T ¶
T is the interface for accessing testing.T.
type Table ¶
Table represents a test table.
Package tt imports 3 packages (graph) and is imported by 1 packages. Updated 1 month ago.
Tools for package owners.