Documentation
¶
Overview ¶
Package assert provides non-fatal golden file assertions for testing.
Assertions return a boolean indicating success or failure, allowing tests to continue after a failure to collect multiple errors.
Example:
func TestOutput(t *testing.T) {
output := runMyProgram()
assert.Golden(t, output)
}
func TestWithOptions(t *testing.T) {
a := assert.New(termitest.WithSize(80, 24))
a.Golden(t, output, "should match terminal size")
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Golden ¶
Golden compares got against the golden file for the current test. If the golden file doesn't exist, it creates it automatically. Returns true if the assertion passed, false otherwise.
Optional msgAndArgs can be provided to customize the error message.
To update a golden file, delete it and run the test again.
Types ¶
type Assertions ¶
type Assertions struct {
// contains filtered or unexported fields
}
Assertions provides golden file assertions with pre-configured options.
func New ¶
func New(opts ...termitest.Option) *Assertions
New creates a new Assertions instance with the given options. Use this when you want to reuse the same options across multiple assertions.
Example:
a := assert.New(termitest.WithSize(80, 24)) a.Golden(t, output1, "first check") a.Golden(t, output2, "second check")
func (*Assertions) Golden ¶
func (a *Assertions) Golden(t TestingT, got string, msgAndArgs ...any) bool
Golden compares got against the golden file for the current test. If the golden file doesn't exist, it creates it automatically. Returns true if the assertion passed, false otherwise.
Optional msgAndArgs can be provided to customize the error message.
func (*Assertions) GoldenText ¶
func (a *Assertions) GoldenText(t TestingT, got string, msgAndArgs ...any) bool
GoldenText compares only the text content against the golden file, stripping all ANSI escape codes (colors, styles, cursor movements).