Package functest
Overview ▹
Index ▹
type Case ¶
Case is a test case to run.
Test cases can be either named or unnamed, depending on how they're created. Naming cases is optional; all failures messages aim to have useful output and include the input to the function.
Unless the function's arity is zero, all cases should have their input set with In.
The case's expected output can be set with Want and/or Check.
type Case struct {
// contains filtered or unexported fields
}
func (*Case) Check ¶
func (c *Case) Check(checker func(Result) error) *Case
Check adds a function to check the result of the case's function call. It is a low-level function when Want is insufficient. For instance, it allows checking whether a function panics. If no checker functions are registered, function panics are considered a test failure.
Check modifies and returns c. Callers my use both Want and Check, and may use Check multiple times.
func (*Case) In ¶
func (c *Case) In(args ...interface{}) *Case
In sets the arguments of c used to call f.
func (*Case) Want ¶
func (c *Case) Want(result ...interface{}) *Case
Want sets the expected result values of the test case. Want modifies and returns c. Callers my use both Want and Check.
type Func ¶
Func is a wrapper around a func to test. It must be created with New.
type Func struct { // Name is the name of the function to use in error messages. // In most cases it is initialized by New, unless the function // being tested is an anonymous function. Name string // contains filtered or unexported fields }
func New ¶
func New(f interface{}) *Func
New wraps a function for testing. The provided value f must be a function or method.
func (*Func) Case ¶
func (f *Func) Case(name string) *Case
Case returns a new named case. It should be modified before use.
func (*Func) In ¶
func (f *Func) In(args ...interface{}) *Case
In returns a new unnamed test case. It will be identified by its arguments only.
func (*Func) Test ¶
func (f *Func) Test(t testing.TB, cases ...*Case)
Test runs the provided test cases against f. If any test cases fail, t.Errorf is called.
type Result ¶
Result is the result of a function call, for use with Check.
type Result struct { // Result is the return value(s) of the function. Result []interface{} // Panic is the panic value of the function. Panic interface{} // Panicked is whether the function paniced. // It can be used to determine whether a function // called panic(nil). Panicked bool }