Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilReceiver occurs when a method is called on a receiver that is nil. This // error can be checked with the == operator. // // Format: // "receiver must not be nil" ErrNilReceiver error // ErrTestNotImpl occurs when a test is not implemented. This can be checked // with the == operator. // // Format: // "test not implemented" ErrTestNotImpl error )
var (
// FAIL is the namespace for creating ErrTest errors.
FAIL failT
)
Functions ¶
func NewErrPanic ¶
NewErrPanic creates a new error that represents a panic.
Parameters:
- value: The value of the panic.
Returns:
- error: The new error. Never returns nil.
Format:
"panic: <value>"
where <value> is the value of the panic.
func NewErrTest ¶ added in v0.1.3
NewErrTest creates and returns a new ErrTest error with the given expected and actual values.
Parameters:
- want: The expected value.
- got: The actual value.
Returns:
- error: A pointer to the newly created ErrTest. Never returns nil.
WARNING: Constructors that uses the FAIL namespaces are recommended to be used instead of this. However, if the precise use case is not found in the FAIL namespaces, this can be used.
Format:
"want <want>, got <got>"
Where:
- <want> is the expected value.
- <got> is the actual value.
func Try ¶
func Try(fn func()) error
Try executes the given function and returns any paniced error. If the given function does not panic, nil is returned.
Parameters:
- fn: The function to execute. If nil, nil is returned.
Returns:
- error: The paniced error, if any. Otherwise, nil.
Errors:
- *ErrPanic: If the panic value is not an error.
- any other error: If the panic value is an error.
If the panic value is an error, it is returned as-is. If the panic value is a string, it is converted to an error. In any other case, a new ErrPanic is created.
Example:
err := Try(func() { panic("something went wrong") }) fmt.Println(err) // Prints: "something went wrong"
Types ¶
type ErrPanic ¶
type ErrPanic struct { // Value is the value of the panic. Value any }
ErrPanic is an error that represents a panic.
type ErrTest ¶ added in v0.1.3
type ErrTest struct { // Want is the expected value. Want string // Got is the actual value. Got string }
ErrTest occurs when a test failed.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is an instance of a test.
type MakeFn ¶ added in v0.1.3
MakeFn is a function that is used to create TestingFn instances.
Parameters:
- args: The arguments to pass to the testing function.
Returns:
- TestingFn: The function that is used to run the test. Never returns nil.
type TestSet ¶ added in v0.1.3
type TestSet[T any] struct { // contains filtered or unexported fields }
TestSet is a collection of tests.
func NewTestSet ¶ added in v0.1.3
NewTestSet creates and returns a new Tests instance with a specified function to create TestingFn instances. If no function is provided, a default testing function is used.
Parameters:
- makeFn: A function that returns a TestingFn. If nil, a default testing function is used.
Returns:
- Tests: A new Tests instance with the provided or default makeFn.
func (*TestSet[T]) Add ¶ added in v0.1.3
Add adds a new test to the collection of tests.
Parameters:
- name: The name of the test.
- args: The arguments to pass to the testing function.
Returns:
- error: An error if the test could not be added.
Errors:
- ErrNilReceiver: If the receiver is nil.
type TestingFn ¶ added in v0.1.3
type TestingFn func() error
TestingFn is a function that is used to run a test.
Parameters:
- error: An error if the test failed.
var ( // DefaultTestingFn is the default function for when no testing function is provided. // // It just returns ErrTestNotImpl. DefaultTestingFn TestingFn )