elvish: github.com/elves/elvish/pkg/tt Index | Files

package tt

import "github.com/elves/elvish/pkg/tt"

Package tt supports table-driven tests with little boilerplate.

See the test case for this package for example usage.

Index

Package Files

tt.go

func Test Uses

func Test(t T, fn *FnToTest, tests Table)

Test tests a function against test cases.

type Case Uses

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 Uses

func Args(args ...interface{}) *Case

Args returns a new Case with the given arguments.

func (*Case) Rets Uses

func (c *Case) Rets(matchers ...interface{}) *Case

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 Uses

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

FnToTest describes a function to test.

func Fn Uses

func Fn(name string, body interface{}) *FnToTest

Fn makes a new FnToTest with the given function name and body.

func (*FnToTest) ArgsFmt Uses

func (fn *FnToTest) ArgsFmt(s string) *FnToTest

ArgsFmt sets the string for formatting arguments in test error messages, and return fn itself.

func (*FnToTest) RetsFmt Uses

func (fn *FnToTest) RetsFmt(s string) *FnToTest

RetsFmt sets the string for formatting return values in test error messages, and return fn itself.

type Matcher Uses

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.

var Any Matcher = anyMatcher{}

Any is a Matcher that matches any value.

type RetValue Uses

type RetValue interface{}

RetValue is an empty interface used in the Matcher interface.

type T Uses

type T interface {
    Helper()
    Errorf(format string, args ...interface{})
}

T is the interface for accessing testing.T.

type Table Uses

type Table []*Case

Table represents a test table.

Package tt imports 3 packages (graph) and is imported by 1 packages. Updated 2020-02-22. Refresh now. Tools for package owners.