tt

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2018 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package tt supports table-driven tests with little boilerplate.

See the test case for this package for example usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Test

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

Test tests a function against test cases.

Types

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 added in v0.12.0

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.

type RetValue added in v0.12.0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL