docs(tinyssert): documentation about the functional options
This commit is contained in:
@@ -182,20 +182,35 @@ func New(opts ...Option) Assertions {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Option is used in new constructor functions (such as [New] and [NewDisabled]) to customize
|
||||||
|
// the behaviour of the implementation.
|
||||||
type Option = func(*assertions)
|
type Option = func(*assertions)
|
||||||
|
|
||||||
|
// WithPanic sets the implementation to panic when an assertion fails. If used together with
|
||||||
|
// [WithTest], the implementation should use [testing.T.FailNow] instead of panic.
|
||||||
func WithPanic() Option {
|
func WithPanic() Option {
|
||||||
return func(a *assertions) {
|
return func(a *assertions) {
|
||||||
a.panic = true
|
a.panic = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTest provides a [TestingT] implementation, such as the provided by the [testing] stadard package
|
||||||
|
// to be used to log and mark tests as failed if possible.
|
||||||
|
//
|
||||||
|
// If the implementation has an Errorf method, it will be used instead of any logger provided by [WithLogger].
|
||||||
|
//
|
||||||
|
// If the implementation has an FailNow method, it will be used instead of panic.
|
||||||
func WithTest(t TestingT) Option {
|
func WithTest(t TestingT) Option {
|
||||||
return func(a *assertions) {
|
return func(a *assertions) {
|
||||||
a.test = t
|
a.test = t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLogger provides an [slog.Logger] instance to be used by the [Assertions] implementation to log
|
||||||
|
// failed assertions.
|
||||||
|
//
|
||||||
|
// If used together with [WithTest], the logger is not used if the [TestingT] implementation provided has
|
||||||
|
// an Errorf method.
|
||||||
func WithLogger(l *slog.Logger) Option {
|
func WithLogger(l *slog.Logger) Option {
|
||||||
return func(a *assertions) {
|
return func(a *assertions) {
|
||||||
a.log = l
|
a.log = l
|
||||||
@@ -212,7 +227,7 @@ type assertions struct {
|
|||||||
group string
|
group string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper interface around [testing.T].
|
// TestingT is a wrapper interface around [testing.T].
|
||||||
type TestingT interface {
|
type TestingT interface {
|
||||||
Errorf(format string, args ...any)
|
Errorf(format string, args ...any)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user