Documentation
¶
Index ¶
- func DeepEqual(t *testing.T, actual, expect any, message ...string) error
- func Nil(t *testing.T, val any, message ...string) error
- func NotDeepEqual(t *testing.T, actual, expect any, message ...string) error
- func NotNil(t *testing.T, val any, message ...string) error
- func NotPanic(t *testing.T, fn func(), message ...string) (err error)
- func Panic(t *testing.T, fn func(), message ...string) (err error)
- type Assertion
- func (a *Assertion) Cleanup(f func())
- func (a *Assertion) Deadline() (deadline time.Time, ok bool)
- func (a *Assertion) DeepEqual(actual, expect any, message ...string) error
- func (a *Assertion) Error(args ...any)
- func (a *Assertion) Errorf(format string, args ...any)
- func (a *Assertion) Fail()
- func (a *Assertion) FailNow()
- func (a *Assertion) Failed() bool
- func (a *Assertion) Fatal(args ...any)
- func (a *Assertion) Fatalf(format string, args ...any)
- func (a *Assertion) Helper()
- func (a *Assertion) Log(args ...any)
- func (a *Assertion) Logf(format string, args ...any)
- func (a *Assertion) Name() string
- func (a *Assertion) Nil(val any, message ...string) error
- func (a *Assertion) NotDeepEqual(actual, expect any, message ...string) error
- func (a *Assertion) NotNil(val any, message ...string) error
- func (a *Assertion) NotPanic(fn func(), message ...string) (err error)
- func (a *Assertion) Panic(fn func(), message ...string) (err error)
- func (a *Assertion) Parallel()
- func (a *Assertion) Run(name string, f func(*testing.T)) bool
- func (a *Assertion) Setenv(key, value string)
- func (a *Assertion) Skip(args ...any)
- func (a *Assertion) SkipNow()
- func (a *Assertion) Skipf(format string, args ...any)
- func (a *Assertion) Skipped() bool
- func (a *Assertion) TempDir() string
- type AssertionError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Nil ¶ added in v0.1.1
Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.
func NotDeepEqual ¶
NotDeepEqual tests deeply inequality between actual and expected parameters.
func NotNil ¶ added in v0.1.1
NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.
Types ¶
type Assertion ¶
type Assertion struct {
// contains filtered or unexported fields
}
func (*Assertion) Cleanup ¶ added in v0.1.1
func (a *Assertion) Cleanup(f func())
Cleanup registers a function to be called when the test (or subtest) and all its subtests complete. Cleanup functions will be called in last added, first called order.
func (*Assertion) Deadline ¶ added in v0.1.1
Deadline reports the time at which the test binary will have exceeded the timeout specified by the -timeout flag.
The ok result is false if the -timeout flag indicates “no timeout” (0).
func (*Assertion) Fail ¶ added in v0.1.1
func (a *Assertion) Fail()
Fail marks the function as having failed but continues execution.
func (*Assertion) FailNow ¶ added in v0.1.1
func (a *Assertion) FailNow()
FailNow marks the function as having failed and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine). Execution will continue at the next test or benchmark. FailNow must be called from the goroutine running the test or benchmark function, not from other goroutines created during the test. Calling FailNow does not stop those other goroutines.
func (*Assertion) Helper ¶ added in v0.1.1
func (a *Assertion) Helper()
Helper marks the calling function as a test helper function. When printing file and line information, that function will be skipped. Helper may be called simultaneously from multiple goroutines.
func (*Assertion) Log ¶ added in v0.1.1
Log formats its arguments using default formatting, analogous to Println, and records the text in the error log. For tests, the text will be printed only if the test fails or the -test.v flag is set. For benchmarks, the text is always printed to avoid having performance depend on the value of the -test.v flag.
func (*Assertion) Logf ¶ added in v0.1.1
Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. A final newline is added if not provided. For tests, the text will be printed only if the test fails or the -test.v flag is set. For benchmarks, the text is always printed to avoid having performance depend on the value of the -test.v flag.
func (*Assertion) Name ¶ added in v0.1.1
Name returns the name of the running (sub-) test or benchmark.
The name will include the name of the test along with the names of any nested sub-tests. If two sibling sub-tests have the same name, Name will append a suffix to guarantee the returned name is unique.
func (*Assertion) Nil ¶ added in v0.1.1
Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.
func (*Assertion) NotDeepEqual ¶
NotDeepEqual tests deeply inequality between actual and expected parameters.
func (*Assertion) NotNil ¶ added in v0.1.1
NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.
func (*Assertion) Parallel ¶ added in v0.1.1
func (a *Assertion) Parallel()
Parallel signals that this test is to be run in parallel with (and only with) other parallel tests. When a test is run multiple times due to use of -test.count or -test.cpu, multiple instances of a single test never run in parallel with each other.
func (*Assertion) Run ¶ added in v0.1.1
Run runs f as a subtest of t called name. It runs f in a separate goroutine and blocks until f returns or calls t.Parallel to become a parallel test. Run reports whether f succeeded (or at least did not fail before calling t.Parallel).
Run may be called simultaneously from multiple goroutines, but all such calls must return before the outer test function for t returns.
func (*Assertion) Setenv ¶ added in v0.1.1
Setenv calls os.Setenv(key, value) and uses Cleanup to restore the environment variable to its original value after the test.
Because Setenv affects the whole process, it cannot be used in parallel tests or tests with parallel ancestors.
func (*Assertion) SkipNow ¶ added in v0.1.1
func (a *Assertion) SkipNow()
SkipNow marks the test as having been skipped and stops its execution by calling runtime.Goexit. If a test fails (see Error, Errorf, Fail) and is then skipped, it is still considered to have failed. Execution will continue at the next test or benchmark. See also FailNow. SkipNow must be called from the goroutine running the test, not from other goroutines created during the test. Calling SkipNow does not stop those other goroutines.
func (*Assertion) TempDir ¶ added in v0.1.1
TempDir returns a temporary directory for the test to use. The directory is automatically removed by Cleanup when the test and all its subtests complete. Each subsequent call to t.TempDir returns a unique directory; if the directory creation fails, TempDir terminates the test by calling Fatal.
type AssertionError ¶
type AssertionError struct {
// contains filtered or unexported fields
}
AssertionError indicates the failure of an assertion.
func (AssertionError) Error ¶
func (err AssertionError) Error() string
Error returns the message of the error.