Package tt supports table-driven tests with little boilerplate.

    See the test case for this package for example usage.



    This section is empty.


    This section is empty.


    func Test

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

      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

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

          Args returns a new Case with the given arguments.

          func (*Case) Rets

          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

            type FnToTest struct {
            	// contains filtered or unexported fields

              FnToTest describes a function to test.

              func Fn

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

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

                func (*FnToTest) ArgsFmt

                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

                  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

                    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

                        type RetValue interface{}

                          RetValue is an empty interface used in the Matcher interface.

                          type T

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

                            T is the interface for accessing testing.T.

                            type Table

                            type Table []*Case

                              Table represents a test table.

                              Source Files