require

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 require provides fatal golden file assertions for testing.

Assertions call FailNow() on failure, stopping test execution immediately. Use this for critical checks where continuing would be meaningless.

Example:

func TestOutput(t *testing.T) {
    output := runMyProgram()
    require.Golden(t, output)
}

func TestWithOptions(t *testing.T) {
    r := require.New(termitest.WithSize(80, 24))
    r.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)

Golden compares got against the golden file for the current test. If the golden file doesn't exist, it creates it automatically. If the comparison fails, it calls FailNow() to stop the test immediately.

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)

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:

r := require.New(termitest.WithSize(80, 24))
r.Golden(t, output1, "first check")
r.Golden(t, output2, "second check")

func (*Assertions) Golden

func (a *Assertions) Golden(t TestingT, got string, msgAndArgs ...any)

Golden compares got against the golden file for the current test. If the golden file doesn't exist, it creates it automatically. If the comparison fails, it calls FailNow() to stop the test immediately.

Optional msgAndArgs can be provided to customize the error message.

func (*Assertions) GoldenText

func (a *Assertions) GoldenText(t TestingT, got string, msgAndArgs ...any)

GoldenText compares only the text content against the golden file, stripping all ANSI escape codes (colors, styles, cursor movements).

type TestingT

type TestingT interface {
	golden.TestingT
	FailNow()
}

TestingT is the interface required for require assertions. It extends the basic testing interface with FailNow for fatal failures.

Jump to

Keyboard shortcuts

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