assert

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 2 Imported by: 0

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

func 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.

To update a golden file, delete it and run the test again.

func GoldenText

func 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). Use this when you want to test the text output without formatting.

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).

type TestingT

type TestingT = golden.TestingT

TestingT is the minimal interface required for assertions. It is satisfied by *testing.T and *testing.B.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL