Documentation
¶
Overview ¶
Package termitest provides golden file testing utilities for terminal applications.
Golden files are stored in testdata/{TestName}.golden and are created automatically when they don't exist. To update golden files, run tests with the -update flag: go test -update
Index ¶
- Variables
- func Compare(got, want []byte) bool
- func Diff(want, got []byte, wantLabel, gotLabel string) string
- func GoldenPath(testName string, name ...string) string
- func Normalize(content []byte) []byte
- func PrintGolden(tb testing.TB, name ...string)
- func ProcessWithOptions(text string, opts *Options) string
- func ReadGolden(path string) ([]byte, error)
- func StripANSI(s string) string
- func WriteGolden(path string, content []byte) error
- type Option
- type Options
- type Screen
Constants ¶
This section is empty.
Variables ¶
var UpdateGolden = flag.Bool("update", false, "update golden files")
UpdateGolden is a flag to update golden files instead of comparing. Use with: go test -update.
Functions ¶
func Compare ¶
Compare compares actual content against expected golden content. Returns true if they match after normalization.
func GoldenPath ¶
GoldenPath returns the path to a golden file for the given test name. If name is empty, returns testdata/{testName}.golden. If name is provided, returns testdata/{testName}_{name}.golden.
func Normalize ¶
Normalize normalizes content for comparison: - Converts CRLF to LF - Trims trailing whitespace from each line - Ensures single trailing newline.
func PrintGolden ¶ added in v0.0.2
PrintGolden prints the golden file content for the current test to stdout. This is useful for debugging during test development. If name is provided, prints testdata/{testName}_{name}.golden.
func ProcessWithOptions ¶
ProcessWithOptions processes text through a virtual screen if options specify dimensions.
func ReadGolden ¶
ReadGolden reads the golden file content. Returns nil if the file doesn't exist.
func StripANSI ¶
StripANSI removes all ANSI escape codes from the input string, returning plain text without any styling.
func WriteGolden ¶
WriteGolden writes content to the golden file, creating directories as needed.
Types ¶
type Option ¶
type Option func(*Options)
Option is a functional option for configuring golden file comparison.
func WithName ¶
WithName sets the suffix for the golden file name (e.g., WithName("dark") produces testdata/TestName_dark.golden).
type Options ¶
Options configures how golden file comparison is performed.
func ApplyOptions ¶
ApplyOptions applies all options and returns the configured Options.
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
Screen represents a virtual terminal screen with fixed dimensions.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package assert provides non-fatal golden file assertions for testing.
|
Package assert provides non-fatal golden file assertions for testing. |
|
internal
|
|
|
golden
Package golden provides shared golden file testing logic for assert and require packages.
|
Package golden provides shared golden file testing logic for assert and require packages. |
|
Package require provides fatal golden file assertions for testing.
|
Package require provides fatal golden file assertions for testing. |