Documentation ¶
Overview ¶
Package check helps you migrate off of gopkg.in/check.v1
Index ¶
- func List(suite interface{}, runConf *RunConf) []string
- func ListAll(runConf *RunConf) []string
- func Run(t *testing.T, suite interface{}, runConf *RunConf)
- func RunAll(t *testing.T, runConf *RunConf)
- func Suite(suite interface{}) interface{}
- func TestingT(testingT *testing.T)
- type C
- func (c *C) Assert(obtained interface{}, checker Checker, args ...interface{})
- func (c *C) Check(obtained interface{}, checker Checker, args ...interface{}) bool
- func (c *C) Error(args ...interface{})
- func (c *C) Errorf(format string, args ...interface{})
- func (c *C) ExpectFailure(reason string)
- func (c *C) Fail()
- func (c *C) FailNow()
- func (c *C) Failed() bool
- func (c *C) Fatal(args ...interface{})
- func (c *C) Fatalf(format string, args ...interface{})
- func (c *C) GetTestLog() string
- func (c *C) Log(args ...interface{})
- func (c *C) Logf(format string, args ...interface{})
- func (c *C) MkDir() string
- func (c *C) Output(calldepth int, s string) error
- func (c *C) ResetTimer()
- func (c *C) SetBytes(n int64)
- func (c *C) StartTimer()
- func (c *C) StopTimer()
- func (c *C) Succeed()
- func (c *C) SucceedNow()
- func (c *C) TestName() string
- type Checker
- type CheckerInfo
- type CommentInterface
- type Result
- type RunConf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
List returns the names of the test functions in the given suite that will be run with the provided run configuration.
func ListAll ¶
ListAll returns the names of all the test functions registered with the Suite function that will be run with the provided run configuration.
func RunAll ¶
RunAll runs all test suites registered with the Suite function, using the provided run configuration.
Types ¶
type C ¶
func (*C) Assert ¶
Assert ensures that the first value matches the expected value according to the provided checker. If they do not match, an error is logged, the test is marked as failed, and the test execution stops.
Some checkers may not need the expected argument (e.g. IsNil).
If the last value in args implements CommentInterface, it is used to log additional information instead of being passed to the checker (see Commentf for an example).
func (*C) Check ¶
Check verifies if the first value matches the expected value according to the provided checker. If they do not match, an error is logged, the test is marked as failed, and the test execution continues.
Some checkers may not need the expected argument (e.g. IsNil).
If the last value in args implements CommentInterface, it is used to log additional information instead of being passed to the checker (see Commentf for an example).
func (*C) Error ¶
func (c *C) Error(args ...interface{})
Error logs an error into the test error output and marks the test as failed. The provided arguments are assembled together into a string with fmt.Sprint.
func (*C) Errorf ¶
Errorf logs an error into the test error output and marks the test as failed. The provided arguments are assembled together into a string with fmt.Sprintf.
func (*C) ExpectFailure ¶
ExpectFailure informs that the running test is knowingly broken for the provided reason. If the test does not fail, an error will be reported to raise attention to this fact. 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()
Fail marks the currently running test as failed.
Something ought to have been previously logged so the developer can tell what went wrong. The higher level helper functions will fail the test and do the logging properly.
func (*C) FailNow ¶
func (c *C) FailNow()
FailNow marks the currently running test as failed and stops running it. Something ought to have been previously logged so the developer can tell what went wrong. The higher level helper functions will fail the test and do the logging properly.
func (*C) Fatal ¶
func (c *C) Fatal(args ...interface{})
Fatal logs an error into the test error output, marks the test as failed, and stops the test execution. The provided arguments are assembled together into a string with fmt.Sprint.
func (*C) Fatalf ¶
Fatlaf logs an error into the test error output, marks the test as failed, and stops the test execution. The provided arguments are assembled together into a string with fmt.Sprintf.
func (*C) GetTestLog ¶
GetTestLog returns the current test error output.
func (*C) Log ¶
func (c *C) Log(args ...interface{})
Log logs some information into the test error output. The provided arguments are assembled together into a string with fmt.Sprint.
func (*C) Logf ¶
Log logs some information into the test error output. The provided arguments are assembled together into a string with fmt.Sprintf.
func (*C) MkDir ¶
Create a new temporary directory which is automatically removed after the suite finishes running.
func (*C) Output ¶
Output enables *C to be used as a logger in functions that require only the minimum interface of *log.Logger.
func (*C) ResetTimer ¶
func (c *C) ResetTimer()
ResetTimer sets the elapsed benchmark time to zero. It does not affect whether the timer is running.
func (*C) SetBytes ¶
SetBytes informs the number of bytes that the benchmark processes on each iteration. If this is called in a benchmark it will also report MB/s.
func (*C) StartTimer ¶
func (c *C) StartTimer()
StartTimer starts timing a test. This function is called automatically before a benchmark starts, but it can also used to resume timing after a call to StopTimer.
func (*C) StopTimer ¶
func (c *C) StopTimer()
StopTimer stops timing a test. This can be used to pause the timer while performing complex initialization that you don't want to measure.
func (*C) Succeed ¶
func (c *C) Succeed()
Succeed marks the currently running test as succeeded, undoing any previous failures.
func (*C) SucceedNow ¶
func (c *C) SucceedNow()
SucceedNow marks the currently running test as succeeded, undoing any previous failures, and stops 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 Assert and Check verification methods.
var DeepEquals Checker = &deepEqualsChecker{ &CheckerInfo{Name: "DeepEquals", Params: []string{"obtained", "expected"}}, }
The DeepEquals checker verifies that the obtained value is deep-equal to the expected value. The check will work correctly even when facing slices, interfaces, and values of different types (which always fail the test).
For example:
c.Assert(value, DeepEquals, 42) c.Assert(array, DeepEquals, []string{"hi", "there"})
var Equals Checker = &equalsChecker{ &CheckerInfo{Name: "Equals", Params: []string{"obtained", "expected"}}, }
The Equals checker verifies that the obtained value is equal to the expected value, according to usual Go semantics for ==.
For example:
c.Assert(value, Equals, 42)
var ErrorMatches Checker = errorMatchesChecker{ &CheckerInfo{Name: "ErrorMatches", Params: []string{"value", "regex"}}, }
The ErrorMatches checker verifies that the error value is non nil and matches the regular expression provided.
For example:
c.Assert(err, ErrorMatches, "perm.*denied")
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 HasLen Checker = &hasLenChecker{ &CheckerInfo{Name: "HasLen", Params: []string{"obtained", "n"}}, }
The HasLen checker verifies that the obtained value has the provided length. In many cases this is superior to using Equals in conjunction with the len function because in case the check fails the value itself will be printed, instead of its length, providing more details for figuring the problem.
For example:
c.Assert(list, HasLen, 5)
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 = ¬NilChecker{ &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 PanicMatches Checker = &panicMatchesChecker{ &CheckerInfo{Name: "PanicMatches", Params: []string{"function", "expected"}}, }
The PanicMatches checker verifies that calling the provided zero-argument function will cause a panic with an error value matching the regular expression provided.
For example:
c.Assert(func() { f(1, 2) }, PanicMatches, `open.*: no such file or directory`).
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, &SomeErrorType{"BOOM"}).
type CheckerInfo ¶
See the Checker interface.
func (*CheckerInfo) Info ¶
func (info *CheckerInfo) Info() *CheckerInfo
type CommentInterface ¶
type CommentInterface interface {
CheckCommentString() string
}
CommentInterface must be implemented by types that attach extra information to failed checks. See the Commentf function for details.
func Commentf ¶
func Commentf(format string, args ...interface{}) CommentInterface
Commentf returns an infomational value to use with 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(v, Equals, 42, Commentf("Iteration #%d failed.", i))
Note that if the comment is constant, a better option is to simply use a normal comment right above or next to the line, as it will also get printed with any errors:
c.Assert(l, Equals, 8192) // Ensure buffer size is correct (bug #123)