Documentation ¶
Index ¶
- Constants
- func Catch(code func()) (result interface{})
- func Contains(actual_ interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
- func ContainsAll(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func ContainsAny(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func ContainsExactly(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func ContainsInOrder(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func ContainsInPartialOrder(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func Equals(actual interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
- func Errorf(format string, args ...interface{}) os.Error
- func IsFalse(actual interface{}, _ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func IsNil(actual interface{}, _ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func IsNoError(actual interface{}, _ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func IsSame(actual interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
- func IsTrue(actual interface{}, _ interface{}) (match bool, pos Message, neg Message, err os.Error)
- func Main(runner *Runner)
- func MainGoTest(runner *Runner, t *testing.T)
- func RunsNormally(actual interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
- func Satisfies(actual interface{}, criteria interface{}) (match bool, pos Message, neg Message, err os.Error)
- func Values(values ...interface{}) []interface{}
- type Context
- type Equality
- type Error
- type ErrorType
- type Location
- type Matcher
- type Message
- type PrintFormat
- type Printer
- type ResultCollector
- type ResultVisitor
- type Runner
Constants ¶
const ( ALL printMode = iota ONLY_FAILING )
Variables ¶
This section is empty.
Functions ¶
func Catch ¶
func Catch(code func()) (result interface{})
Runs code() and returns whatever value it threw by calling panic(value). Or if panic(value) was not called, returns a special value indicating that no error happened, which can be tested with IsNoError.
func Contains ¶
func Contains(actual_ interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual collection must contain the expected value.
func ContainsAll ¶
func ContainsAll(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual collection must contain all expected elements, but it may contain also other non-expected elements. The order of elements is not significant.
func ContainsAny ¶
func ContainsAny(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual collection must contain at least one of the expected elements.
func ContainsExactly ¶
func ContainsExactly(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual collection must contain all expected elements and nothing else. The order of elements is not significant.
func ContainsInOrder ¶
func ContainsInOrder(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual collection must contain all expected elements, in the same order, and nothing else.
func ContainsInPartialOrder ¶
func ContainsInPartialOrder(actual_ interface{}, expected_ interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual collection must contain all expected objects, in the same order, but it may contain also other non-expected objects. For example [1, 2, 2, 3, 4] contains in partial order [1, 2, 3]. See http://en.wikipedia.org/wiki/Partial_order for further information.
func Equals ¶
func Equals(actual interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual value must equal the expected value. For primitives the equality operator is used. All other objects must implement the Equality interface.
func Errorf ¶
Constructs an error message the same way as fmt.Sprintf(), but the string is created lazily when it is used, if it is used at all. This avoids unnecessary string parsing in matchers, because most of the time there are no failures and thus the error messages are not used.
func IsFalse ¶
func IsFalse(actual interface{}, _ interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual value must be <false>.
func IsNil ¶
The actual value must be <nil>, or a typed nil pointer inside an interface value. See http://groups.google.com/group/golang-nuts/browse_thread/thread/d900674d491ef8d for discussion on how in Go typed nil values can turn into non-nil interface values.
func IsNoError ¶
func IsNoError(actual interface{}, _ interface{}) (match bool, pos Message, neg Message, err os.Error)
Checks whether a call to Catch() returned a special value indicating that panic() was not called by the code. Used together with either Panic or Catch, but not both at the same time.
May be useful in cases when Panic and RunsNormally are not sufficient and you need to do more complicated things with the error value.
func IsSame ¶
func IsSame(actual interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual value must be a pointer to the same object as the expected value.
func Main ¶
func Main(runner *Runner)
Executes the specs which have been added to the Runner and prints the results to stdout. Exits the process after it is finished - with zero or non-zero exit value, depending on whether any specs failed.
func MainGoTest ¶
Executes the specs which have been added to the Runner and prints the results to stdout. Fails the surrounding test if any of the specs fails.
func RunsNormally ¶
func RunsNormally(actual interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
The actual func() must not panic.
This is the same as Panic(IsNoError) except that it prints nicer messages.
Types ¶
type Context ¶
type Context interface { // Creates a child spec for the currently executing spec. Specs can be // nested unlimitedly. The name should describe what is the behaviour being // specified by this spec, and the closure should express the same // specification as code. Specify(name string, closure func()) // Makes an expectation. For example: // c.Expect(theAnswer, Equals, 42) // c.Expect(theAnswer, Not(Equals), 666) // c.Expect(thereIsASpoon, IsFalse) Expect(actual interface{}, matcher Matcher, expected ...interface{}) // Makes an assumption. Otherwise the same as an expectation, // but on failure will not continue executing the child specs. Assume(actual interface{}, matcher Matcher, expected ...interface{}) }
Context controls the execution of the current spec. Child specs can be created with the Specify method.
type Matcher ¶
type Matcher func(actual interface{}, expected interface{}) (match bool, pos Message, neg Message, err os.Error)
Matchers are used in expectations to compare the actual and expected values.
Return values:
match: Should be true when `actual` and `expected` match, otherwise false. pos: Message for a failed expectation. neg: Message for a failed expectation when the matcher is combined with Not. err: Message for an unrecoverable error, for example if the arguments had a wrong type.
func Is ¶
The actual value must satisfy the given criteria as described by the given description.
Like Satisfies but allows to name the criteria. The description and its args are formatted using fmt.Sprintf().
func Not ¶
Negates the meaning of a Matcher. Matches when the original matcher does not match, and the other way around.
type PrintFormat ¶
type PrintFormat interface { PrintPassing(nestingLevel int, name string) PrintFailing(nestingLevel int, name string, errors []*Error) PrintSummary(passCount int, failCount int) }
func DefaultPrintFormat ¶
func DefaultPrintFormat(out io.Writer) PrintFormat
PrintFormat for production use.
func SimplePrintFormat ¶
func SimplePrintFormat(out io.Writer) PrintFormat
PrintFormat for use in only tests. Does not print line numbers, colors or other fancy stuff. Makes comparing as a string easier.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer formats the spec results into a human-readable format.
func NewPrinter ¶
func NewPrinter(format PrintFormat) *Printer
func (*Printer) HideSummary ¶
func (this *Printer) HideSummary()
func (*Printer) ShowOnlyFailing ¶
func (this *Printer) ShowOnlyFailing()
func (*Printer) ShowSummary ¶
func (this *Printer) ShowSummary()
type ResultCollector ¶
type ResultCollector struct {
// contains filtered or unexported fields
}
Collects test results for all specs in a reporting friendly format.
func (*ResultCollector) FailCount ¶
func (r *ResultCollector) FailCount() int
func (*ResultCollector) PassCount ¶
func (r *ResultCollector) PassCount() int
func (*ResultCollector) TotalCount ¶
func (r *ResultCollector) TotalCount() int
func (*ResultCollector) Update ¶
func (r *ResultCollector) Update(spec *specRun)
func (*ResultCollector) Visit ¶
func (r *ResultCollector) Visit(visitor ResultVisitor)
type ResultVisitor ¶
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes the specs and collects their results.
func (*Runner) AddNamedSpec ¶
Adds a spec for later execution. Uses the provided name instead of retrieving the name of the spec function with reflection.
func (*Runner) Results ¶
func (r *Runner) Results() *ResultCollector