gocheck

package module
v0.0.0-...-79f35df Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2011 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Suite

func Suite(suite interface{}) interface{}

Register the given value as a test suite to be run. Any methods starting with the Test prefix in the given value will be considered as a test to be run.

func TestingT

func TestingT(testingT *testing.T)

Run all test suites registered with the Suite() function, printing results to stdout, and reporting any failures back to the 'testing' module.

Types

type BugInfo

type BugInfo interface {
	GetBugInfo() string
}

BugInfo is the interface which must be supported for attaching extra information to checks. See the Bug() function for details.

func Bug

func Bug(format string, args ...interface{}) BugInfo

Bug enables attaching some information to Assert() or Check() calls. If the checker test fails, the provided arguments will be passed to fmt.Sprintf(), and will be presented next to the logged failure.

For example:

c.Assert(l, Equals, 8192, Bug("Buffer size is incorrect, bug #123"))
c.Assert(v, Equals, 42, Bug("Iteration #%d", i))

type C

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

func (*C) Assert

func (c *C) Assert(obtained interface{}, checker Checker, args ...interface{})

Ensure that the first value matches with the expected value. What matching means is defined by the provided checker. In case they do not match, an error will be logged, the test will be marked as failed, and the test execution will stop. Some checkers may not need the expected argument (e.g. IsNil). In either case, any extra arguments provided to the function will be logged next to the reported problem when the matching fails. This is a handy way to provide problem-specific hints.

func (*C) Check

func (c *C) Check(obtained interface{}, checker Checker, args ...interface{}) bool

Verify if the first value matches with the expected value. What matching means is defined by the provided checker. In case they do not match, an error will be logged, the test will be marked as failed, and the test execution will continue. Some checkers may not need the expected argument (e.g. IsNil). In either case, any extra arguments provided to the function will be logged next to the reported problem when the matching fails. This is a handy way to provide problem-specific hints.

func (*C) Error

func (c *C) Error(args ...interface{})

Log an error into the test error output, and mark the test as failed. The provided arguments will be assembled together into a string using fmt.Sprint().

func (*C) Errorf

func (c *C) Errorf(format string, args ...interface{})

Log an error into the test error output, and mark the test as failed. The provided arguments will be assembled together into a string using fmt.Sprintf().

func (*C) ExpectFailure

func (c *C) ExpectFailure(reason string)

Expect the currently running test to fail, for the given reason. If the test does not fail, an error will be reported to raise the attention to this fact. The reason string is just a summary of why the given test is supposed to fail. This method is useful to temporarily disable tests which cover well known problems until a better time to fix the problem is found, without forgetting about the fact that a failure still exists.

func (*C) Fail

func (c *C) Fail()

Mark the currently running test as failed. Something ought to have been previously logged so that the developer knows what went wrong. The higher level helper functions will fail the test and do the logging properly.

func (*C) FailNow

func (c *C) FailNow()

Mark the currently running test as failed, and stop running the test. Something ought to have been previously logged so that the developer knows what went wrong. The higher level helper functions will fail the test and do the logging properly.

func (*C) Failed

func (c *C) Failed() bool

Return true if the currently running test has already failed.

func (*C) Fatal

func (c *C) Fatal(args ...interface{})

Log an error into the test error output, mark the test as failed, and stop the test execution. The provided arguments will be assembled together into a string using fmt.Sprint().

func (*C) Fatalf

func (c *C) Fatalf(format string, args ...interface{})

Log an error into the test error output, mark the test as failed, and stop the test execution. The provided arguments will be assembled together into a string using fmt.Sprintf().

func (*C) GetTestLog

func (c *C) GetTestLog() string

Return the current test error output.

func (*C) Log

func (c *C) Log(args ...interface{})

Log some information into the test error output. The provided arguments will be assembled together into a string using fmt.Sprint().

func (*C) Logf

func (c *C) Logf(format string, args ...interface{})

Log some information into the test error output. The provided arguments will be assembled together into a string using fmt.Sprintf().

func (*C) MkDir

func (c *C) MkDir() string

Create a new temporary directory which is automatically removed after the suite finishes running.

func (*C) Skip

func (c *C) Skip(reason string)

Skip the running test, for the given reason. If used within SetUpTest, the individual test being set up will be skipped, and in SetUpSuite it will cause the whole suite to be skipped.

func (*C) Succeed

func (c *C) Succeed()

Mark the currently running test as succeeded, undoing any previous failures.

func (*C) SucceedNow

func (c *C) SucceedNow()

Mark the currently running test as succeeded, undoing any previous failures, and stop running the test.

type Checker

type Checker interface {
	Info() *CheckerInfo
	Check(params []interface{}, names []string) (result bool, error string)
}

The Checker interface must be provided by checkers used with the c.Assert() and c.Check() verification methods.

var Equals Checker = &equalsChecker{
	&CheckerInfo{Name: "Equals", Params: []string{"obtained", "expected"}},
}

The Equals checker verifies that the obtained value is deep-equal to the expected value. The check will work correctly even when facing arrays, interfaces, and values of different types (which always fail the test).

For example:

c.Assert(value, Equals, 42)
c.Assert(array, Equals, []string{"hi", "there"})
var FitsTypeOf Checker = &fitsTypeChecker{
	&CheckerInfo{Name: "FitsTypeOf", Params: []string{"obtained", "sample"}},
}

The FitsTypeOf checker verifies that the obtained value is assignable to a variable with the same type as the provided sample value.

For example:

c.Assert(value, FitsTypeOf, int64(0))
c.Assert(value, FitsTypeOf, os.Error(nil))
var Implements Checker = &implementsChecker{
	&CheckerInfo{Name: "Implements", Params: []string{"obtained", "ifaceptr"}},
}

The Implements checker verifies that the obtained value implements the interface specified via a pointer to an interface variable.

For example:

var e os.Error
c.Assert(err, Implements, &e)
var IsNil Checker = &isNilChecker{
	&CheckerInfo{Name: "IsNil", Params: []string{"value"}},
}

The IsNil checker tests whether the obtained value is nil.

For example:

c.Assert(err, IsNil)
var Matches Checker = &matchesChecker{
	&CheckerInfo{Name: "Matches", Params: []string{"value", "regex"}},
}

The Matches checker verifies that the string provided as the obtained value (or the string resulting from obtained.String()) matches the regular expression provided.

For example:

c.Assert(err, Matches, "perm.*denied")
var NotNil Checker = &notNilChecker{
	&CheckerInfo{Name: "NotNil", Params: []string{"value"}},
}

The NotNil checker verifies that the obtained value is not nil.

For example:

c.Assert(iface, NotNil)

This is an alias for Not(IsNil), made available since it's a fairly common check.

var Panics Checker = &panicsChecker{
	&CheckerInfo{Name: "Panics", Params: []string{"function", "expected"}},
}

The Panics checker verifies that calling the provided zero-argument function will cause a panic which is deep-equal to the provided value.

For example:

c.Assert(func() { f(1, 2) }, Panics, os.NewError("BOOM")).

If the provided value is a plain string, it will also be attempted to be matched as a regular expression against the String() value of the panic.

func Not

func Not(checker Checker) Checker

The Not() checker inverts the logic of the provided checker. The resulting checker will succeed where the original one failed, and vice-versa.

For example:

c.Assert(a, Not(Equals), b)

type CheckerInfo

type CheckerInfo struct {
	Name   string
	Params []string
}

See the Checker interface.

func (*CheckerInfo) Info

func (info *CheckerInfo) Info() *CheckerInfo

type Result

type Result struct {
	Succeeded        int
	Failed           int
	Skipped          int
	Panicked         int
	FixturePanicked  int
	ExpectedFailures int
	Missed           int   // Not even tried to run, related to a panic in the fixture.
	RunError         error // Houston, we've got a problem.
}

func Run

func Run(suite interface{}, runConf *RunConf) *Result

Run the given test suite using the provided run configuration.

func RunAll

func RunAll(runConf *RunConf) *Result

Run all test suites registered with the Suite() function, using the given run configuration.

func (*Result) Add

func (r *Result) Add(other *Result)

func (*Result) Passed

func (r *Result) Passed() bool

func (*Result) String

func (r *Result) String() string

type RunConf

type RunConf struct {
	Output  io.Writer
	Stream  bool
	Verbose bool
	Filter  string
}

Jump to

Keyboard shortcuts

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